Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-icon

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-icon - npm Package Compare versions

Comparing version 6.0.9 to 7.0.0-alpha.1

lib-old/config.js

224

lib/index.js

@@ -7,24 +7,12 @@ "use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _postcss = require("postcss");
var _utils = require("./utils.js");
var _LazyIconSet = require("./LazyIconSet.js");
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 _config = require("./config");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var NAME = "postcss-icon";
exports.default = (0, _postcss.plugin)(NAME, function () {
for (var _len = arguments.length, listIconData = Array(_len), _key = 0; _key < _len; _key++) {
listIconData[_key] = arguments[_key];
}
if (listIconData.length === 0) {
console.log(`[${NAME}]`, "Error: Options data for the css icon can not be empty!");
return function (root) {
exports.default = (0, _postcss.plugin)(_config.NAME, options => {
if (!options) {
console.log(`[${_config.NAME}]`, "Error: Options data for the css icon can not be empty!");
return root => {
walkAtRuleIcon(root, nodeToComment);

@@ -34,23 +22,14 @@ };

listIconData = listIconData.length === 1 ? Array.isArray(listIconData[0]) ? listIconData[0] : [listIconData[0]] : listIconData;
const lazy = new _LazyIconSet.LazyIconSet(options);
var AllIcons = getMapAllIcons(listIconData);
return (root, result) => {
// Step 1: find all icons in this file
walkAtRuleIcon(root, atRuleIcon => {
const iconAdded = lazy.addIcon({
root: closestRoot(atRuleIcon),
parent: atRuleIcon.parent,
iconName: clearValue(atRuleIcon.params)
});
return function (root, result) {
var currentList = new Map();
// Step 1: find all icons in this file
walkAtRuleIcon(root, function (atRuleIcon) {
var iconName = clearValue(atRuleIcon.params);
if (AllIcons.has(iconName)) {
var rootOrMq = closestRoot(atRuleIcon);
if (!currentList.has(rootOrMq)) {
currentList.set(rootOrMq, new Map());
}
var rootMap = currentList.get(rootOrMq);
if (!rootMap.get(iconName)) {
rootMap.set(iconName, []);
}
var iconMap = rootMap.get(iconName);
iconMap.push(atRuleIcon.parent);
if (iconAdded) {
atRuleIcon.remove();

@@ -64,62 +43,6 @@ } else {

// Step 2: Extend all finded icons
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = currentList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref = _step.value;
var _ref2 = _slicedToArray(_ref, 2);
var rootOrMq = _ref2[0];
var nodesSet = _ref2[1];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = nodesSet[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _ref3 = _step2.value;
var _ref4 = _slicedToArray(_ref3, 2);
var iconName = _ref4[0];
var nodes = _ref4[1];
processExtend({
extendRules: AllIcons.get(iconName),
userRules: nodes,
parent: rootOrMq
});
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return lazy.applySet({
root,
result
}); // return Promise
};

@@ -134,3 +57,3 @@ });

function walkAtRuleIcon(root, func) {
root.walkAtRules(function (atRuleIcon) {
root.walkAtRules(atRuleIcon => {
if (atRuleIcon.name && atRuleIcon.name === "icon" || atRuleIcon.name === "icon:") {

@@ -142,95 +65,2 @@ func(atRuleIcon);

function getMapAllIcons(listIconData) {
return listIconData.map(function (_ref5) {
var _ref5$prefix = _ref5.prefix,
prefix = _ref5$prefix === undefined ? "" : _ref5$prefix,
_ref5$data = _ref5.data,
data = _ref5$data === undefined ? {} : _ref5$data;
return prefixIconNames(prefix, data);
}).reduce(function (allIcons, isonSet) {
(0, _utils.objectMap)(isonSet, function (nodes, iconName) {
if (allIcons.has(iconName)) {
console.log(`[${NAME}]`, `Warn: the iconName \`${iconName}\` already declared! Use a different prefix to avoid conflicts.`);
} else {
allIcons.set(iconName, nodes);
}
});
return allIcons;
}, new Map());
}
function isOneUseIcon(userRules) {
return userRules.length === 1;
}
function processExtend(_ref6) {
var extendRules = _ref6.extendRules,
userRules = _ref6.userRules,
parent = _ref6.parent;
if (userRules.length !== 0) {
var allSelectors = userRules.map(function (_ref7) {
var selector = _ref7.selector;
return selector;
});
var tmpRoot = (0, _postcss.parse)(extendRules.join("\n"));
var isOneUseRule = isOneUseIcon(userRules);
var tmpCloner = void 0;
if (isOneUseRule) {
tmpCloner = new TmpContainer({ toNode: userRules[0] });
}
tmpRoot.walkRules(function (rule) {
if (isOneUseRule && rule.selector === ".extend") {
tmpCloner.addProps(rule);
rule.remove();
} else {
var extendedSelector = rule.selectors.map(function (selector) {
return allSelectors.map(function (userSelect) {
return selector.replace(/\.extend/g, userSelect.trim());
}).join(",");
}).join(",");
rule.selector = extendedSelector;
}
});
if (isOneUseRule) {
tmpCloner.cloneProps();
}
if (tmpRoot.nodes.length) {
parent.insertBefore(userRules[0], tmpRoot.nodes);
}
}
}
var TmpContainer = function () {
function TmpContainer(_ref8) {
var toNode = _ref8.toNode;
_classCallCheck(this, TmpContainer);
this.toNode = toNode;
this.tmpNodes = [];
}
_createClass(TmpContainer, [{
key: "addProps",
value: function addProps(fromNode) {
var _tmpNodes;
(_tmpNodes = this.tmpNodes).push.apply(_tmpNodes, _toConsumableArray(fromNode.nodes));
}
}, {
key: "cloneProps",
value: function cloneProps() {
if (this.tmpNodes.length !== 0) {
var _toNode;
(_toNode = this.toNode).prepend.apply(_toNode, _toConsumableArray(this.tmpNodes));
}
}
}]);
return TmpContainer;
}();
function clearValue(val) {

@@ -240,13 +70,3 @@ return val.replace(/['"]/g, "");

function prefixIconNames(prefix, obj) {
var tmp = {};
(0, _utils.objectMap)(obj, function (val, key) {
tmp[prefix + key] = val;
});
return tmp;
}
function closestRoot(_ref9) {
var parent = _ref9.parent;
function closestRoot({ parent }) {
if (parent === undefined) {

@@ -253,0 +73,0 @@ return false;

{
"name": "postcss-icon",
"description": "PostCSS plugin which allows you to quickly add styles to css icons",
"version": "6.0.9",
"main": "lib/index.js",
"version": "7.0.0-alpha.1",
"repository": "https://github.com/retyui/postcss-icon",
"author": "David ♥ <vamnemne@gmail.com>",
"author": "retyui <vamnemne@gmail.com>",
"license": "MIT",
"main": "postcss-icon.js",
"files": [
"lib",
"lib-old"
],
"scripts": {
"lint": "eslint ./**/*.js",
"precompile": "npm run lint",
"compile": "babel src --out-dir lib",
"babel:modern": "cross-env BABEL_ENV=modern babel src --out-dir lib",
"babel:old": "cross-env BABEL_ENV=old babel src --out-dir lib-old",
"clean": "rimraf ./test/test.js ./lib ./lib-old",
"compile": "npm-run-all --parallel babel:* testcompile",
"lint": "eslint ./**/*.js --fix --quiet",
"precompile": "npm-run-all clean lint",
"pretest": "npm run compile",
"test": "mocha --compilers js:babel-register ./test/test.mjs"
"test": "mocha ./test/test.js",
"testcompile": "cross-env BABEL_ENV=old babel test/test.mjs --out-file test/test.js"
},
"dependencies": {
"postcss": "6"
"fonteditor-core": "^1.0.0",
"mkdirp-promise": "^5.0.1",
"postcss": "^6.0.0",
"regenerator-runtime": "^0.11.1",
"ttf2woff2": "^2.0.0",
"util.promisify": "^1.0.0"
},

@@ -27,12 +40,20 @@ "devDependencies": {

"chai": "3.5.0",
"cross-env": "^5.1.3",
"eslint": "3.19.0",
"mocha": "3.4.2",
"postcss-merge-rules": "^4.0.0-rc.2"
"npm-run-all": "^4.1.2",
"postcss-icon.font-awesome-v4": "^0.0.1",
"postcss-icon.material-design": "^0.0.2",
"postcss-merge-rules": "^4.0.0-rc.2",
"rimraf": "^2.6.2"
},
"keywords": [
"css",
"css-icon",
"postcss",
"css",
"postcss-plugin",
"css-icon"
]
"postcss-plugin"
],
"engines": {
"node": ">= 4.2"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc