UNPKG

1.93 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.splitByPlaceholders = exports.makePlaceholder = exports.placeholderRegex = void 0;
7
8function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
9
10function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
11
12function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
13
14function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); }
15
16function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
17
18function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
19
20function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
22// The capture group makes sure that the split contains the interpolation index
23var placeholderRegex = /(?:__PLACEHOLDER_(\d+)__)/g; // Alternative regex that splits without a capture group
24
25exports.placeholderRegex = placeholderRegex;
26var placeholderNonCapturingRegex = /__PLACEHOLDER_(?:\d+)__/g; // Generates a placeholder from an index
27
28var makePlaceholder = function makePlaceholder(index) {
29 return `__PLACEHOLDER_${index}__`;
30}; // Splits CSS by placeholders
31
32
33exports.makePlaceholder = makePlaceholder;
34
35var splitByPlaceholders = function splitByPlaceholders(_ref) {
36 var _ref2 = _toArray(_ref),
37 css = _ref2[0],
38 rest = _ref2.slice(1);
39
40 var capture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
41 return [css.split(capture ? placeholderRegex : placeholderNonCapturingRegex)].concat(_toConsumableArray(rest));
42};
43
44exports.splitByPlaceholders = splitByPlaceholders;
\No newline at end of file