@ezez/utils 1.1.0 → 1.4.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/.github/workflows/docs.yml +50 -0
- package/CHANGELOG.md +22 -0
- package/README.md +45 -20
- package/dist/ensureDate.d.ts +3 -0
- package/dist/ensureDate.d.ts.map +1 -0
- package/dist/ensureDate.js +11 -0
- package/dist/ensureDate.js.map +1 -0
- package/dist/ensureError.d.ts.map +1 -1
- package/dist/ensureError.js.map +1 -1
- package/dist/ensurePrefix.d.ts +3 -0
- package/dist/ensurePrefix.d.ts.map +1 -0
- package/dist/ensurePrefix.js +11 -0
- package/dist/ensurePrefix.js.map +1 -0
- package/dist/ensureSuffix.d.ts +3 -0
- package/dist/ensureSuffix.d.ts.map +1 -0
- package/dist/ensureSuffix.js +11 -0
- package/dist/ensureSuffix.js.map +1 -0
- package/dist/ensureTimestamp.d.ts +3 -0
- package/dist/ensureTimestamp.d.ts.map +1 -0
- package/dist/ensureTimestamp.js +11 -0
- package/dist/ensureTimestamp.js.map +1 -0
- package/dist/escapeRegExp.d.ts +3 -0
- package/dist/escapeRegExp.d.ts.map +1 -0
- package/dist/escapeRegExp.js +8 -0
- package/dist/escapeRegExp.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/isPlainObject.d.ts.map +1 -1
- package/dist/isPlainObject.js.map +1 -1
- package/dist/replace.d.ts +3 -0
- package/dist/replace.d.ts.map +1 -0
- package/dist/replace.js +10 -0
- package/dist/replace.js.map +1 -0
- package/dist/safe.d.ts +4 -0
- package/dist/safe.d.ts.map +1 -0
- package/dist/safe.js +13 -0
- package/dist/safe.js.map +1 -0
- package/dist/sortProps.d.ts +3 -0
- package/dist/sortProps.d.ts.map +1 -0
- package/dist/sortProps.js +19 -0
- package/dist/sortProps.js.map +1 -0
- package/dist/stripPrefix.d.ts +3 -0
- package/dist/stripPrefix.d.ts.map +1 -0
- package/dist/stripPrefix.js +11 -0
- package/dist/stripPrefix.js.map +1 -0
- package/dist/stripSuffix.d.ts +3 -0
- package/dist/stripSuffix.d.ts.map +1 -0
- package/dist/stripSuffix.js +11 -0
- package/dist/stripSuffix.js.map +1 -0
- package/docs/assets/highlight.css +14 -0
- package/docs/assets/main.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +4 -5
- package/docs/functions/cap.html +17 -6
- package/docs/functions/capitalize.html +17 -6
- package/docs/functions/coalesce.html +19 -9
- package/docs/functions/ensureArray.html +18 -7
- package/docs/functions/ensureDate.html +131 -0
- package/docs/functions/ensureError.html +27 -6
- package/docs/functions/ensurePrefix.html +133 -0
- package/docs/functions/ensureSuffix.html +133 -0
- package/docs/functions/ensureTimestamp.html +131 -0
- package/docs/functions/escapeRegExp.html +127 -0
- package/docs/functions/get.html +17 -6
- package/docs/functions/getMultiple.html +17 -6
- package/docs/functions/insertSeparator.html +17 -6
- package/docs/functions/isEmpty.html +17 -6
- package/docs/functions/isNumericString.html +17 -6
- package/docs/functions/isPlainObject.html +32 -6
- package/docs/functions/last.html +17 -6
- package/docs/functions/mapAsync.html +17 -6
- package/docs/functions/mapValues.html +17 -6
- package/docs/functions/match.html +17 -6
- package/docs/functions/merge.html +25 -14
- package/docs/functions/mostFrequent.html +17 -6
- package/docs/functions/noop.html +17 -6
- package/docs/functions/occurrences.html +17 -6
- package/docs/functions/omit.html +17 -6
- package/docs/functions/pick.html +17 -6
- package/docs/functions/pull.html +17 -6
- package/docs/functions/remove.html +17 -6
- package/docs/functions/replace.html +133 -0
- package/docs/functions/rethrow.html +17 -6
- package/docs/functions/safe.html +171 -0
- package/docs/functions/scale.html +17 -6
- package/docs/functions/seq.html +17 -6
- package/docs/functions/seqEarlyBreak.html +17 -6
- package/docs/functions/set.html +17 -6
- package/docs/functions/setImmutable.html +17 -6
- package/docs/functions/sortBy.html +17 -6
- package/docs/functions/sortProps.html +136 -0
- package/docs/functions/stripPrefix.html +127 -0
- package/docs/functions/stripSuffix.html +127 -0
- package/docs/functions/throttle.html +17 -6
- package/docs/functions/truthy.html +17 -6
- package/docs/functions/wait.html +17 -6
- package/docs/functions/waitFor.html +17 -6
- package/docs/functions/waitSync.html +17 -6
- package/docs/index.html +92 -25
- package/docs/interfaces/GetMultipleSource.html +17 -6
- package/docs/interfaces/GetSource.html +17 -6
- package/docs/interfaces/IsNumericStringOptions.html +11 -10
- package/docs/interfaces/OccurencesOptions.html +8 -7
- package/docs/interfaces/SetImmutableSource.html +17 -6
- package/docs/interfaces/SetSource.html +17 -6
- package/docs/interfaces/ThrottleOptions.html +9 -8
- package/docs/interfaces/ThrottledFunctionExtras.html +9 -8
- package/docs/modules.html +26 -5
- package/docs/pages/CHANGELOG.html +764 -0
- package/docs/pages/Introduction.html +16 -5
- package/docs/types/MapValuesFn.html +17 -6
- package/docs/types/MatchCallback.html +17 -6
- package/docs/types/SeqEarlyBreaker.html +17 -6
- package/docs/types/SeqFn.html +17 -6
- package/docs/types/SeqFunctions.html +17 -6
- package/docs/types/SetImmutablePath.html +17 -6
- package/docs/types/ThrottledFunction.html +17 -6
- package/docs/variables/mapValuesUNSET.html +17 -6
- package/docs/variables/mergeUNSET.html +17 -6
- package/esm/ensureDate.d.ts +3 -0
- package/esm/ensureDate.d.ts.map +1 -0
- package/esm/ensureDate.js +8 -0
- package/esm/ensureDate.js.map +1 -0
- package/esm/ensureError.d.ts.map +1 -1
- package/esm/ensureError.js.map +1 -1
- package/esm/ensurePrefix.d.ts +3 -0
- package/esm/ensurePrefix.d.ts.map +1 -0
- package/esm/ensurePrefix.js +8 -0
- package/esm/ensurePrefix.js.map +1 -0
- package/esm/ensureSuffix.d.ts +3 -0
- package/esm/ensureSuffix.d.ts.map +1 -0
- package/esm/ensureSuffix.js +8 -0
- package/esm/ensureSuffix.js.map +1 -0
- package/esm/ensureTimestamp.d.ts +3 -0
- package/esm/ensureTimestamp.d.ts.map +1 -0
- package/esm/ensureTimestamp.js +8 -0
- package/esm/ensureTimestamp.js.map +1 -0
- package/esm/escapeRegExp.d.ts +3 -0
- package/esm/escapeRegExp.d.ts.map +1 -0
- package/esm/escapeRegExp.js +5 -0
- package/esm/escapeRegExp.js.map +1 -0
- package/esm/index.d.ts +10 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +10 -0
- package/esm/index.js.map +1 -1
- package/esm/isPlainObject.d.ts.map +1 -1
- package/esm/isPlainObject.js.map +1 -1
- package/esm/replace.d.ts +3 -0
- package/esm/replace.d.ts.map +1 -0
- package/esm/replace.js +7 -0
- package/esm/replace.js.map +1 -0
- package/esm/safe.d.ts +4 -0
- package/esm/safe.d.ts.map +1 -0
- package/esm/safe.js +10 -0
- package/esm/safe.js.map +1 -0
- package/esm/sortProps.d.ts +3 -0
- package/esm/sortProps.d.ts.map +1 -0
- package/esm/sortProps.js +16 -0
- package/esm/sortProps.js.map +1 -0
- package/esm/stripPrefix.d.ts +3 -0
- package/esm/stripPrefix.d.ts.map +1 -0
- package/esm/stripPrefix.js +8 -0
- package/esm/stripPrefix.js.map +1 -0
- package/esm/stripSuffix.d.ts +3 -0
- package/esm/stripSuffix.d.ts.map +1 -0
- package/esm/stripSuffix.js +8 -0
- package/esm/stripSuffix.js.map +1 -0
- package/package.json +23 -23
- package/src/coalesce.ts +2 -2
- package/src/ensureArray.ts +1 -1
- package/src/ensureDate.spec.ts +13 -0
- package/src/ensureDate.ts +18 -0
- package/src/ensureError.ts +7 -0
- package/src/ensurePrefix.spec.ts +11 -0
- package/src/ensurePrefix.ts +18 -0
- package/src/ensureSuffix.spec.ts +11 -0
- package/src/ensureSuffix.ts +18 -0
- package/src/ensureTimestamp.spec.ts +11 -0
- package/src/ensureTimestamp.ts +18 -0
- package/src/escapeRegExp.spec.ts +31 -0
- package/src/escapeRegExp.ts +17 -0
- package/src/index.ts +10 -0
- package/src/isPlainObject.spec.ts +0 -7
- package/src/isPlainObject.ts +5 -0
- package/src/replace.spec.ts +22 -0
- package/src/replace.ts +19 -0
- package/src/safe.spec.ts +52 -0
- package/src/safe.ts +24 -0
- package/src/sortProps.spec.ts +20 -0
- package/src/sortProps.ts +21 -0
- package/src/stripPrefix.spec.ts +13 -0
- package/src/stripPrefix.ts +15 -0
- package/src/stripSuffix.spec.ts +13 -0
- package/src/stripSuffix.ts +16 -0
- package/typedoc.cjs +5 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensurePrefix.d.ts","sourceRoot":"","sources":["../src/ensurePrefix.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,YAAY,WAAY,MAAM,UAAU,MAAM,WAKnD,CAAC;AAEF,OAAO,EACH,YAAY,GACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensurePrefix.js","sourceRoot":"","sources":["../src/ensurePrefix.ts"],"names":[],"mappings":"AAQA,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,MAAc,EAAE,EAAE;IACpD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QAC3B,OAAO,MAAM,CAAC;KACjB;IACD,OAAO,MAAM,GAAG,MAAM,CAAC;AAC3B,CAAC,CAAC;AAEF,OAAO,EACH,YAAY,GACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureSuffix.d.ts","sourceRoot":"","sources":["../src/ensureSuffix.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,YAAY,WAAY,MAAM,UAAU,MAAM,WAKnD,CAAC;AAEF,OAAO,EACH,YAAY,GACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureSuffix.js","sourceRoot":"","sources":["../src/ensureSuffix.ts"],"names":[],"mappings":"AAQA,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,MAAc,EAAE,EAAE;IACpD,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO,MAAM,CAAC;KACjB;IACD,OAAO,MAAM,GAAG,MAAM,CAAC;AAC3B,CAAC,CAAC;AAEF,OAAO,EACH,YAAY,GACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureTimestamp.d.ts","sourceRoot":"","sources":["../src/ensureTimestamp.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,eAAe,SAAU,IAAI,GAAG,MAAM,KAAG,MAK9C,CAAC;AAEF,OAAO,EACH,eAAe,GAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureTimestamp.js","sourceRoot":"","sources":["../src/ensureTimestamp.ts"],"names":[],"mappings":"AAQA,MAAM,eAAe,GAAG,CAAC,IAAmB,EAAU,EAAE;IACpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC1B,OAAO,IAAI,CAAC;KACf;IACD,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;AAC1B,CAAC,CAAC;AAEF,OAAO,EACH,eAAe,GAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escapeRegExp.d.ts","sourceRoot":"","sources":["../src/escapeRegExp.ts"],"names":[],"mappings":"AAUA,QAAA,MAAM,YAAY,WAAY,MAAM,WAEnC,CAAC;AAEF,OAAO,EACH,YAAY,GACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escapeRegExp.js","sourceRoot":"","sources":["../src/escapeRegExp.ts"],"names":[],"mappings":"AAUA,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,EAAE;IACpC,OAAO,MAAM,CAAC,OAAO,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,OAAO,EACH,YAAY,GACf,CAAC"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
export * from "./ensurePrefix.js";
|
|
2
|
+
export * from "./ensureSuffix.js";
|
|
1
3
|
export * from "./cap.js";
|
|
2
4
|
export * from "./capitalize.js";
|
|
3
5
|
export * from "./coalesce.js";
|
|
4
6
|
export * from "./ensureArray.js";
|
|
7
|
+
export * from "./ensureDate.js";
|
|
5
8
|
export * from "./ensureError.js";
|
|
9
|
+
export * from "./ensureTimestamp.js";
|
|
10
|
+
export * from "./escapeRegExp.js";
|
|
6
11
|
export * from "./get.js";
|
|
7
12
|
export * from "./getMultiple.js";
|
|
8
13
|
export * from "./insertSeparator.js";
|
|
@@ -21,12 +26,17 @@ export * from "./omit.js";
|
|
|
21
26
|
export * from "./pick.js";
|
|
22
27
|
export * from "./pull.js";
|
|
23
28
|
export * from "./remove.js";
|
|
29
|
+
export * from "./replace.js";
|
|
24
30
|
export * from "./rethrow.js";
|
|
31
|
+
export * from "./safe.js";
|
|
25
32
|
export * from "./scale.js";
|
|
26
33
|
export * from "./seq.js";
|
|
27
34
|
export * from "./set.js";
|
|
28
35
|
export * from "./setImmutable.js";
|
|
29
36
|
export * from "./sortBy.js";
|
|
37
|
+
export * from "./sortProps.js";
|
|
38
|
+
export * from "./stripPrefix.js";
|
|
39
|
+
export * from "./stripSuffix.js";
|
|
30
40
|
export * from "./throttle.js";
|
|
31
41
|
export * from "./truthy.js";
|
|
32
42
|
export * from "./wait.js";
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
export * from "./ensurePrefix.js";
|
|
2
|
+
export * from "./ensureSuffix.js";
|
|
1
3
|
export * from "./cap.js";
|
|
2
4
|
export * from "./capitalize.js";
|
|
3
5
|
export * from "./coalesce.js";
|
|
4
6
|
export * from "./ensureArray.js";
|
|
7
|
+
export * from "./ensureDate.js";
|
|
5
8
|
export * from "./ensureError.js";
|
|
9
|
+
export * from "./ensureTimestamp.js";
|
|
10
|
+
export * from "./escapeRegExp.js";
|
|
6
11
|
export * from "./get.js";
|
|
7
12
|
export * from "./getMultiple.js";
|
|
8
13
|
export * from "./insertSeparator.js";
|
|
@@ -21,12 +26,17 @@ export * from "./omit.js";
|
|
|
21
26
|
export * from "./pick.js";
|
|
22
27
|
export * from "./pull.js";
|
|
23
28
|
export * from "./remove.js";
|
|
29
|
+
export * from "./replace.js";
|
|
24
30
|
export * from "./rethrow.js";
|
|
31
|
+
export * from "./safe.js";
|
|
25
32
|
export * from "./scale.js";
|
|
26
33
|
export * from "./seq.js";
|
|
27
34
|
export * from "./set.js";
|
|
28
35
|
export * from "./setImmutable.js";
|
|
29
36
|
export * from "./sortBy.js";
|
|
37
|
+
export * from "./sortProps.js";
|
|
38
|
+
export * from "./stripPrefix.js";
|
|
39
|
+
export * from "./stripSuffix.js";
|
|
30
40
|
export * from "./throttle.js";
|
|
31
41
|
export * from "./truthy.js";
|
|
32
42
|
export * from "./wait.js";
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPlainObject.d.ts","sourceRoot":"","sources":["../src/isPlainObject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isPlainObject.d.ts","sourceRoot":"","sources":["../src/isPlainObject.ts"],"names":[],"mappings":"AASA,QAAA,MAAM,aAAa,UAAW,OAAO,YAQpC,CAAC;AAEF,OAAO,EACH,aAAa,GAChB,CAAC"}
|
package/esm/isPlainObject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPlainObject.js","sourceRoot":"","sources":["../src/isPlainObject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isPlainObject.js","sourceRoot":"","sources":["../src/isPlainObject.ts"],"names":[],"mappings":"AASA,MAAM,aAAa,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,OAAO,CAC7C,KAAK;OACF,OAAO,KAAK,KAAK,QAAQ;OACzB,CACC,KAAK,CAAC,WAAW,KAAK,MAAM;WACzB,CAAC,CAAC,aAAa,IAAI,KAAK,CAAC;WACzB,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAC/D,CACJ,CAAC;AAEF,OAAO,EACH,aAAa,GAChB,CAAC"}
|
package/esm/replace.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace.d.ts","sourceRoot":"","sources":["../src/replace.ts"],"names":[],"mappings":"AAUA,QAAA,MAAM,OAAO,WAAY,MAAM,cAAc,OAAO,MAAM,EAAE,MAAM,CAAC,WAIlE,CAAC;AAEF,OAAO,EACH,OAAO,GACV,CAAC"}
|
package/esm/replace.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { escapeRegExp } from "./escapeRegExp.js";
|
|
2
|
+
const replace = (source, replaceMap) => {
|
|
3
|
+
const regex = new RegExp(Object.keys(replaceMap).map(escapeRegExp).join("|"), "g");
|
|
4
|
+
return source.replace(regex, (matched) => replaceMap[matched]);
|
|
5
|
+
};
|
|
6
|
+
export { replace, };
|
|
7
|
+
//# sourceMappingURL=replace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace.js","sourceRoot":"","sources":["../src/replace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AASjD,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,UAAkC,EAAE,EAAE;IAEnE,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IACnF,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,OAAO,EACH,OAAO,GACV,CAAC"}
|
package/esm/safe.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe.d.ts","sourceRoot":"","sources":["../src/safe.ts"],"names":[],"mappings":"AAAA,iBAAS,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AAC7C,iBAAS,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAsBhD,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/esm/safe.js
ADDED
package/esm/safe.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe.js","sourceRoot":"","sources":["../src/safe.ts"],"names":[],"mappings":"AAaA,SAAS,IAAI,CAAO,EAAW,EAAE,GAAO;IAEpC,IAAI;QACA,OAAO,EAAE,EAAE,CAAC;KACf;IACD,MAAM;QACF,OAAO,GAAG,CAAC;KACd;AACL,CAAC;AAED,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortProps.d.ts","sourceRoot":"","sources":["../src/sortProps.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,SAAS,oEASd,CAAC;AAEF,OAAO,EACH,SAAS,GACZ,CAAC"}
|
package/esm/sortProps.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const sortProps = (object, asc = true) => {
|
|
2
|
+
const sorted = {};
|
|
3
|
+
const keys = Object.keys(object);
|
|
4
|
+
if (asc) {
|
|
5
|
+
keys.sort();
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
keys.sort().reverse();
|
|
9
|
+
}
|
|
10
|
+
for (const key of keys) {
|
|
11
|
+
sorted[key] = object[key];
|
|
12
|
+
}
|
|
13
|
+
return sorted;
|
|
14
|
+
};
|
|
15
|
+
export { sortProps, };
|
|
16
|
+
//# sourceMappingURL=sortProps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortProps.js","sourceRoot":"","sources":["../src/sortProps.ts"],"names":[],"mappings":"AAOA,MAAM,SAAS,GAAG,CAAoC,MAAS,EAAE,GAAG,GAAG,IAAI,EAAK,EAAE;IAC9E,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,GAAG,EAAE;QAAE,IAAI,CAAC,IAAI,EAAE,CAAC;KAAE;SACpB;QAAE,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;KAAE;IAC/B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;QACpB,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;KAC7B;IACD,OAAO,MAAW,CAAC;AACvB,CAAC,CAAC;AAEF,OAAO,EACH,SAAS,GACZ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripPrefix.d.ts","sourceRoot":"","sources":["../src/stripPrefix.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,WAAW,SAAU,MAAM,UAAU,MAAM,KAAG,MAKnD,CAAC;AAEF,OAAO,EACH,WAAW,GACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripPrefix.js","sourceRoot":"","sources":["../src/stripPrefix.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,MAAc,EAAU,EAAE;IACzD,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KACpC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,OAAO,EACH,WAAW,GACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripSuffix.d.ts","sourceRoot":"","sources":["../src/stripSuffix.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,WAAW,SAAU,MAAM,UAAU,MAAM,KAAG,MAKnD,CAAC;AAEF,OAAO,EACH,WAAW,GACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripSuffix.js","sourceRoot":"","sources":["../src/stripSuffix.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,MAAc,EAAU,EAAE;IACzD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KACxC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,OAAO,EACH,WAAW,GACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezez/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"repository": "https://github.com/dzek69/bottom-line.git",
|
|
5
5
|
"author": "Jacek Nowacki @dzek69 <git-public@dzek.eu>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "NODE_ENV=test jest",
|
|
9
9
|
"test:lodashImports": "node test/lodash-tree.cjs",
|
|
10
|
-
"docs": "typedoc src/index.ts --skipErrorChecking --out docs --includeVersion
|
|
10
|
+
"docs": "typedoc src/index.ts --skipErrorChecking --out docs --includeVersion",
|
|
11
11
|
"compile": "yarn compile:esm && yarn compile:cjs",
|
|
12
12
|
"compile:esm": "rm -rf esm && tsc --project tsconfig.esm.json && node ./build-scripts/compile.esm.after.mjs",
|
|
13
13
|
"compile:cjs": "rm -rf dist && tsc --project tsconfig.cjs.json && node ./build-scripts/compile.cjs.after.mjs",
|
|
@@ -35,31 +35,31 @@
|
|
|
35
35
|
"module": "./esm/index.js",
|
|
36
36
|
"type": "module",
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@babel/core": "^7.
|
|
39
|
-
"@babel/preset-env": "^7.
|
|
40
|
-
"@babel/preset-typescript": "^7.
|
|
41
|
-
"@dzek69/eslint-config-base": "^2.
|
|
42
|
-
"@dzek69/eslint-config-
|
|
43
|
-
"@
|
|
38
|
+
"@babel/core": "^7.21.4",
|
|
39
|
+
"@babel/preset-env": "^7.21.4",
|
|
40
|
+
"@babel/preset-typescript": "^7.21.4",
|
|
41
|
+
"@dzek69/eslint-config-base": "^2.4.0",
|
|
42
|
+
"@dzek69/eslint-config-import": "^1.2.0",
|
|
43
|
+
"@dzek69/eslint-config-import-typescript": "^1.0.0",
|
|
44
|
+
"@dzek69/eslint-config-typescript": "^1.1.0",
|
|
45
|
+
"@knodes/typedoc-plugin-pages": "^0.23.4",
|
|
46
|
+
"@types/jest": "^29.5.0",
|
|
44
47
|
"@types/lodash": "^4.14.168",
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
46
|
-
"@typescript-eslint/parser": "^5.
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^5.58.0",
|
|
49
|
+
"@typescript-eslint/parser": "^5.58.0",
|
|
47
50
|
"babel-plugin-module-extension": "^0.1.3",
|
|
48
|
-
"eslint": "^8.
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
51
|
+
"eslint": "^8.38.0",
|
|
52
|
+
"eslint-plugin-import": "^2.27.5",
|
|
53
|
+
"fs-extra": "^11.1.1",
|
|
54
|
+
"husky": "^8.0.3",
|
|
55
|
+
"jest": "^29.5.0",
|
|
52
56
|
"lodash": "^4.17.21",
|
|
53
57
|
"must": "^0.13.4",
|
|
54
|
-
"nodemon": "^2.0.
|
|
58
|
+
"nodemon": "^2.0.22",
|
|
59
|
+
"prettier": "^2.8.7",
|
|
55
60
|
"ts-node": "^10.9.1",
|
|
56
|
-
"typedoc": "^0.23.
|
|
57
|
-
"typescript": "^
|
|
58
|
-
"eslint-plugin-import": "^2.26.0",
|
|
59
|
-
"@dzek69/eslint-config-import": "^1.0.0",
|
|
60
|
-
"@dzek69/eslint-config-import-typescript": "^1.0.0",
|
|
61
|
-
"@knodes/typedoc-plugin-pages": "^0.23.1",
|
|
62
|
-
"prettier": "^2.8.3"
|
|
61
|
+
"typedoc": "^0.23.28",
|
|
62
|
+
"typescript": "^5.0.4"
|
|
63
63
|
},
|
|
64
64
|
"husky": {
|
|
65
65
|
"hooks": {
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
69
|
"libraryTemplate": {
|
|
70
|
-
"version": "3.
|
|
70
|
+
"version": "3.9.1",
|
|
71
71
|
"language": "typescript",
|
|
72
72
|
"fixDefaultForCommonJS": false,
|
|
73
73
|
"jsx": false
|
package/src/coalesce.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Returns first non-nil (not undefined, not null) value from given arguments.
|
|
3
3
|
*
|
|
4
4
|
* @param {...*} args - values
|
|
5
|
-
* @example coalesce(null, undefined, void
|
|
6
|
-
* @example coalesce(
|
|
5
|
+
* @example coalesce(null, undefined, void 1, 5); // returns 5 (mind the `void`)
|
|
6
|
+
* @example coalesce(0, null, 6, undefined); // returns 0
|
|
7
7
|
* @example coalesce(undefined); // returns null
|
|
8
8
|
* @example coalesce(); // returns null
|
|
9
9
|
* @returns {*|null} first non-nil value or null
|
package/src/ensureArray.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ensureDate } from "./ensureDate.js";
|
|
2
|
+
|
|
3
|
+
describe("ensureDate", function() {
|
|
4
|
+
it("should convert timestamps to date instances", function() {
|
|
5
|
+
ensureDate(123456789).must.be.instanceOf(Date);
|
|
6
|
+
ensureDate(123456789).getTime().must.equal(123456789);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("should return the same date instance", function() {
|
|
10
|
+
const date = new Date(123456789);
|
|
11
|
+
ensureDate(date).must.equal(date);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensure that the date value is a Date instance
|
|
3
|
+
*
|
|
4
|
+
* @example ensureDate(123456789); // Date(123456789)
|
|
5
|
+
* @example ensureDate(new Date(123456789)); // Date(123456789) -- same instance as given
|
|
6
|
+
* @see {@link ensureTimestamp}
|
|
7
|
+
* @param {Date | number} date - date value
|
|
8
|
+
*/
|
|
9
|
+
const ensureDate = (date: Date | number): Date => {
|
|
10
|
+
if (typeof date === "number") {
|
|
11
|
+
return new Date(date);
|
|
12
|
+
}
|
|
13
|
+
return date;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
ensureDate,
|
|
18
|
+
};
|
package/src/ensureError.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Ensures given value is an instance of Error.
|
|
3
|
+
*
|
|
4
|
+
* This is for simple use cases only, for maximum flexibility use `@ezez/errors` package.
|
|
5
|
+
* @example ensureError(new Error("test")); // returns given Error instance (not modified)
|
|
6
|
+
* @example ensureError("test");
|
|
7
|
+
* // ^ returns new Error instance with error message: "Expected error instance, got something else: test"
|
|
8
|
+
* @example ensureError({});
|
|
9
|
+
* // ^ returns new Error instance with error message: "Expected error instance, got something else: [object Object]"
|
|
3
10
|
* @param {*} e - value to check
|
|
4
11
|
* @returns Error - original error or new Error instance
|
|
5
12
|
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ensurePrefix } from "./ensurePrefix.js";
|
|
2
|
+
|
|
3
|
+
describe("ensure prefix", function() {
|
|
4
|
+
it("adds prefix", function() {
|
|
5
|
+
ensurePrefix("1234bbcc", "0x").must.equal("0x1234bbcc");
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("doesn't add prefix if already present", function() {
|
|
9
|
+
ensurePrefix("0x1234bbcc", "0x").must.equal("0x1234bbcc");
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add prefix to string if it doesn't already have it
|
|
3
|
+
*
|
|
4
|
+
* @example ensurePrefix("1234bbcc", "0x") -> "0x1234bbcc"
|
|
5
|
+
* @example ensurePrefix("0x1234bbcc", "0x") -> "0x1234bbcc"
|
|
6
|
+
* @param {string} string - string to add prefix to
|
|
7
|
+
* @param {string} prefix - prefix to add
|
|
8
|
+
*/
|
|
9
|
+
const ensurePrefix = (string: string, prefix: string) => {
|
|
10
|
+
if (string.startsWith(prefix)) {
|
|
11
|
+
return string;
|
|
12
|
+
}
|
|
13
|
+
return prefix + string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
ensurePrefix,
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ensureSuffix } from "./ensureSuffix.js";
|
|
2
|
+
|
|
3
|
+
describe("ensure suffix", function() {
|
|
4
|
+
it("adds suffix to a string", function() {
|
|
5
|
+
ensureSuffix("hello world", ".").must.equal("hello world.");
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("doesn't add suffix if already present", function() {
|
|
9
|
+
ensureSuffix("hello world.", ".").must.equal("hello world.");
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add suffix to string if it does not already end with it
|
|
3
|
+
*
|
|
4
|
+
* @example ensureSuffix("hello world", ".") -> "hello world."
|
|
5
|
+
* @example ensureSuffix("hello world.", ".") -> "hello world."
|
|
6
|
+
* @param {string} string - string to add suffix to
|
|
7
|
+
* @param {string} suffix - suffix to add
|
|
8
|
+
*/
|
|
9
|
+
const ensureSuffix = (string: string, suffix: string) => {
|
|
10
|
+
if (string.endsWith(suffix)) {
|
|
11
|
+
return string;
|
|
12
|
+
}
|
|
13
|
+
return string + suffix;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
ensureSuffix,
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ensureTimestamp } from "./ensureTimestamp.js";
|
|
2
|
+
|
|
3
|
+
describe("ensure timestamp", function() {
|
|
4
|
+
it("returns number if number given", function() {
|
|
5
|
+
ensureTimestamp(123456789).must.equal(123456789);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("returns number if date given", function() {
|
|
9
|
+
ensureTimestamp(new Date(123456789)).must.equal(123456789);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensures that the given date value is a numeric timestamp.
|
|
3
|
+
*
|
|
4
|
+
* @example ensureTimestamp(123456789); // 123456789
|
|
5
|
+
* @example ensureTimestamp(new Date(123456789)); // 123456789
|
|
6
|
+
* @see {@link ensureDate}
|
|
7
|
+
* @param {Date | number} date - date value
|
|
8
|
+
*/
|
|
9
|
+
const ensureTimestamp = (date: Date | number): number => {
|
|
10
|
+
if (typeof date === "number") {
|
|
11
|
+
return date;
|
|
12
|
+
}
|
|
13
|
+
return date.getTime();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
ensureTimestamp,
|
|
18
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { escapeRegExp } from "./escapeRegExp.js";
|
|
2
|
+
|
|
3
|
+
describe("escapeRegExp", () => {
|
|
4
|
+
it("it should escape dot", () => {
|
|
5
|
+
const userName = ".";
|
|
6
|
+
const regex = new RegExp(`^(maciek|${escapeRegExp(userName)})$`);
|
|
7
|
+
const result = regex.test("maciek");
|
|
8
|
+
result.must.be.true();
|
|
9
|
+
|
|
10
|
+
const result2 = regex.test("stefan");
|
|
11
|
+
result2.must.be.false();
|
|
12
|
+
|
|
13
|
+
const result3 = regex.test(",");
|
|
14
|
+
result3.must.be.false();
|
|
15
|
+
|
|
16
|
+
const result4 = regex.test(".");
|
|
17
|
+
result4.must.be.true();
|
|
18
|
+
|
|
19
|
+
const result5 = regex.test("...");
|
|
20
|
+
result5.must.be.false();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should escape complex string", () => {
|
|
24
|
+
const userName = "([{^|";
|
|
25
|
+
const fn = () => new RegExp(`^(maciek|${escapeRegExp(userName)})$`);
|
|
26
|
+
fn.must.not.throw();
|
|
27
|
+
|
|
28
|
+
const fnNoEscape = () => new RegExp(`^(maciek|${userName})$`);
|
|
29
|
+
fnNoEscape.must.throw();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escapes a string to be used in a regular expression.
|
|
3
|
+
* From: https://stackoverflow.com/a/3561711
|
|
4
|
+
* @param string - string to escape
|
|
5
|
+
* @example ```typescript
|
|
6
|
+
* const badName = "([{^|";
|
|
7
|
+
* const regex = new RegExp(`^(maciek|${escapeRegExp(badName)})$`); // won't crash
|
|
8
|
+
* regex.test(badName); // true
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
const escapeRegExp = (string: string) => {
|
|
12
|
+
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
escapeRegExp,
|
|
17
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/* eslint-disable import/max-dependencies */
|
|
2
|
+
export * from "./ensurePrefix.js";
|
|
3
|
+
export * from "./ensureSuffix.js";
|
|
2
4
|
export * from "./cap.js";
|
|
3
5
|
export * from "./capitalize.js";
|
|
4
6
|
export * from "./coalesce.js";
|
|
5
7
|
export * from "./ensureArray.js";
|
|
8
|
+
export * from "./ensureDate.js";
|
|
6
9
|
export * from "./ensureError.js";
|
|
10
|
+
export * from "./ensureTimestamp.js";
|
|
11
|
+
export * from "./escapeRegExp.js";
|
|
7
12
|
export * from "./get.js";
|
|
8
13
|
export * from "./getMultiple.js";
|
|
9
14
|
export * from "./insertSeparator.js";
|
|
@@ -22,12 +27,17 @@ export * from "./omit.js";
|
|
|
22
27
|
export * from "./pick.js";
|
|
23
28
|
export * from "./pull.js";
|
|
24
29
|
export * from "./remove.js";
|
|
30
|
+
export * from "./replace.js";
|
|
25
31
|
export * from "./rethrow.js";
|
|
32
|
+
export * from "./safe.js";
|
|
26
33
|
export * from "./scale.js";
|
|
27
34
|
export * from "./seq.js";
|
|
28
35
|
export * from "./set.js";
|
|
29
36
|
export * from "./setImmutable.js";
|
|
30
37
|
export * from "./sortBy.js";
|
|
38
|
+
export * from "./sortProps.js";
|
|
39
|
+
export * from "./stripPrefix.js";
|
|
40
|
+
export * from "./stripSuffix.js";
|
|
31
41
|
export * from "./throttle.js";
|
|
32
42
|
export * from "./truthy.js";
|
|
33
43
|
export * from "./wait.js";
|