Skip to content

Commit 95522d2

Browse files
committed
api: prefix -> space, updated test
1 parent 37564ba commit 95522d2

8 files changed

+94
-114
lines changed

.commithash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a4ffe5692fe16f820fce58d54c4c9c98691652f1
1+
fcb1546c1ba81821bed252880079f04cea1a6cfe

dist/cssobj-plugin-localize.amd.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ function own(o, k) {
2727
// random string, should used across all cssobj plugins
2828
var random = (function () {
2929
var count = 0;
30-
return function () {
30+
return function (prefix) {
3131
count++;
32-
return '_' + Math.floor(Math.random() * Math.pow(2, 32)).toString(36) + count + '_'
32+
return '_' + (prefix||'') + Math.floor(Math.random() * Math.pow(2, 32)).toString(36) + count + '_'
3333
}
3434
})();
3535

@@ -60,11 +60,11 @@ function cssobj_plugin_selector_localize(option) {
6060

6161
option = option || {};
6262

63-
var prefix = option.prefix = typeof option.prefix!=='string' ? random() : option.prefix;
63+
var space = option.space = typeof option.space!=='string' ? random() : option.space;
6464

6565
var localNames = option.localNames = option.localNames || {};
6666

67-
var parser = function(str) {
67+
var parseSel = function(str) {
6868
var store=[], ast=[], lastAst, match;
6969
for(var c, n, i=0, len=str.length; i<len; i++) {
7070
c=str[i];
@@ -92,7 +92,7 @@ function cssobj_plugin_selector_localize(option) {
9292
n = match.join('');
9393
c += n in localNames
9494
? localNames[n]
95-
: prefix + n;
95+
: n + space;
9696
}
9797
i--;
9898
}
@@ -105,21 +105,17 @@ function cssobj_plugin_selector_localize(option) {
105105
return store.join('')
106106
};
107107

108-
var mapSel = function(str) {
109-
return parser(str)
110-
};
111-
112108
var mapClass = function(str) {
113-
return mapSel(str.replace(/\s+\.?/g, '.').replace(/^([^:\s.])/i, '.$1')).replace(/\./g, ' ')
109+
return parseSel(str.replace(/\s+\.?/g, '.').replace(/^([^:\s.])/i, '.$1')).replace(/\./g, ' ')
114110
};
115111

116112
return {
117113
selector: function localizeName (sel, node, result) {
118114
// don't touch at rule's selText
119115
// it's copied from parent, which already localized
120116
if(node.at) return sel
121-
if(!result.mapSel) result.mapSel = mapSel, result.mapClass = mapClass;
122-
return mapSel(sel)
117+
if(!result.mapSel) result.mapSel = parseSel, result.mapClass = mapClass;
118+
return parseSel(sel)
123119
}
124120
}
125121
}

dist/cssobj-plugin-localize.cjs.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ function own(o, k) {
2727
// random string, should used across all cssobj plugins
2828
var random = (function () {
2929
var count = 0;
30-
return function () {
30+
return function (prefix) {
3131
count++;
32-
return '_' + Math.floor(Math.random() * Math.pow(2, 32)).toString(36) + count + '_'
32+
return '_' + (prefix||'') + Math.floor(Math.random() * Math.pow(2, 32)).toString(36) + count + '_'
3333
}
3434
})();
3535

@@ -60,11 +60,11 @@ function cssobj_plugin_selector_localize(option) {
6060

6161
option = option || {};
6262

63-
var prefix = option.prefix = typeof option.prefix!=='string' ? random() : option.prefix;
63+
var space = option.space = typeof option.space!=='string' ? random() : option.space;
6464

6565
var localNames = option.localNames = option.localNames || {};
6666

67-
var parser = function(str) {
67+
var parseSel = function(str) {
6868
var store=[], ast=[], lastAst, match;
6969
for(var c, n, i=0, len=str.length; i<len; i++) {
7070
c=str[i];
@@ -92,7 +92,7 @@ function cssobj_plugin_selector_localize(option) {
9292
n = match.join('');
9393
c += n in localNames
9494
? localNames[n]
95-
: prefix + n;
95+
: n + space;
9696
}
9797
i--;
9898
}
@@ -105,21 +105,17 @@ function cssobj_plugin_selector_localize(option) {
105105
return store.join('')
106106
};
107107

108-
var mapSel = function(str) {
109-
return parser(str)
110-
};
111-
112108
var mapClass = function(str) {
113-
return mapSel(str.replace(/\s+\.?/g, '.').replace(/^([^:\s.])/i, '.$1')).replace(/\./g, ' ')
109+
return parseSel(str.replace(/\s+\.?/g, '.').replace(/^([^:\s.])/i, '.$1')).replace(/\./g, ' ')
114110
};
115111

116112
return {
117113
selector: function localizeName (sel, node, result) {
118114
// don't touch at rule's selText
119115
// it's copied from parent, which already localized
120116
if(node.at) return sel
121-
if(!result.mapSel) result.mapSel = mapSel, result.mapClass = mapClass;
122-
return mapSel(sel)
117+
if(!result.mapSel) result.mapSel = parseSel, result.mapClass = mapClass;
118+
return parseSel(sel)
123119
}
124120
}
125121
}

dist/cssobj-plugin-localize.es.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ function own(o, k) {
2525
// random string, should used across all cssobj plugins
2626
var random = (function () {
2727
var count = 0;
28-
return function () {
28+
return function (prefix) {
2929
count++;
30-
return '_' + Math.floor(Math.random() * Math.pow(2, 32)).toString(36) + count + '_'
30+
return '_' + (prefix||'') + Math.floor(Math.random() * Math.pow(2, 32)).toString(36) + count + '_'
3131
}
3232
})();
3333

@@ -58,11 +58,11 @@ function cssobj_plugin_selector_localize(option) {
5858

5959
option = option || {};
6060

61-
var prefix = option.prefix = typeof option.prefix!=='string' ? random() : option.prefix;
61+
var space = option.space = typeof option.space!=='string' ? random() : option.space;
6262

6363
var localNames = option.localNames = option.localNames || {};
6464

65-
var parser = function(str) {
65+
var parseSel = function(str) {
6666
var store=[], ast=[], lastAst, match;
6767
for(var c, n, i=0, len=str.length; i<len; i++) {
6868
c=str[i];
@@ -90,7 +90,7 @@ function cssobj_plugin_selector_localize(option) {
9090
n = match.join('');
9191
c += n in localNames
9292
? localNames[n]
93-
: prefix + n;
93+
: n + space;
9494
}
9595
i--;
9696
}
@@ -103,21 +103,17 @@ function cssobj_plugin_selector_localize(option) {
103103
return store.join('')
104104
};
105105

106-
var mapSel = function(str) {
107-
return parser(str)
108-
};
109-
110106
var mapClass = function(str) {
111-
return mapSel(str.replace(/\s+\.?/g, '.').replace(/^([^:\s.])/i, '.$1')).replace(/\./g, ' ')
107+
return parseSel(str.replace(/\s+\.?/g, '.').replace(/^([^:\s.])/i, '.$1')).replace(/\./g, ' ')
112108
};
113109

114110
return {
115111
selector: function localizeName (sel, node, result) {
116112
// don't touch at rule's selText
117113
// it's copied from parent, which already localized
118114
if(node.at) return sel
119-
if(!result.mapSel) result.mapSel = mapSel, result.mapClass = mapClass;
120-
return mapSel(sel)
115+
if(!result.mapSel) result.mapSel = parseSel, result.mapClass = mapClass;
116+
return parseSel(sel)
121117
}
122118
}
123119
}

dist/cssobj-plugin-localize.iife.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ function own(o, k) {
2828
// random string, should used across all cssobj plugins
2929
var random = (function () {
3030
var count = 0;
31-
return function () {
31+
return function (prefix) {
3232
count++;
33-
return '_' + Math.floor(Math.random() * Math.pow(2, 32)).toString(36) + count + '_'
33+
return '_' + (prefix||'') + Math.floor(Math.random() * Math.pow(2, 32)).toString(36) + count + '_'
3434
}
3535
})();
3636

@@ -61,11 +61,11 @@ function cssobj_plugin_selector_localize(option) {
6161

6262
option = option || {};
6363

64-
var prefix = option.prefix = typeof option.prefix!=='string' ? random() : option.prefix;
64+
var space = option.space = typeof option.space!=='string' ? random() : option.space;
6565

6666
var localNames = option.localNames = option.localNames || {};
6767

68-
var parser = function(str) {
68+
var parseSel = function(str) {
6969
var store=[], ast=[], lastAst, match;
7070
for(var c, n, i=0, len=str.length; i<len; i++) {
7171
c=str[i];
@@ -93,7 +93,7 @@ function cssobj_plugin_selector_localize(option) {
9393
n = match.join('');
9494
c += n in localNames
9595
? localNames[n]
96-
: prefix + n;
96+
: n + space;
9797
}
9898
i--;
9999
}
@@ -106,21 +106,17 @@ function cssobj_plugin_selector_localize(option) {
106106
return store.join('')
107107
};
108108

109-
var mapSel = function(str) {
110-
return parser(str)
111-
};
112-
113109
var mapClass = function(str) {
114-
return mapSel(str.replace(/\s+\.?/g, '.').replace(/^([^:\s.])/i, '.$1')).replace(/\./g, ' ')
110+
return parseSel(str.replace(/\s+\.?/g, '.').replace(/^([^:\s.])/i, '.$1')).replace(/\./g, ' ')
115111
};
116112

117113
return {
118114
selector: function localizeName (sel, node, result) {
119115
// don't touch at rule's selText
120116
// it's copied from parent, which already localized
121117
if(node.at) return sel
122-
if(!result.mapSel) result.mapSel = mapSel, result.mapClass = mapClass;
123-
return mapSel(sel)
118+
if(!result.mapSel) result.mapSel = parseSel, result.mapClass = mapClass;
119+
return parseSel(sel)
124120
}
125121
}
126122
}

dist/cssobj-plugin-localize.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cssobj-plugin-localize.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ export default function cssobj_plugin_selector_localize(option) {
66

77
option = option || {}
88

9-
var prefix = option.prefix = typeof option.prefix!=='string' ? random() : option.prefix
9+
var space = option.space = typeof option.space!=='string' ? random() : option.space
1010

1111
var localNames = option.localNames = option.localNames || {}
1212

13-
var parser = function(str) {
13+
var parseSel = function(str) {
1414
var store=[], ast=[], lastAst, match
1515
for(var c, n, i=0, len=str.length; i<len; i++) {
1616
c=str[i]
@@ -38,7 +38,7 @@ export default function cssobj_plugin_selector_localize(option) {
3838
n = match.join('')
3939
c += n in localNames
4040
? localNames[n]
41-
: prefix + n
41+
: n + space
4242
}
4343
i--
4444
}
@@ -51,21 +51,17 @@ export default function cssobj_plugin_selector_localize(option) {
5151
return store.join('')
5252
}
5353

54-
var mapSel = function(str) {
55-
return parser(str)
56-
}
57-
5854
var mapClass = function(str) {
59-
return mapSel(str.replace(/\s+\.?/g, '.').replace(/^([^:\s.])/i, '.$1')).replace(/\./g, ' ')
55+
return parseSel(str.replace(/\s+\.?/g, '.').replace(/^([^:\s.])/i, '.$1')).replace(/\./g, ' ')
6056
}
6157

6258
return {
6359
selector: function localizeName (sel, node, result) {
6460
// don't touch at rule's selText
6561
// it's copied from parent, which already localized
6662
if(node.at) return sel
67-
if(!result.mapSel) result.mapSel = mapSel, result.mapClass = mapClass
68-
return mapSel(sel)
63+
if(!result.mapSel) result.mapSel = parseSel, result.mapClass = mapClass
64+
return parseSel(sel)
6965
}
7066
}
7167
}

0 commit comments

Comments
 (0)