diff --git a/lib/index.js b/lib/index.js index 7631835..8db5184 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,12 +1,5 @@ 'use strict'; -const normalize = { - v1: require('./normalize/normalize'), - v2: require('./normalize/normalize2'), - harmony: require('./normalize/normalize-harmony'), - enb: require('./normalize/normalize2') -}; - module.exports = { normalize: require('./normalize'), merge: require('./merge'), @@ -15,6 +8,5 @@ module.exports = { parse: require('./parse'), assign: require('./assign'), load: require('./load'), - stringify: require('./stringify'), - normalizer: format => (normalize[format] || normalize.v2) + stringify: require('./stringify') }; diff --git a/lib/normalize.js b/lib/normalize.js index dfb1470..e31a9fa 100644 --- a/lib/normalize.js +++ b/lib/normalize.js @@ -1,14 +1,16 @@ 'use strict'; -const normalizers = { - v1: require('./normalize/normalize'), - v2: require('./normalize/normalize2'), - harmony: require('./normalize/normalize-harmony'), - enb: require('./normalize/normalize2') +const normalizer = { + v1: require('./normalize/v1'), + v2: require('./normalize/v2'), + harmony: require('./normalize/harmony'), + enb: require('./normalize/v2') }; module.exports = (decl, opts) => { opts || (opts = {}); - return opts.format ? normalizers[opts.format](decl) : normalizers.v2(decl); + const format = opts.format || 'v2'; + + return normalizer[format](decl); }; diff --git a/lib/normalize/normalize-harmony.js b/lib/normalize/harmony.js similarity index 100% rename from lib/normalize/normalize-harmony.js rename to lib/normalize/harmony.js diff --git a/lib/normalize/normalize.js b/lib/normalize/v1.js similarity index 100% rename from lib/normalize/normalize.js rename to lib/normalize/v1.js diff --git a/lib/normalize/normalize2.js b/lib/normalize/v2.js similarity index 100% rename from lib/normalize/normalize2.js rename to lib/normalize/v2.js diff --git a/lib/parse.js b/lib/parse.js index 23106b7..c403c1e 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -5,9 +5,9 @@ const assert = require('assert'); const nodeEval = require('node-eval'); const detect = require('./detect'); -const normalize = require('./normalize/normalize'); -const normalize2 = require('./normalize/normalize2'); -const normalizeHarmony = require('./normalize/normalize-harmony'); +const normalize = require('./normalize/v1'); +const normalize2 = require('./normalize/v2'); +const normalizeHarmony = require('./normalize/harmony'); const normalizers = { v1: normalize, diff --git a/test/index.test.js b/test/index.test.js index 3255852..4a2be7d 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -31,41 +31,6 @@ test('should support `BEMDECL 2.0` format', t => { t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); }); -test('should have `normalizer` method', t => { - t.truthy(typeof bemDecl.normalizer === 'function'); -}); - -test('normalizer should support default value as `normalize`', t => { - var decl = bemDecl.normalizer('v1')(decls.v1); - - t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); -}); - -test('should support `BEMDECL 1.0` format through normalizer', t => { - var decl = bemDecl.normalizer('v1')(decls.v1); - - t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); -}); - -// TODO: define name of format -test('should have support `BEMDECL x.0` format through normalizer', t => { - var decl = bemDecl.normalizer('v2')(decls.v2); - - t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); -}) - -test('should support `BEMDECL 2.0` format through normalizer', t => { - var decl = bemDecl.normalizer('harmony')(decls.v2); - - t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); -}); - -test('should support uncorrect normalizer arg with default result', t => { - var decl = bemDecl.normalizer('levoe')(decls.v2); - - t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); -}); - test('should have `merge` method', t => { t.truthy(typeof bemDecl.merge === 'function'); }); diff --git a/test/normalize-harmony/block.test.js b/test/normalize-harmony/block.test.js index 4744539..d5fad5c 100644 --- a/test/normalize-harmony/block.test.js +++ b/test/normalize-harmony/block.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support block', t => { var block = { block: 'block' }; diff --git a/test/normalize-harmony/common.test.js b/test/normalize-harmony/common.test.js index d0edc12..3ce526e 100644 --- a/test/normalize-harmony/common.test.js +++ b/test/normalize-harmony/common.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support undefined', t => { t.deepEqual(normalize(), []); diff --git a/test/normalize-harmony/elem.test.js b/test/normalize-harmony/elem.test.js index 7820267..c16b51b 100644 --- a/test/normalize-harmony/elem.test.js +++ b/test/normalize-harmony/elem.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support elem', t => { const decl = { block: 'block', elem: 'elem' }; diff --git a/test/normalize-harmony/elems.test.js b/test/normalize-harmony/elems.test.js index e2f5645..d95d9c4 100644 --- a/test/normalize-harmony/elems.test.js +++ b/test/normalize-harmony/elems.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support strings', t => { const decl = { diff --git a/test/normalize-harmony/mix.test.js b/test/normalize-harmony/mix.test.js index f443101..8d22f6b 100644 --- a/test/normalize-harmony/mix.test.js +++ b/test/normalize-harmony/mix.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support mix', t => { const decl = { diff --git a/test/normalize-harmony/mods.test.js b/test/normalize-harmony/mods.test.js index 02b46c4..3a7434c 100644 --- a/test/normalize-harmony/mods.test.js +++ b/test/normalize-harmony/mods.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support shortcut for bool mod', t => { const decl = { block: 'block', modName: 'mod' }; diff --git a/test/normalize-harmony/scope.test.js b/test/normalize-harmony/scope.test.js index c4e8c5a..903ab22 100644 --- a/test/normalize-harmony/scope.test.js +++ b/test/normalize-harmony/scope.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support mod in block scope', t => { const decl = { diff --git a/test/normalize/common.test.js b/test/normalize/common.test.js index d4b89e8..c772d6b 100644 --- a/test/normalize/common.test.js +++ b/test/normalize/common.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v1'); +const normalize = require('../../lib/normalize/v1'); test('should support undefined', t => { t.deepEqual(normalize(), []); diff --git a/test/normalize/elems.test.js b/test/normalize/elems.test.js index f8df016..54c3a84 100644 --- a/test/normalize/elems.test.js +++ b/test/normalize/elems.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v1'); +const normalize = require('../../lib/normalize/v1'); test('should support arrays', t => { const decl = { diff --git a/test/normalize/mods.test.js b/test/normalize/mods.test.js index 58f1201..2c85a7b 100644 --- a/test/normalize/mods.test.js +++ b/test/normalize/mods.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v1'); +const normalize = require('../../lib/normalize/v1'); test('should support objects', t => { const decl = { name: 'block', mods: [{ name: 'mod', vals: [{ name: 'val' }] }] }; diff --git a/test/normalize2/block-mod.test.js b/test/normalize2/block-mod.test.js index 0f787f9..f82787c 100644 --- a/test/normalize2/block-mod.test.js +++ b/test/normalize2/block-mod.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support mod', t => { const decl = { diff --git a/test/normalize2/block-mods.test.js b/test/normalize2/block-mods.test.js index 9ac09f8..f28c185 100644 --- a/test/normalize2/block-mods.test.js +++ b/test/normalize2/block-mods.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('sould support mods', t => { const decl = { diff --git a/test/normalize2/block.test.js b/test/normalize2/block.test.js index ba72560..b0746de 100644 --- a/test/normalize2/block.test.js +++ b/test/normalize2/block.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support block', t => { t.deepEqual(normalize({ block: 'block' }), [ diff --git a/test/normalize2/common.test.js b/test/normalize2/common.test.js index d6f8700..f3dee38 100644 --- a/test/normalize2/common.test.js +++ b/test/normalize2/common.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support undefined', t => { t.deepEqual(normalize(), []); diff --git a/test/normalize2/elem-mod.test.js b/test/normalize2/elem-mod.test.js index ee4aca4..6342bdd 100644 --- a/test/normalize2/elem-mod.test.js +++ b/test/normalize2/elem-mod.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support shortcut for bool mod of elem', t => { const decl = { block: 'block', elem: 'elem', mod: 'mod' }; diff --git a/test/normalize2/elem-mods.test.js b/test/normalize2/elem-mods.test.js index 976f7ed..9b411f2 100644 --- a/test/normalize2/elem-mods.test.js +++ b/test/normalize2/elem-mods.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support elem as object and mod', t => { const decl = { diff --git a/test/normalize2/elem.test.js b/test/normalize2/elem.test.js index 6deae66..dac7171 100644 --- a/test/normalize2/elem.test.js +++ b/test/normalize2/elem.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support elem', t => { const decl = { block: 'block', elem: 'elem' }; diff --git a/test/normalize2/elems-mod.test.js b/test/normalize2/elems-mod.test.js index 9de8e00..65f5098 100644 --- a/test/normalize2/elems-mod.test.js +++ b/test/normalize2/elems-mod.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support shortcut for bool mod of elem', t => { const decl = { block: 'block', elems: 'elem', mod: 'mod' }; diff --git a/test/normalize2/elems-mods.test.js b/test/normalize2/elems-mods.test.js index 1ec44dc..644dd82 100644 --- a/test/normalize2/elems-mods.test.js +++ b/test/normalize2/elems-mods.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support elem as object and mod', t => { const decl = { diff --git a/test/normalize2/elems.test.js b/test/normalize2/elems.test.js index fbd1663..8d0d6f3 100644 --- a/test/normalize2/elems.test.js +++ b/test/normalize2/elems.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support elems', t => { const decl = { block: 'block', elems: 'elem' }; diff --git a/test/normalize2/iterable.test.js b/test/normalize2/iterable.test.js index 81ac400..c2c3fa8 100644 --- a/test/normalize2/iterable.test.js +++ b/test/normalize2/iterable.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support iterable set', t => { const decl = new Set(); diff --git a/test/normalize2/mod-mods-vals.test.js b/test/normalize2/mod-mods-vals.test.js index 3cada11..e6577f6 100644 --- a/test/normalize2/mod-mods-vals.test.js +++ b/test/normalize2/mod-mods-vals.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support mod and mods without block, elem', t => { const decl = [ diff --git a/test/normalize2/unusual.test.js b/test/normalize2/unusual.test.js index e156799..7b2703b 100644 --- a/test/normalize2/unusual.test.js +++ b/test/normalize2/unusual.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib').normalizer('v2'); +const normalize = require('../../lib/normalize/v2'); test('should support both mod and mods', t => { const decl = {