Skip to content

Commit a35aea3

Browse files
committed
cs fix
1 parent 118fa48 commit a35aea3

File tree

9 files changed

+951
-46
lines changed

9 files changed

+951
-46
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ root = true
22

33
[*]
44
indent_style = space
5-
indent_size = 4
5+
indent_size = 2
66
charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true

.eslintrc.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"extends": "eslint:recommended",
6+
"rules": {
7+
"indent": [
8+
"error",
9+
2
10+
],
11+
"linebreak-style": [
12+
"error",
13+
"unix"
14+
],
15+
"quotes": [
16+
"error",
17+
"single"
18+
],
19+
"semi": [
20+
"error",
21+
"always"
22+
]
23+
}
24+
}

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.editorconfig
22
.gitignore
33
.npmignore
4+
.eslintrc.json
45
.idea/
56
.git/

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: node_js
2+
3+
node_js:
4+
- "4"
5+
- "stable"
6+
7+
install:
8+
- npm install
9+
10+
script:
11+
- npm test
12+
13+
notifications:
14+
email: false

CHANGELOG.md

Whitespace-only changes.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Igor Ognichenko
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

index.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
11
'use strict';
22

33
var path = require('path');
4-
var namedRegexp = require("named-js-regexp");
4+
var namedRegexp = require('named-js-regexp');
55

66
module.exports = function (css, resourcePath, aliases) {
7-
var IMPORT_REGEX = namedRegexp(/^(:<import>@import\s+)(:<url_tag_open>url\()?\s*(:<quote_open>"|')(:<url>.+)\s*(:<quote_close>"|')(:<url_tag_close>\))?(:<context>.*);$/gm);
8-
var URL_REGEX = namedRegexp(/(:<url_tag_open>url\()\s*(:<quote_open>"|')?(:<url>.+)\s*(:<quote_close>"|')?(:<url_tag_close>\))/gm);
9-
css = parse(css, IMPORT_REGEX);
10-
css = parse(css, URL_REGEX);
7+
var IMPORT_REGEX = namedRegexp(/^(:<import>@import\s+)(:<url_tag_open>url\()?\s*(:<quote_open>"|')(:<url>.+)\s*(:<quote_close>"|')(:<url_tag_close>\))?(:<context>.*);$/gm);
8+
var URL_REGEX = namedRegexp(/(:<url_tag_open>url\()\s*(:<quote_open>"|')?(:<url>.+)\s*(:<quote_close>"|')?(:<url_tag_close>\))/gm);
9+
css = parse(css, IMPORT_REGEX);
10+
css = parse(css, URL_REGEX);
1111

12-
return css;
13-
14-
function resolve(url, resourcePath) {
12+
return css;
1513

16-
for (var aliasName in aliases) {
17-
var regExp = new RegExp('^' + aliasName + '(.*)')
14+
function resolve(url, resourcePath) {
1815

19-
if (regExp.test(url)) {
20-
return path.relative(path.dirname(resourcePath), path.resolve(aliases[aliasName] + url.replace(regExp, '$1')));
21-
}
22-
}
16+
for (var aliasName in aliases) {
17+
var regExp = new RegExp('^' + aliasName + '(.*)');
2318

24-
return url;
19+
if (regExp.test(url)) {
20+
return path.relative(path.dirname(resourcePath), path.resolve(aliases[aliasName] + url.replace(regExp, '$1')));
21+
}
2522
}
2623

27-
function parse(css, regex) {
28-
var m, importOriginal, importReplace, replace = [];
24+
return url;
25+
}
2926

30-
while ((m = regex.exec(css)) !== null) {
31-
if (m.index === regex.lastIndex) {
32-
regex.lastIndex++;
33-
}
27+
function parse(css, regex) {
28+
var m, importOriginal, importReplace, replace = [];
3429

35-
replace.push(m);
36-
}
30+
while ((m = regex.exec(css)) !== null) {
31+
if (m.index === regex.lastIndex) {
32+
regex.lastIndex++;
33+
}
3734

38-
for (var item in replace) {
39-
var m = replace[item];
35+
replace.push(m);
36+
}
4037

41-
importOriginal = '';
42-
importReplace = '';
43-
var mathGroups = m.groups();
38+
for (var item in replace) {
39+
m = replace[item];
4440

45-
for (var groupName in mathGroups) {
46-
var match = mathGroups[groupName];
47-
importOriginal += typeof match !== 'undefined' ? match : '';
41+
importOriginal = '';
42+
importReplace = '';
43+
var mathGroups = m.groups();
4844

49-
if (groupName !== 'url') {
50-
importReplace += typeof match !== 'undefined' ? match : '';
51-
} else {
52-
importReplace += resolve(match, resourcePath);
53-
}
54-
}
45+
for (var groupName in mathGroups) {
46+
var match = mathGroups[groupName];
47+
importOriginal += typeof match !== 'undefined' ? match : '';
5548

56-
if (importOriginal !== importReplace) {
57-
css = css.replace(importOriginal, importReplace);
58-
}
49+
if (groupName !== 'url') {
50+
importReplace += typeof match !== 'undefined' ? match : '';
51+
} else {
52+
importReplace += resolve(match, resourcePath);
5953
}
54+
}
6055

61-
return css;
56+
if (importOriginal !== importReplace) {
57+
css = css.replace(importOriginal, importReplace);
58+
}
6259
}
63-
}
60+
61+
return css;
62+
}
63+
};

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"name": "css-aliases",
3-
"version": "1.1.2",
4-
"description": "Lets you create custom aliases for CSS,less, SASS and etc. properties with an @alias rule",
3+
"version": "1.1.3",
4+
"description": "Lets you create custom aliases for CSS, less, SASS and etc. properties with an @alias rule",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "node_modules/.bin/eslint .",
8+
"patch": "npm version patch && git push origin master --follow-tags && npm publish",
9+
"minor": "npm version minor && git push origin master --follow-tags && npm publish",
10+
"major": "npm version major && git push origin master --follow-tags && npm publish"
811
},
912
"repository": {
1013
"type": "git",
@@ -28,5 +31,8 @@
2831
"dependencies": {
2932
"named-js-regexp": "^1.3.2",
3033
"path": "^0.12.7"
34+
},
35+
"devDependencies": {
36+
"eslint": "^3.19.0"
3137
}
3238
}

0 commit comments

Comments
 (0)