icss-utils
Advanced tools
Comparing version 3.0.1 to 4.0.0
@@ -13,14 +13,10 @@ "use strict"; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var createImports = function createImports(imports) { | ||
return Object.keys(imports).map(function (path) { | ||
var aliases = imports[path]; | ||
var declarations = Object.keys(aliases).map(function (key) { | ||
return _postcss2.default.decl({ | ||
prop: key, | ||
value: aliases[key], | ||
raws: { before: "\n " } | ||
}); | ||
}); | ||
const createImports = imports => { | ||
return Object.keys(imports).map(path => { | ||
const aliases = imports[path]; | ||
const declarations = Object.keys(aliases).map(key => _postcss2.default.decl({ | ||
prop: key, | ||
value: aliases[key], | ||
raws: { before: "\n " } | ||
})); | ||
return _postcss2.default.rule({ | ||
@@ -33,14 +29,12 @@ selector: `:import('${path}')`, | ||
var createExports = function createExports(exports) { | ||
var declarations = Object.keys(exports).map(function (key) { | ||
return _postcss2.default.decl({ | ||
prop: key, | ||
value: exports[key], | ||
raws: { before: "\n " } | ||
}); | ||
}); | ||
const createExports = exports => { | ||
const declarations = Object.keys(exports).map(key => _postcss2.default.decl({ | ||
prop: key, | ||
value: exports[key], | ||
raws: { before: "\n " } | ||
})); | ||
if (declarations.length === 0) { | ||
return []; | ||
} | ||
var rule = _postcss2.default.rule({ | ||
const rule = _postcss2.default.rule({ | ||
selector: `:export`, | ||
@@ -52,6 +46,4 @@ raws: { after: "\n" } | ||
var createICSSRules = function createICSSRules(imports, exports) { | ||
return [].concat(_toConsumableArray(createImports(imports)), _toConsumableArray(createExports(exports))); | ||
}; | ||
const createICSSRules = (imports, exports) => [...createImports(imports), ...createExports(exports)]; | ||
exports.default = createICSSRules; |
@@ -6,7 +6,7 @@ "use strict"; | ||
}); | ||
var importPattern = /^:import\(("[^"]*"|'[^']*'|[^"']+)\)$/; | ||
const importPattern = /^:import\(("[^"]*"|'[^']*'|[^"']+)\)$/; | ||
var getDeclsObject = function getDeclsObject(rule) { | ||
var object = {}; | ||
rule.walkDecls(function (decl) { | ||
const getDeclsObject = rule => { | ||
const object = {}; | ||
rule.walkDecls(decl => { | ||
object[decl.raws.before.trim() + decl.prop] = decl.value; | ||
@@ -17,14 +17,12 @@ }); | ||
var extractICSS = function extractICSS(css) { | ||
var removeRules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var icssImports = {}; | ||
var icssExports = {}; | ||
css.each(function (node) { | ||
const extractICSS = (css, removeRules = true) => { | ||
const icssImports = {}; | ||
const icssExports = {}; | ||
css.each(node => { | ||
if (node.type === "rule") { | ||
if (node.selector.slice(0, 7) === ":import") { | ||
var matches = importPattern.exec(node.selector); | ||
const matches = importPattern.exec(node.selector); | ||
if (matches) { | ||
var path = matches[1].replace(/'|"/g, ""); | ||
var aliases = Object.assign(icssImports[path] || {}, getDeclsObject(node)); | ||
const path = matches[1].replace(/'|"/g, ""); | ||
const aliases = Object.assign(icssImports[path] || {}, getDeclsObject(node)); | ||
icssImports[path] = aliases; | ||
@@ -31,0 +29,0 @@ if (removeRules) { |
@@ -13,4 +13,4 @@ "use strict"; | ||
var replaceSymbols = function replaceSymbols(css, replacements) { | ||
css.walk(function (node) { | ||
const replaceSymbols = (css, replacements) => { | ||
css.walk(node => { | ||
if (node.type === "decl") { | ||
@@ -17,0 +17,0 @@ node.value = (0, _replaceValueSymbols2.default)(node.value, replacements); |
@@ -6,8 +6,8 @@ "use strict"; | ||
}); | ||
var matchValueName = /[$]?[\w-]+/g; | ||
const matchValueName = /[$]?[\w-]+/g; | ||
var replaceValueSymbols = function replaceValueSymbols(value, replacements) { | ||
var matches = void 0; | ||
const replaceValueSymbols = (value, replacements) => { | ||
let matches; | ||
while (matches = matchValueName.exec(value)) { | ||
var replacement = replacements[matches[0]]; | ||
const replacement = replacements[matches[0]]; | ||
if (replacement) { | ||
@@ -14,0 +14,0 @@ value = value.slice(0, matches.index) + replacement + value.slice(matchValueName.lastIndex); |
{ | ||
"name": "icss-utils", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"description": "ICSS utils for postcss ast", | ||
"main": "lib/index.js", | ||
"engines": { | ||
"node": ">= 6" | ||
}, | ||
"files": [ | ||
@@ -37,3 +40,3 @@ "lib" | ||
"targets": { | ||
"node": 4 | ||
"node": 6 | ||
} | ||
@@ -61,3 +64,3 @@ } | ||
"dependencies": { | ||
"postcss": "^6.0.2" | ||
"postcss": "^7.0.5" | ||
}, | ||
@@ -64,0 +67,0 @@ "devDependencies": { |
@@ -0,0 +0,0 @@ [![Build Status](https://travis-ci.org/css-modules/icss-utils.svg)](https://travis-ci.org/css-modules/icss-utils) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8746
8
141
1
+ Addedpicocolors@0.2.1(transitive)
+ Addedpostcss@7.0.39(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedpostcss@6.0.23(transitive)
- Removedsupports-color@5.5.0(transitive)
Updatedpostcss@^7.0.5