Skip to content

Commit f7800f1

Browse files
Merge pull request #2 from dutchenkoOleg/upd
Upd
2 parents 774916c + 5269e88 commit f7800f1

File tree

6 files changed

+143
-21
lines changed

6 files changed

+143
-21
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- "7"
5+
- "6"

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Change log
2+
3+
:back: [README.md](./README.md)
4+
5+
> _All notable changes to this project will be documented in this file._
6+
> _This project adheres to [Semantic Versioning](http://semver.org/)._
7+
8+
---
9+
10+
### [1.1.9] - 2017-07-07
11+
12+
#### Added
13+
14+
- this CHANGELOG.md file ))
15+
- test for code style
16+
- test of sorting result, see [./tests/index.js](./tests/index.js)
17+
- [Travis CI](https://travis-ci.org/dutchenkoOleg/gulp-not-supported-file) builds
18+
19+
#### Changed
20+
21+
- js code style with accordance to [`happiness`]((https://github.com/JedWatson/happiness))
22+
23+
---

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
![npm](https://img.shields.io/badge/node-6.3.0-yellow.svg)
44
![es2015](https://img.shields.io/badge/ECMAScript-2015_(ES6)-blue.svg)
5+
![license](https://img.shields.io/badge/License-MIT-orange.svg)
6+
[![Build Status](https://travis-ci.org/dutchenkoOleg/sort-css-media-queries.svg?branch=master)](https://travis-ci.org/dutchenkoOleg/sort-css-media-queries)
57

6-
The custom `sort` method for [`css-mqpacker`](https://www.npmjs.com/package/css-mqpacker) or [`pleeease`](https://www.npmjs.com/package/pleeease) (which uses css-mqpacker) or, perhaps, something else ))
8+
> The custom `sort` method for [`css-mqpacker`](https://www.npmjs.com/package/css-mqpacker) or [`pleeease`](https://www.npmjs.com/package/pleeease) (which uses css-mqpacker) or, perhaps, something else ))
9+
10+
[![js happiness style](https://cdn.rawgit.com/JedWatson/happiness/master/badge.svg)](https://github.com/JedWatson/happiness)
711

812
## Installing
913

@@ -42,7 +46,12 @@ it's use es6 syntax
4246

4347
## Tests
4448

45-
Sorry but here no tests yet.
49+
1. `npm test` for testing js code style and test sorting method
50+
1. `npm run fix` for automatically fix most of problems with **js code style**
51+
52+
## Changelog
53+
54+
Please read [CHANGELOG.md](https://github.com/dutchenkoOleg/sort-css-media-queries/blob/master/CHANGELOG.md)
4655

4756

4857
## Contributing

index.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ function getQueryLength (length) {
5151
let unit = length[2];
5252

5353
switch (unit) {
54-
case "ch":
54+
case 'ch':
5555
num = parseFloat(num) * 8.8984375;
5656
break;
5757

58-
case "em":
59-
case "rem":
58+
case 'em':
59+
case 'rem':
6060
num = parseFloat(num) * 16;
6161
break;
6262

63-
case "ex":
63+
case 'ex':
6464
num = parseFloat(num) * 8.296875;
6565
break;
6666

67-
case "px":
67+
case 'px':
6868
num = parseFloat(num);
6969
break;
7070
}
@@ -86,18 +86,16 @@ function testQuery (doubleTestTrue, doubleTestFalse, singleTest) {
8686
* @param {string} query
8787
* @return {boolean}
8888
*/
89-
return function(query) {
90-
if ( doubleTestTrue.test(query) ) {
89+
return function (query) {
90+
if (doubleTestTrue.test(query)) {
9191
return true;
92-
} else if ( doubleTestFalse.test(query) ) {
92+
} else if (doubleTestFalse.test(query)) {
9393
return false;
9494
}
9595
return singleTest.test(query);
96-
}
96+
};
9797
}
9898

99-
100-
10199
// ----------------------------------------
102100
// Exports
103101
// ----------------------------------------
@@ -112,20 +110,20 @@ function testQuery (doubleTestTrue, doubleTestFalse, singleTest) {
112110
module.exports = function (a, b) {
113111
let minA = isMinWidth(a) || isMinHeight(a);
114112
let maxA = isMaxWidth(a) || isMaxHeight(a);
115-
113+
116114
let minB = isMinWidth(b) || isMinHeight(b);
117115
let maxB = isMaxWidth(b) || isMaxHeight(b);
118-
116+
119117
if (minA && maxB) {
120118
return -1;
121119
}
122120
if (maxA && minB) {
123121
return 1;
124122
}
125-
123+
126124
let lengthA = getQueryLength(a);
127125
let lengthB = getQueryLength(b);
128-
126+
129127
if (lengthA > lengthB) {
130128
if (maxA) {
131129
return -1;

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "sort-css-media-queries",
3-
"version": "1.1.1",
3+
"version": "1.1.9",
44
"description": "The custom `sort` method for `css-mqpacker` or `pleeease` (which uses css-mqpacker) or, perhaps, something else ))",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "happiness --verbose | snazzy && node ./tests/index.js",
8+
"fix": "happiness --verbose --fix | snazzy"
89
},
910
"repository": {
1011
"type": "git",
@@ -18,13 +19,17 @@
1819
"media",
1920
"queries"
2021
],
21-
"author": "Oleg Dutchenko <dutchenko.o.wezom@gmail.com>",
22+
"author": "Oleg Dutchenko <dutchenko.o.dev@gmail.com>",
2223
"license": "MIT",
2324
"bugs": {
2425
"url": "https://github.com/dutchenkoOleg/sort-css-media-queries/issues"
2526
},
2627
"engines": {
2728
"node": ">= 6.3.0"
2829
},
29-
"homepage": "https://github.com/dutchenkoOleg/sort-css-media-queries#readme"
30+
"homepage": "https://github.com/dutchenkoOleg/sort-css-media-queries#readme",
31+
"devDependencies": {
32+
"happiness": "^7.1.2",
33+
"snazzy": "^7.0.0"
34+
}
3035
}

tests/index.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* > Sorting test
3+
* @module path/to
4+
* @author Oleg Dutchenko <[email protected]>
5+
*/
6+
7+
'use strict';
8+
9+
// ----------------------------------------
10+
// Imports
11+
// ----------------------------------------
12+
13+
const sortCSSmq = require('../');
14+
15+
// ----------------------------------------
16+
// Helpers / Private
17+
// ----------------------------------------
18+
19+
// randomize
20+
function shuffleArray (array) {
21+
let newArray = array.concat();
22+
23+
for (let i = array.length - 1; i > 0; i--) {
24+
let j = Math.floor(Math.random() * (i + 1));
25+
let temp = newArray[i];
26+
27+
newArray[i] = newArray[j];
28+
newArray[j] = temp;
29+
}
30+
return newArray;
31+
}
32+
33+
// ----------------------------------------
34+
// Public
35+
// ----------------------------------------
36+
37+
// correct sorted order
38+
const queries = [
39+
// min-width/-height -> from smallest to largest
40+
'only screen and (min-width: 320px) and (max-width: 767px)',
41+
'screen and (min-height: 480px)',
42+
'screen and (min-height: 480px) and (min-width: 320px)',
43+
'only screen and (min-width: 640px)',
44+
'screen and (min-width: 1024px)',
45+
'only screen and (min-width: 1280px)',
46+
47+
// device
48+
'only screen and (min-device-width: 320px) and (max-device-width: 767px)',
49+
50+
// max-width/-height <- from largest to smallest
51+
'only screen and (max-width: 1023px)',
52+
'only screen and (max-height: 767px) and (min-height: 320px)',
53+
'only screen and (max-width: 767px) and (min-width: 320px)',
54+
'screen and (max-width: 639px)'
55+
];
56+
57+
// shuffle it
58+
const random = shuffleArray(queries);
59+
60+
// sort by module
61+
random.sort(sortCSSmq);
62+
63+
// make strings for compare
64+
const correct = queries.join(',');
65+
const sorted = random.join(',');
66+
67+
// lets test
68+
if (correct !== sorted) {
69+
let msg = [
70+
'',
71+
'ERROR -----------------',
72+
'sortCSSmq result should be same as correct!',
73+
'Correct sort',
74+
`- ${queries.join('\n- ')}`,
75+
'sortCSSmq result:',
76+
`- ${random.join('\n- ')}`,
77+
''
78+
].join('\n\n');
79+
80+
console.log(msg);
81+
process.exit(1);
82+
}

0 commit comments

Comments
 (0)