Skip to content

Commit aa73811

Browse files
committed
add option.random
1 parent 5ddc5ff commit aa73811

10 files changed

+41
-17
lines changed

.commithash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e0363919377ea8b9f80fe7bfd60b87140fc08fb9
1+
5ddc5ff4bbcf8a7578b92f894689753e38ea37ff

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
coverage
12
node_modules

dist/cssobj-plugin-localize.amd.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ function cssobj_plugin_selector_localize(option) {
5757

5858
option = option || {};
5959

60-
var space = option.space = typeof option.space!=='string' ? random() : option.space;
60+
var space = option.space = typeof option.space!=='string'
61+
? (typeof option.random == 'function' ? option.random() : random())
62+
: option.space;
6163

6264
var localNames = option.localNames = option.localNames || {};
6365

dist/cssobj-plugin-localize.cjs.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
// check n is numeric, or string of numeric
66

77

8-
function own(o, k) {
9-
return {}.hasOwnProperty.call(o, k)
10-
}
8+
119

1210
// set default option (not deeply)
1311

@@ -34,11 +32,7 @@ var random = (function () {
3432

3533

3634
// ensure obj[k] as array, then push v into it
37-
function arrayKV (obj, k, v, reverse, unique) {
38-
obj[k] = k in obj ? [].concat(obj[k]) : [];
39-
if(unique && obj[k].indexOf(v)>-1) return
40-
reverse ? obj[k].unshift(v) : obj[k].push(v);
41-
}
35+
4236

4337
// replace find in str, with rep function result
4438

@@ -57,7 +51,9 @@ function cssobj_plugin_selector_localize(option) {
5751

5852
option = option || {};
5953

60-
var space = option.space = typeof option.space!=='string' ? random() : option.space;
54+
var space = option.space = typeof option.space!=='string'
55+
? (typeof option.random == 'function' ? option.random() : random())
56+
: option.space;
6157

6258
var localNames = option.localNames = option.localNames || {};
6359

dist/cssobj-plugin-localize.es.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ function cssobj_plugin_selector_localize(option) {
5555

5656
option = option || {};
5757

58-
var space = option.space = typeof option.space!=='string' ? random() : option.space;
58+
var space = option.space = typeof option.space!=='string'
59+
? (typeof option.random == 'function' ? option.random() : random())
60+
: option.space;
5961

6062
var localNames = option.localNames = option.localNames || {};
6163

dist/cssobj-plugin-localize.iife.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ function cssobj_plugin_selector_localize(option) {
5858

5959
option = option || {};
6060

61-
var space = option.space = typeof option.space!=='string' ? random() : option.space;
61+
var space = option.space = typeof option.space!=='string'
62+
? (typeof option.random == 'function' ? option.random() : random())
63+
: option.space;
6264

6365
var localNames = option.localNames = option.localNames || {};
6466

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.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "cssobj-plugin-localize",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "Localize class name for cssobj",
55
"main": "dist/cssobj-plugin-localize.cjs.js",
6+
"browser": "dist/cssobj-plugin-localize.iife.js",
67
"jsnext:main": "dist/cssobj-plugin-localize.es.js",
78
"scripts": {
8-
"test": "npm run build && mocha",
9+
"test": "npm run build && istanbul cover _mocha",
910
"report": "cd dist && gzip < cssobj-plugin-localize.min.js > cssobj-plugin-localize.min.gz && ls -lh && rm -f *.gz",
1011
"build": "git rev-parse HEAD > .commithash && rollup -c && uglifyjs dist/cssobj-plugin-localize.iife.js -cm -o dist/cssobj-plugin-localize.min.js",
1112
"make": "gulp bump && npm run build"

src/cssobj-plugin-localize.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export default function cssobj_plugin_selector_localize(option) {
66

77
option = option || {}
88

9-
var space = option.space = typeof option.space!=='string' ? random() : option.space
9+
var space = option.space = typeof option.space!=='string'
10+
? (typeof option.random == 'function' ? option.random() : random())
11+
: option.space
1012

1113
var localNames = option.localNames = option.localNames || {}
1214

test/test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ describe('Test plugin selector localize', function() {
2222

2323
})
2424

25+
it('should localize with custom random method', function() {
26+
27+
var loc = lib({random: ()=>'_random_'}).selector
28+
29+
var ret = loc('body .nav .item', {}, {})
30+
expect(ret).match(/body .nav_random_ .item_random_/)
31+
32+
})
33+
34+
it('should not localize for @-rules', function() {
35+
36+
var loc = lib().selector
37+
38+
var ret = loc('body .nav .item', {at: 'keyframes'}, {})
39+
expect(ret).equal('body .nav .item')
40+
41+
})
42+
2543
it('should localize with localNames', function() {
2644

2745
var loc = lib({space: null, localNames: {nav: '_custom_nav'}}).selector

0 commit comments

Comments
 (0)