Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
145 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,12 @@ | ||
'use strict'; | ||
|
||
const normalize = { | ||
v1: require('./normalize'), | ||
v2: require('./normalize2'), | ||
harmony: require('./normalize-harmony'), | ||
enb: require('./normalize2') | ||
}; | ||
|
||
module.exports = { | ||
normalize: (decl, opts) => { | ||
opts || (opts = {}); | ||
|
||
return opts.format ? normalize[opts.format](decl) : normalize.v2(decl); | ||
}, | ||
normalize: require('./normalize'), | ||
merge: require('./merge'), | ||
subtract: require('./subtract'), | ||
intersect: require('./intersect'), | ||
parse: require('./parse'), | ||
assign: require('./assign'), | ||
load: require('./load'), | ||
stringify: require('./stringify'), | ||
normalizer: format => (normalize[format] || normalize.v2) | ||
stringify: require('./stringify') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,16 @@ | ||
'use strict'; | ||
|
||
const naming = require('bem-naming'); | ||
|
||
module.exports = function (decl) { | ||
const res = []; | ||
const hash = {}; | ||
|
||
function add(entity) { | ||
const str = naming.stringify(entity); | ||
|
||
if (!hash[str]) { | ||
res.push({ entity: entity, tech: null }); | ||
} | ||
|
||
hash[str] = true; | ||
} | ||
|
||
if (!decl) { return []; } | ||
if (!Array.isArray(decl)) { decl = [decl]; } | ||
|
||
for (let i = 0; i < decl.length; ++i) { | ||
const entity = decl[i]; | ||
const block = entity.name; | ||
const mods = entity.mods; | ||
const elems = entity.elems; | ||
|
||
add({ block: block }); | ||
|
||
if (mods) { | ||
normalizeMods(block, mods); | ||
} | ||
|
||
if (elems) { | ||
for (let j = 0; j < elems.length; ++j) { | ||
const elem = elems[j]; | ||
const elemName = elem.name; | ||
const elemMods = elem.mods; | ||
|
||
add({ block: block, elem: elemName }); | ||
|
||
if (elemMods) { | ||
normalizeMods(block, elemName, elemMods); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function normalizeMods(block, elem, mods) { | ||
const isElem = arguments.length === 3; | ||
|
||
if (!isElem) { | ||
mods = elem; | ||
} | ||
|
||
for (let i = 0; i < mods.length; ++i) { | ||
const mod = mods[i]; | ||
const vals = mod.vals; | ||
const l = vals && vals.length; | ||
|
||
let resItem; | ||
|
||
if (l) { | ||
for (let j = 0; j < l; ++j) { | ||
resItem = { | ||
block: block, | ||
modName: mod.name, modVal: vals[j].name | ||
}; | ||
|
||
isElem && (resItem.elem = elem); | ||
|
||
add(resItem); | ||
} | ||
} else { | ||
resItem = { | ||
block: block, | ||
modName: mod.name, modVal: true | ||
}; | ||
const normalizer = { | ||
v1: require('./normalize/v1'), | ||
v2: require('./normalize/v2'), | ||
harmony: require('./normalize/harmony'), | ||
enb: require('./normalize/v2') | ||
}; | ||
|
||
isElem && (resItem.elem = elem); | ||
module.exports = (decl, opts) => { | ||
opts || (opts = {}); | ||
|
||
add(resItem); | ||
} | ||
} | ||
} | ||
const format = opts.format || 'v2'; | ||
|
||
return res; | ||
return normalizer[format](decl); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict'; | ||
|
||
const naming = require('bem-naming'); | ||
|
||
module.exports = function (decl) { | ||
const res = []; | ||
const hash = {}; | ||
|
||
function add(entity) { | ||
const str = naming.stringify(entity); | ||
|
||
if (!hash[str]) { | ||
res.push({ entity: entity, tech: null }); | ||
} | ||
|
||
hash[str] = true; | ||
} | ||
|
||
if (!decl) { return []; } | ||
if (!Array.isArray(decl)) { decl = [decl]; } | ||
|
||
for (let i = 0; i < decl.length; ++i) { | ||
const entity = decl[i]; | ||
const block = entity.name; | ||
const mods = entity.mods; | ||
const elems = entity.elems; | ||
|
||
add({ block: block }); | ||
|
||
if (mods) { | ||
normalizeMods(block, mods); | ||
} | ||
|
||
if (elems) { | ||
for (let j = 0; j < elems.length; ++j) { | ||
const elem = elems[j]; | ||
const elemName = elem.name; | ||
const elemMods = elem.mods; | ||
|
||
add({ block: block, elem: elemName }); | ||
|
||
if (elemMods) { | ||
normalizeMods(block, elemName, elemMods); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function normalizeMods(block, elem, mods) { | ||
const isElem = arguments.length === 3; | ||
|
||
if (!isElem) { | ||
mods = elem; | ||
} | ||
|
||
for (let i = 0; i < mods.length; ++i) { | ||
const mod = mods[i]; | ||
const vals = mod.vals; | ||
const hasVals = vals && vals.length; | ||
|
||
let resItem; | ||
let j = 0; | ||
|
||
do { | ||
resItem = { | ||
block: block, | ||
modName: mod.name, | ||
modVal: hasVals ? vals[j].name : true | ||
}; | ||
|
||
isElem && (resItem.elem = elem); | ||
|
||
add(resItem); | ||
++j; | ||
} while (j < hasVals); | ||
} | ||
} | ||
|
||
return res; | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.