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

css-scaffolder

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-scaffolder - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

2

dist/extract.d.ts
interface ExtractOptions {
ignorePatternForSingleClass?: RegExp;
modifierPattern?: RegExp;
reset?: boolean;

@@ -4,0 +4,0 @@ }

@@ -9,2 +9,3 @@ "use strict";

var parser_postcss_1 = __importDefault(require("prettier/parser-postcss"));
var underscore_1 = __importDefault(require("underscore"));
var utils_1 = require("./utils");

@@ -27,4 +28,9 @@ var reset_1 = require("./reset");

}
var defaultOptions = {
modifierPattern: /$./,
reset: false
};
function extract(htmlString, options) {
if (options === void 0) { options = {}; }
options = Object.assign({}, defaultOptions, options);
var selectors = [];

@@ -48,6 +54,8 @@ var selectorFlag = new Map();

var classNames = getClassNames(el);
if (!classNames && currentPath.length === 0) {
return;
}
if (!classNames) {
// クラス名を起点とする文脈に居るかどうかの判定
if (currentPath.length === 0) {
el.childNodes.forEach(function (el) { return retrieveClassNames(el); });
return;
}
var path_1 = currentPath.concat(el.tagName);

@@ -57,17 +65,26 @@ var selector = path_1.join('>');

el.childNodes.forEach(function (el) { return retrieveClassNames(el, path_1); });
return;
}
else {
for (var i = 1; i <= classNames.length; i += 1) {
utils_1.combination(classNames.length, i).forEach(function (index) {
if (index.length === 1 &&
options.ignorePatternForSingleClass &&
options.ignorePatternForSingleClass.test(classNames[index[0]])) {
return;
}
var selector = index.map(function (cn) { return "." + classNames[cn]; }).join('');
addSelector(selector, el);
el.childNodes.forEach(function (el) { return retrieveClassNames(el, [selector]); });
});
}
var _a = underscore_1.default.partition(classNames, function (cn) { return options.modifierPattern.test(cn); }), modifiers = _a[0], modifierExcluded = _a[1];
if (modifierExcluded.length === 0) {
el.childNodes.forEach(function (el) { return retrieveClassNames(el); });
return;
}
// モディファイア以外のクラス名は、組み合わせを列挙し
// それぞれについて子孫要素を見ていく
for (var i = 1; i <= modifierExcluded.length; i += 1) {
utils_1.combination(modifierExcluded.length, i).forEach(function (index) {
var selector = index.map(function (cn) { return "." + modifierExcluded[cn]; }).join('');
addSelector(selector, el);
el.childNodes.forEach(function (el) { return retrieveClassNames(el, [selector]); });
var _loop_1 = function (j) {
var selector2 = selector + "." + modifiers[j];
addSelector(selector2, el);
el.childNodes.forEach(function (el) { return retrieveClassNames(el, [selector2]); });
};
for (var j = 0; j < modifiers.length; j += 1) {
_loop_1(j);
}
});
}
};

@@ -74,0 +91,0 @@ var fragment = parse5_1.parseFragment(htmlString);

{
"name": "css-scaffolder",
"version": "0.2.0",
"version": "0.3.0",
"description": "Scaffold CSS declarations from HTML",

@@ -22,4 +22,6 @@ "scripts": {

"@types/jest": "^24.0.15",
"@types/node": "^12.6.2",
"@types/parse5": "^5.0.1",
"@types/prettier": "^1.16.4",
"@types/underscore": "^1.9.2",
"jest": "^24.8.0",

@@ -31,4 +33,5 @@ "ts-jest": "^24.0.2",

"parse5": "^5.1.0",
"prettier": "^1.18.2"
"prettier": "^1.18.2",
"underscore": "^1.9.1"
}
}
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