@spscommerce/utils 5.5.0-ie → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{dist/out-tsc → lib}/array/flatten.d.ts +0 -0
- package/{dist/out-tsc → lib}/array/flatten.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/array/index.d.ts +0 -0
- package/{dist/out-tsc → lib}/array/is-subset.d.ts +0 -0
- package/{dist/out-tsc → lib}/array/is-subset.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/array/range.d.ts +0 -0
- package/{dist/out-tsc → lib}/array/range.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/classes/custom-event.d.ts +0 -0
- package/{dist/out-tsc → lib}/classes/index.d.ts +0 -0
- package/{dist/out-tsc → lib}/data/doctypes.d.ts +0 -0
- package/{dist/out-tsc → lib}/data/index.d.ts +0 -0
- package/{dist/out-tsc → lib}/decorators/cast-to-number.d.ts +0 -0
- package/{dist/out-tsc → lib}/decorators/debounced.broken_spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/decorators/debounced.d.ts +0 -0
- package/{dist/out-tsc → lib}/decorators/index.d.ts +0 -0
- package/{dist/out-tsc → lib}/decorators/locked-to-animation-frames.d.ts +0 -0
- package/{dist/out-tsc → lib}/decorators/locked-to-animation-frames.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/decorators/simple-metadata-decorator-applicator.d.ts +0 -0
- package/{dist/out-tsc → lib}/decorators/tick-delay.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/debounce.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/debounce.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/debounced-function.interface.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/delayed-function.interface.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/index.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/lock-to-animation-frames.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/lock-to-animation-frames.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/on-next-tick.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/on-next-tick.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/op.d.ts +0 -0
- package/{dist/out-tsc → lib}/function/op.spec.d.ts +0 -0
- package/lib/index.cjs.js +1 -0
- package/{dist/out-tsc → lib}/index.d.ts +0 -0
- package/lib/index.es.js +1024 -0
- package/{dist/out-tsc → lib}/number/constrain.d.ts +0 -0
- package/{dist/out-tsc → lib}/number/decimal-round.d.ts +0 -0
- package/{dist/out-tsc → lib}/number/decimal-round.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/number/index.d.ts +0 -0
- package/{dist/out-tsc → lib}/number/to-file-size-string.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/copy-property.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/copy-property.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/crumble-path.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/crumble-path.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/deep-freeze.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/deep-freeze.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/diff.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/diff.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/for-each-entry-deep.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/for-each-entry-deep.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/for-each-nested-object.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/for-each-nested-object.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/get-path.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/get-path.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/index.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/merge-deep.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/merge-deep.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/merge-properties-deep.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/merge-properties-deep.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/omit.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/omit.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/set-path.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/set-path.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/traverse-path.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/values.d.ts +0 -0
- package/{dist/out-tsc → lib}/object/values.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/string/code.template-tag.d.ts +0 -0
- package/{dist/out-tsc → lib}/string/index.d.ts +0 -0
- package/{dist/out-tsc → lib}/string/parse-file-size.d.ts +0 -0
- package/{dist/out-tsc → lib}/string/template.d.ts +0 -0
- package/{dist/out-tsc → lib}/string/template.spec.d.ts +0 -0
- package/{dist/out-tsc → lib}/typings.d.ts +0 -0
- package/package.json +5 -5
- package/vite.config.js +1 -1
- package/.pnpm-debug.log +0 -20
- package/dist/out-tsc/array/flatten.js +0 -7
- package/dist/out-tsc/array/flatten.js.map +0 -1
- package/dist/out-tsc/array/flatten.spec.js +0 -10
- package/dist/out-tsc/array/flatten.spec.js.map +0 -1
- package/dist/out-tsc/array/index.js +0 -4
- package/dist/out-tsc/array/index.js.map +0 -1
- package/dist/out-tsc/array/is-subset.js +0 -41
- package/dist/out-tsc/array/is-subset.js.map +0 -1
- package/dist/out-tsc/array/is-subset.spec.js +0 -41
- package/dist/out-tsc/array/is-subset.spec.js.map +0 -1
- package/dist/out-tsc/array/range.js +0 -16
- package/dist/out-tsc/array/range.js.map +0 -1
- package/dist/out-tsc/array/range.spec.js +0 -26
- package/dist/out-tsc/array/range.spec.js.map +0 -1
- package/dist/out-tsc/classes/custom-event.js +0 -87
- package/dist/out-tsc/classes/custom-event.js.map +0 -1
- package/dist/out-tsc/classes/index.js +0 -2
- package/dist/out-tsc/classes/index.js.map +0 -1
- package/dist/out-tsc/data/doctypes.js +0 -302
- package/dist/out-tsc/data/doctypes.js.map +0 -1
- package/dist/out-tsc/data/index.js +0 -2
- package/dist/out-tsc/data/index.js.map +0 -1
- package/dist/out-tsc/decorators/cast-to-number.js +0 -29
- package/dist/out-tsc/decorators/cast-to-number.js.map +0 -1
- package/dist/out-tsc/decorators/debounced.broken_spec.js +0 -38
- package/dist/out-tsc/decorators/debounced.broken_spec.js.map +0 -1
- package/dist/out-tsc/decorators/debounced.js +0 -35
- package/dist/out-tsc/decorators/debounced.js.map +0 -1
- package/dist/out-tsc/decorators/index.js +0 -6
- package/dist/out-tsc/decorators/index.js.map +0 -1
- package/dist/out-tsc/decorators/locked-to-animation-frames.js +0 -34
- package/dist/out-tsc/decorators/locked-to-animation-frames.js.map +0 -1
- package/dist/out-tsc/decorators/locked-to-animation-frames.spec.js +0 -63
- package/dist/out-tsc/decorators/locked-to-animation-frames.spec.js.map +0 -1
- package/dist/out-tsc/decorators/simple-metadata-decorator-applicator.js +0 -80
- package/dist/out-tsc/decorators/simple-metadata-decorator-applicator.js.map +0 -1
- package/dist/out-tsc/decorators/tick-delay.js +0 -31
- package/dist/out-tsc/decorators/tick-delay.js.map +0 -1
- package/dist/out-tsc/function/debounce.js +0 -102
- package/dist/out-tsc/function/debounce.js.map +0 -1
- package/dist/out-tsc/function/debounce.spec.js +0 -150
- package/dist/out-tsc/function/debounce.spec.js.map +0 -1
- package/dist/out-tsc/function/debounced-function.interface.js +0 -2
- package/dist/out-tsc/function/debounced-function.interface.js.map +0 -1
- package/dist/out-tsc/function/delayed-function.interface.js +0 -2
- package/dist/out-tsc/function/delayed-function.interface.js.map +0 -1
- package/dist/out-tsc/function/index.js +0 -7
- package/dist/out-tsc/function/index.js.map +0 -1
- package/dist/out-tsc/function/lock-to-animation-frames.js +0 -43
- package/dist/out-tsc/function/lock-to-animation-frames.js.map +0 -1
- package/dist/out-tsc/function/lock-to-animation-frames.spec.js +0 -53
- package/dist/out-tsc/function/lock-to-animation-frames.spec.js.map +0 -1
- package/dist/out-tsc/function/on-next-tick.js +0 -12
- package/dist/out-tsc/function/on-next-tick.js.map +0 -1
- package/dist/out-tsc/function/on-next-tick.spec.js +0 -13
- package/dist/out-tsc/function/on-next-tick.spec.js.map +0 -1
- package/dist/out-tsc/function/op.js +0 -34
- package/dist/out-tsc/function/op.js.map +0 -1
- package/dist/out-tsc/function/op.spec.js +0 -94
- package/dist/out-tsc/function/op.spec.js.map +0 -1
- package/dist/out-tsc/index.js +0 -10
- package/dist/out-tsc/index.js.map +0 -1
- package/dist/out-tsc/number/constrain.js +0 -16
- package/dist/out-tsc/number/constrain.js.map +0 -1
- package/dist/out-tsc/number/decimal-round.js +0 -19
- package/dist/out-tsc/number/decimal-round.js.map +0 -1
- package/dist/out-tsc/number/decimal-round.spec.js +0 -10
- package/dist/out-tsc/number/decimal-round.spec.js.map +0 -1
- package/dist/out-tsc/number/index.js +0 -4
- package/dist/out-tsc/number/index.js.map +0 -1
- package/dist/out-tsc/number/to-file-size-string.js +0 -24
- package/dist/out-tsc/number/to-file-size-string.js.map +0 -1
- package/dist/out-tsc/object/copy-property.js +0 -9
- package/dist/out-tsc/object/copy-property.js.map +0 -1
- package/dist/out-tsc/object/copy-property.spec.js +0 -16
- package/dist/out-tsc/object/copy-property.spec.js.map +0 -1
- package/dist/out-tsc/object/crumble-path.js +0 -9
- package/dist/out-tsc/object/crumble-path.js.map +0 -1
- package/dist/out-tsc/object/crumble-path.spec.js +0 -24
- package/dist/out-tsc/object/crumble-path.spec.js.map +0 -1
- package/dist/out-tsc/object/deep-freeze.js +0 -36
- package/dist/out-tsc/object/deep-freeze.js.map +0 -1
- package/dist/out-tsc/object/deep-freeze.spec.js +0 -14
- package/dist/out-tsc/object/deep-freeze.spec.js.map +0 -1
- package/dist/out-tsc/object/diff.js +0 -92
- package/dist/out-tsc/object/diff.js.map +0 -1
- package/dist/out-tsc/object/diff.spec.js +0 -40
- package/dist/out-tsc/object/diff.spec.js.map +0 -1
- package/dist/out-tsc/object/for-each-entry-deep.js +0 -38
- package/dist/out-tsc/object/for-each-entry-deep.js.map +0 -1
- package/dist/out-tsc/object/for-each-entry-deep.spec.js +0 -24
- package/dist/out-tsc/object/for-each-entry-deep.spec.js.map +0 -1
- package/dist/out-tsc/object/for-each-nested-object.js +0 -38
- package/dist/out-tsc/object/for-each-nested-object.js.map +0 -1
- package/dist/out-tsc/object/for-each-nested-object.spec.js +0 -46
- package/dist/out-tsc/object/for-each-nested-object.spec.js.map +0 -1
- package/dist/out-tsc/object/get-path.js +0 -67
- package/dist/out-tsc/object/get-path.js.map +0 -1
- package/dist/out-tsc/object/get-path.spec.js +0 -44
- package/dist/out-tsc/object/get-path.spec.js.map +0 -1
- package/dist/out-tsc/object/index.js +0 -14
- package/dist/out-tsc/object/index.js.map +0 -1
- package/dist/out-tsc/object/merge-deep.js +0 -60
- package/dist/out-tsc/object/merge-deep.js.map +0 -1
- package/dist/out-tsc/object/merge-deep.spec.js +0 -16
- package/dist/out-tsc/object/merge-deep.spec.js.map +0 -1
- package/dist/out-tsc/object/merge-properties-deep.js +0 -61
- package/dist/out-tsc/object/merge-properties-deep.js.map +0 -1
- package/dist/out-tsc/object/merge-properties-deep.spec.js +0 -24
- package/dist/out-tsc/object/merge-properties-deep.spec.js.map +0 -1
- package/dist/out-tsc/object/omit.js +0 -40
- package/dist/out-tsc/object/omit.js.map +0 -1
- package/dist/out-tsc/object/omit.spec.js +0 -10
- package/dist/out-tsc/object/omit.spec.js.map +0 -1
- package/dist/out-tsc/object/set-path.js +0 -45
- package/dist/out-tsc/object/set-path.js.map +0 -1
- package/dist/out-tsc/object/set-path.spec.js +0 -36
- package/dist/out-tsc/object/set-path.spec.js.map +0 -1
- package/dist/out-tsc/object/traverse-path.js +0 -81
- package/dist/out-tsc/object/traverse-path.js.map +0 -1
- package/dist/out-tsc/object/values.js +0 -31
- package/dist/out-tsc/object/values.js.map +0 -1
- package/dist/out-tsc/object/values.spec.js +0 -7
- package/dist/out-tsc/object/values.spec.js.map +0 -1
- package/dist/out-tsc/string/code.template-tag.js +0 -38
- package/dist/out-tsc/string/code.template-tag.js.map +0 -1
- package/dist/out-tsc/string/index.js +0 -4
- package/dist/out-tsc/string/index.js.map +0 -1
- package/dist/out-tsc/string/parse-file-size.js +0 -43
- package/dist/out-tsc/string/parse-file-size.js.map +0 -1
- package/dist/out-tsc/string/template.js +0 -28
- package/dist/out-tsc/string/template.js.map +0 -1
- package/dist/out-tsc/string/template.spec.js +0 -39
- package/dist/out-tsc/string/template.spec.js.map +0 -1
- package/dist/out-tsc/typings.js +0 -2
- package/dist/out-tsc/typings.js.map +0 -1
- package/rollup.config.js +0 -22
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"values.spec.js","sourceRoot":"","sources":["../../../src/object/values.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,QAAQ,CAAC,QAAQ,EAAE;IACjB,IAAI,CAAC,mCAAmC,EAAE;QACxC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
-
if (ar || !(i in from)) {
|
|
20
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
-
ar[i] = from[i];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
-
};
|
|
26
|
-
/** Template tag function for making strings containing code blocks easier to deal with. */
|
|
27
|
-
export function code(strings) {
|
|
28
|
-
var interpolations = [];
|
|
29
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
30
|
-
interpolations[_i - 1] = arguments[_i];
|
|
31
|
-
}
|
|
32
|
-
var s = strings.reduce(function (a, b, i) { return "".concat(a).concat(i <= interpolations.length ? String(interpolations[i - 1]) : "").concat(b); });
|
|
33
|
-
var leadingWhitespace = Math.min.apply(Math, __spreadArray([], __read(s.split(/[\r\n]/)
|
|
34
|
-
.filter(function (l) { return l.trim(); })
|
|
35
|
-
.map(function (l) { return (/^ */.exec(l))[0].length; })), false));
|
|
36
|
-
return s.replace(new RegExp("^ {".concat(leadingWhitespace, "}"), "gm"), "").trim();
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=code.template-tag.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"code.template-tag.js","sourceRoot":"","sources":["../../../src/string/code.template-tag.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2FAA2F;AAC3F,MAAM,UAAU,IAAI,CAAC,OAA6B;IAAE,wBAA4B;SAA5B,UAA4B,EAA5B,qBAA4B,EAA5B,IAA4B;QAA5B,uCAA4B;;IAC9E,IAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAK,OAAA,UAAG,CAAC,SAAG,CAAC,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAG,CAAC,CAAE,EAA5E,CAA4E,CAAC,CAAC;IACpH,IAAM,iBAAiB,GAAG,IAAI,CAAC,GAAG,OAAR,IAAI,2BACzB,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;SACjB,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,IAAI,EAAE,EAAR,CAAQ,CAAC;SACvB,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAzB,CAAyB,CAAC,UACzC,CAAC;IACF,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,aAAM,iBAAiB,MAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5E,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Parses a string as a file size and returns the size in bytes. For example,
|
|
19
|
-
* `parseFileSize("2KB")` will return `2048`.
|
|
20
|
-
*/
|
|
21
|
-
export function parseFileSize(fileSize) {
|
|
22
|
-
var unitMatch = /[A-Z]?B$/.exec(fileSize);
|
|
23
|
-
if (!unitMatch) {
|
|
24
|
-
throw new Error("Input to parseFileSize (\"".concat(fileSize, "\") doesn't seem like a file size; ")
|
|
25
|
-
+ "cannot identify a unit (e.g. KB, GB)");
|
|
26
|
-
}
|
|
27
|
-
var _a = __read(unitMatch, 1), unit = _a[0];
|
|
28
|
-
var num = Number(fileSize.replace(unit, ""));
|
|
29
|
-
if (Number.isNaN(num)) {
|
|
30
|
-
throw new Error("Could not parse a number out of input to parseFileSize (\"".concat(fileSize, "\")"));
|
|
31
|
-
}
|
|
32
|
-
var magnitude = ["B",
|
|
33
|
-
"KB",
|
|
34
|
-
"MB",
|
|
35
|
-
"GB",
|
|
36
|
-
"TB",
|
|
37
|
-
"PB"].indexOf(unit);
|
|
38
|
-
if (magnitude === -1) {
|
|
39
|
-
throw new Error("parseFileSize does not support units above PB");
|
|
40
|
-
}
|
|
41
|
-
return Math.ceil(num * (Math.pow(1024, magnitude)));
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=parse-file-size.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-file-size.js","sourceRoot":"","sources":["../../../src/string/parse-file-size.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,IAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CACb,oCAA4B,QAAQ,wCAAoC;cAChE,sCAAsC,CAC/C,CAAC;KACH;IAEK,IAAA,KAAA,OAAS,SAAS,IAAA,EAAjB,IAAI,QAAa,CAAC;IACzB,IAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAC/C,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,oEAA4D,QAAQ,QAAI,CAAC,CAAC;KAC3F;IAED,IAAM,SAAS,GAAG,CAAC,GAAG;QACpB,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,IAAI,SAAS,KAAK,CAAC,CAAC,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;KAClE;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,SAAA,IAAI,EAAI,SAAS,CAAA,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { getPath } from "../object";
|
|
2
|
-
var REGEX_REPLACEMENT = /(<%=|{{)(.+?)(%>|}})/g;
|
|
3
|
-
var REGEX_IF = /<%\?(.+?)%>(.+?)<\/%>/g;
|
|
4
|
-
var SYMBOL_TEMPLATE_SOURCE = Symbol("sps.utils.templateSrc");
|
|
5
|
-
/**
|
|
6
|
-
* Every string templating thing out there whether lodash, doT, handlebars, etc
|
|
7
|
-
* is extremely complicated to cover a variety of use cases. This just has two
|
|
8
|
-
* very simple features and great caution should be exercised in making it any more
|
|
9
|
-
* complex than that. A value can be interpolated like so:
|
|
10
|
-
* `<%= foo.bar %>`
|
|
11
|
-
* And a basic "if" conditional can be used like so:
|
|
12
|
-
* `<%? a?.b?.c %>This part will only appear if a.b.c is truthy!</%>`
|
|
13
|
-
* You can put interpolations inside a conditional, as you'd expect. That's it.
|
|
14
|
-
*/
|
|
15
|
-
export function template(string) {
|
|
16
|
-
var fn = function (data) { return string
|
|
17
|
-
.replace(REGEX_IF, function (match, pathToCheck, content) { return (getPath(data, pathToCheck.trim()) ? content : ""); })
|
|
18
|
-
.replace(REGEX_REPLACEMENT, function (match, _, pathToInterpolate) { return getPath(data, pathToInterpolate.trim(), ""); }); };
|
|
19
|
-
fn[SYMBOL_TEMPLATE_SOURCE] = string;
|
|
20
|
-
return fn;
|
|
21
|
-
}
|
|
22
|
-
export function isTemplate(x) {
|
|
23
|
-
return typeof x === "string" && (REGEX_REPLACEMENT.test(x) || REGEX_IF.test(x));
|
|
24
|
-
}
|
|
25
|
-
export function isTemplateFn(x) {
|
|
26
|
-
return typeof x === "function" && Object.prototype.hasOwnProperty.call(x, SYMBOL_TEMPLATE_SOURCE);
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=template.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/string/template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,IAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAClD,IAAM,QAAQ,GAAG,wBAAwB,CAAC;AAE1C,IAAM,sBAAsB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAI/D;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,IAAM,EAAE,GAAG,UAAC,IAAS,IAAK,OAAA,MAAM;SAC7B,OAAO,CAAC,QAAQ,EAAE,UAAC,KAAK,EAAE,WAAW,EAAE,OAAO,IAAK,OAAA,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAlD,CAAkD,CAAC;SACtG,OAAO,CAAC,iBAAiB,EAAE,UAAC,KAAK,EAAE,CAAC,EAAE,iBAAiB,IAAK,OAAA,OAAO,CAAC,IAAI,EAAE,iBAAiB,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,EAA3C,CAA2C,CAAC,EAFjF,CAEiF,CAAC;IAC5G,EAAE,CAAC,sBAAsB,CAAC,GAAG,MAAM,CAAC;IACpC,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,CAAM;IAC/B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,CAAM;IACjC,OAAO,OAAO,CAAC,KAAK,UAAU,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { template } from "./template";
|
|
2
|
-
describe("template", function () {
|
|
3
|
-
test("correctly interpolates from data", function () {
|
|
4
|
-
var templateString = "test ---> <%= a.b %> <--- test";
|
|
5
|
-
var data = { a: { b: "foo" } };
|
|
6
|
-
var expected = "test ---> foo <--- test";
|
|
7
|
-
expect(template(templateString)(data)).toBe(expected);
|
|
8
|
-
});
|
|
9
|
-
test("correctly interpolates from data, alternate", function () {
|
|
10
|
-
var templateString = "test ---> {{a.b}} <--- test";
|
|
11
|
-
var data = { a: { b: "foo" } };
|
|
12
|
-
var expected = "test ---> foo <--- test";
|
|
13
|
-
expect(template(templateString)(data)).toBe(expected);
|
|
14
|
-
});
|
|
15
|
-
test("supports optional chaining", function () {
|
|
16
|
-
var templateString = "test ---> <%= a?.b %> <--- test";
|
|
17
|
-
var data = {};
|
|
18
|
-
var expected = "test ---> <--- test";
|
|
19
|
-
expect(template(templateString)(data)).toBe(expected);
|
|
20
|
-
});
|
|
21
|
-
test("throws if non-optional chaining breaks", function () {
|
|
22
|
-
var templateString = "test ---> <%= a.b %> <--- test";
|
|
23
|
-
var data = {};
|
|
24
|
-
expect(function () { return template(templateString)(data); }).toThrow();
|
|
25
|
-
});
|
|
26
|
-
test("removes falsy conditionals", function () {
|
|
27
|
-
var templateString = "test ---><%? a.c %> <%= a.b %> <--- test</%>";
|
|
28
|
-
var data = { a: { b: "foo" } };
|
|
29
|
-
var expected = "test --->";
|
|
30
|
-
expect(template(templateString)(data)).toBe(expected);
|
|
31
|
-
});
|
|
32
|
-
test("retains truthy conditionals & process any interpolations within", function () {
|
|
33
|
-
var templateString = "test ---><%? a.c %> <%= a.b %> <--- test</%>";
|
|
34
|
-
var data = { a: { b: "foo", c: true } };
|
|
35
|
-
var expected = "test ---> foo <--- test";
|
|
36
|
-
expect(template(templateString)(data)).toBe(expected);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
//# sourceMappingURL=template.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"template.spec.js","sourceRoot":"","sources":["../../../src/string/template.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,QAAQ,CAAC,UAAU,EAAE;IACnB,IAAI,CAAC,kCAAkC,EAAE;QACvC,IAAM,cAAc,GAAG,gCAAgC,CAAC;QACxD,IAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACjC,IAAM,QAAQ,GAAG,yBAAyB,CAAC;QAC3C,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,6CAA6C,EAAE;QAClD,IAAM,cAAc,GAAG,6BAA6B,CAAC;QACrD,IAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACjC,IAAM,QAAQ,GAAG,yBAAyB,CAAC;QAC3C,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,4BAA4B,EAAE;QACjC,IAAM,cAAc,GAAG,iCAAiC,CAAC;QACzD,IAAM,IAAI,GAAG,EAAE,CAAC;QAChB,IAAM,QAAQ,GAAG,sBAAsB,CAAC;QACxC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wCAAwC,EAAE;QAC7C,IAAM,cAAc,GAAG,gCAAgC,CAAC;QACxD,IAAM,IAAI,GAAG,EAAE,CAAC;QAChB,MAAM,CAAC,cAAM,OAAA,QAAQ,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAA9B,CAA8B,CAAC,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,4BAA4B,EAAE;QACjC,IAAM,cAAc,GAAG,8CAA8C,CAAC;QACtE,IAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACjC,IAAM,QAAQ,GAAG,WAAW,CAAC;QAC7B,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,iEAAiE,EAAE;QACtE,IAAM,cAAc,GAAG,8CAA8C,CAAC;QACtE,IAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC;QAC1C,IAAM,QAAQ,GAAG,yBAAyB,CAAC;QAC3C,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/out-tsc/typings.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typings.js","sourceRoot":"","sources":["../../src/typings.ts"],"names":[],"mappings":""}
|
package/rollup.config.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
2
|
-
import resolve from "@rollup/plugin-node-resolve";
|
|
3
|
-
import pkg from "./package.json";
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
input: "dist/out-tsc/index.js",
|
|
7
|
-
output: [
|
|
8
|
-
{
|
|
9
|
-
file: pkg.main,
|
|
10
|
-
format: "cjs",
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
file: pkg.module,
|
|
14
|
-
format: "es",
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
external: Object.keys(pkg.peerDependencies || {}),
|
|
18
|
-
plugins: [
|
|
19
|
-
resolve(),
|
|
20
|
-
commonjs(),
|
|
21
|
-
],
|
|
22
|
-
};
|