pretty-lights
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -6,4 +6,24 @@ "use strict"; | ||
}); | ||
exports.replaceClassNamesInFinalCode = void 0; | ||
exports.defaultClassNameReplacer = defaultClassNameReplacer; | ||
exports.replaceClassNamesInFinalCode = exports.cleanupRogueClassNames = exports.replaceAllPatterns = exports.rogueCssKeyPattern = exports.rogueClassNamePattern = void 0; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var rogueClassNamePattern = /\be[a-zA-Z0-9]+[0-9]+\b/g; | ||
exports.rogueClassNamePattern = rogueClassNamePattern; | ||
var rogueCssKeyPattern = /\b(css-([^g]|g[^l]|gl[^o]|glo[^b]|glob[^a]|globa[^l])\w*)\b/g; | ||
exports.rogueCssKeyPattern = rogueCssKeyPattern; | ||
function defaultClassNameReplacer(className, index) { | ||
@@ -14,3 +34,2 @@ return "lights-".concat(index); | ||
var componentSelectorClassNamePattern = /^e[a-zA-Z0-9]+[0-9]+$/; | ||
var rogueClassNamePattern = /\be[a-zA-Z0-9]+[0-9]+\b/; | ||
@@ -21,2 +40,33 @@ function escapeRegex(pattern) { | ||
var replaceAllPatterns = function replaceAllPatterns(pattern, code, index) { | ||
var classNameReplacer = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : defaultClassNameReplacer; | ||
var fixed = "".concat(code); | ||
var regex; // eslint-disable-next-line no-restricted-syntax | ||
var _iterator = _createForOfIteratorHelper(fixed.matchAll(pattern)), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _step$value = _slicedToArray(_step.value, 1), | ||
_className = _step$value[0]; | ||
regex = new RegExp(_className, 'g'); | ||
fixed = fixed.replace(regex, classNameReplacer(_className, index)); | ||
index += 1; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return { | ||
fixed: fixed, | ||
index: index | ||
}; | ||
}; | ||
exports.replaceAllPatterns = replaceAllPatterns; | ||
var cleanupRogueClassNames = function cleanupRogueClassNames(code, index) { | ||
@@ -29,10 +79,10 @@ var classNameReplacer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultClassNameReplacer; | ||
var rogueStringPatterns = [rogueClassNamePattern, rogueCssKeyPattern]; | ||
var fixed = "".concat(code); | ||
rogueStringPatterns.forEach(function (pattern) { | ||
var _replaceAllPatterns = replaceAllPatterns(pattern, fixed, index, classNameReplacer); | ||
while (rogueClassNamePattern.test(fixed)) { | ||
var _className = rogueClassNamePattern.exec(code)[0]; | ||
index += 1; | ||
fixed = fixed.replace(rogueClassNamePattern, classNameReplacer(_className, index)); | ||
} | ||
index = _replaceAllPatterns.index; | ||
fixed = _replaceAllPatterns.fixed; | ||
}); | ||
return fixed; | ||
@@ -42,2 +92,4 @@ }; // eslint-disable-next-line import/prefer-default-export | ||
exports.cleanupRogueClassNames = cleanupRogueClassNames; | ||
var replaceClassNamesInFinalCode = function replaceClassNamesInFinalCode(classNames, styles, code, keys) { | ||
@@ -58,5 +110,5 @@ var classNameReplacer = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : defaultClassNameReplacer; | ||
}, "".concat(styles).concat(space).concat(code)); | ||
return replacedCode; //cleanupRogueClassNames(replacedCode, index); | ||
return cleanupRogueClassNames(replacedCode, index, classNameReplacer); | ||
}; | ||
exports.replaceClassNamesInFinalCode = replaceClassNamesInFinalCode; |
{ | ||
"name": "pretty-lights", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"description": "CSS-in-JS with a reliable API", | ||
@@ -5,0 +5,0 @@ "main": "lib/pretty-lights.js", |
@@ -58,15 +58,15 @@ # pretty-lights | ||
Instructions on using the Babel plugin: [docs](https://nytimes.github.com/pretty-lights/docs/integrations/babel) | ||
Instructions on using the Babel plugin: [docs](https://nytimes.github.io/pretty-lights/docs/integrations/babel) | ||
## Documentation | ||
[https://nytimes.github.com/pretty-lights] | ||
[https://nytimes.github.io/pretty-lights] | ||
### Core API | ||
- [`css`](https://nytimes.github.com/pretty-lights/docs/api/css) | ||
- [`cx`](https://nytimes.github.com/pretty-lights/docs/api/cx) | ||
- [`keyframes`](https://nytimes.github.com/pretty-lights/docs/api/keyframes) | ||
- [`injectGlobal`](https://nytimes.github.com/pretty-lights/docs/api/injectGlobal) | ||
- [`Global`](https://nytimes.github.com/pretty-lights/docs/api/global) | ||
- [`css`](https://nytimes.github.io/pretty-lights/docs/api/css) | ||
- [`cx`](https://nytimes.github.io/pretty-lights/docs/api/cx) | ||
- [`keyframes`](https://nytimes.github.io/pretty-lights/docs/api/keyframes) | ||
- [`injectGlobal`](https://nytimes.github.io/pretty-lights/docs/api/injectGlobal) | ||
- [`Global`](https://nytimes.github.io/pretty-lights/docs/api/global) | ||
@@ -79,23 +79,23 @@ ### Styled Components | ||
- [`ThemeProvider`](https://nytimes.github.com/pretty-lights/docs/theming/ThemeProvider) | ||
- [`withTheme`](https://nytimes.github.com/pretty-lights/docs/theming/withTheme) | ||
- [`useTheme`](https://nytimes.github.com/pretty-lights/docs/theming/useTheme) | ||
- [`themeFn`](https://nytimes.github.com/pretty-lights/docs/theming/themeFn) | ||
- [`ThemeProvider`](https://nytimes.github.io/pretty-lights/docs/theming/ThemeProvider) | ||
- [`withTheme`](https://nytimes.github.io/pretty-lights/docs/theming/withTheme) | ||
- [`useTheme`](https://nytimes.github.io/pretty-lights/docs/theming/useTheme) | ||
- [`themeFn`](https://nytimes.github.io/pretty-lights/docs/theming/themeFn) | ||
### SSR | ||
- [`extractCritical`](https://nytimes.github.com/pretty-lights/docs/ssr/extractCritical) | ||
- [`hydrate`](https://nytimes.github.com/pretty-lights/docs/ssr/hydrate) | ||
- [`renderStylesToString`](https://nytimes.github.com/pretty-lights/docs/ssr/renderStylesToString) | ||
- [`extractCritical`](https://nytimes.github.io/pretty-lights/docs/ssr/extractCritical) | ||
- [`hydrate`](https://nytimes.github.io/pretty-lights/docs/ssr/hydrate) | ||
- [`renderStylesToString`](https://nytimes.github.io/pretty-lights/docs/ssr/renderStylesToString) | ||
### Jest | ||
- [`pretty-lights/jest`](https://nytimes.github.com/pretty-lights/docs/integrations/jest) | ||
- [`pretty-lights/jest`](https://nytimes.github.io/pretty-lights/docs/integrations/jest) | ||
### Babel | ||
- [`pretty-lights/babel`](https://nytimes.github.com/pretty-lights/docs/integrations/babel) | ||
- [`pretty-lights/babel`](https://nytimes.github.io/pretty-lights/docs/integrations/babel) | ||
### ESLint | ||
- [`eslint-plugin-pretty-lights`](https://nytimes.github.com/pretty-lights/docs/integrations/eslint) | ||
- [`eslint-plugin-pretty-lights`](https://nytimes.github.io/pretty-lights/docs/integrations/eslint) |
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
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
239049
1229
0