@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.
Files changed (197) hide show
  1. package/.github/workflows/docs.yml +50 -0
  2. package/CHANGELOG.md +22 -0
  3. package/README.md +45 -20
  4. package/dist/ensureDate.d.ts +3 -0
  5. package/dist/ensureDate.d.ts.map +1 -0
  6. package/dist/ensureDate.js +11 -0
  7. package/dist/ensureDate.js.map +1 -0
  8. package/dist/ensureError.d.ts.map +1 -1
  9. package/dist/ensureError.js.map +1 -1
  10. package/dist/ensurePrefix.d.ts +3 -0
  11. package/dist/ensurePrefix.d.ts.map +1 -0
  12. package/dist/ensurePrefix.js +11 -0
  13. package/dist/ensurePrefix.js.map +1 -0
  14. package/dist/ensureSuffix.d.ts +3 -0
  15. package/dist/ensureSuffix.d.ts.map +1 -0
  16. package/dist/ensureSuffix.js +11 -0
  17. package/dist/ensureSuffix.js.map +1 -0
  18. package/dist/ensureTimestamp.d.ts +3 -0
  19. package/dist/ensureTimestamp.d.ts.map +1 -0
  20. package/dist/ensureTimestamp.js +11 -0
  21. package/dist/ensureTimestamp.js.map +1 -0
  22. package/dist/escapeRegExp.d.ts +3 -0
  23. package/dist/escapeRegExp.d.ts.map +1 -0
  24. package/dist/escapeRegExp.js +8 -0
  25. package/dist/escapeRegExp.js.map +1 -0
  26. package/dist/index.d.ts +10 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +10 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/isPlainObject.d.ts.map +1 -1
  31. package/dist/isPlainObject.js.map +1 -1
  32. package/dist/replace.d.ts +3 -0
  33. package/dist/replace.d.ts.map +1 -0
  34. package/dist/replace.js +10 -0
  35. package/dist/replace.js.map +1 -0
  36. package/dist/safe.d.ts +4 -0
  37. package/dist/safe.d.ts.map +1 -0
  38. package/dist/safe.js +13 -0
  39. package/dist/safe.js.map +1 -0
  40. package/dist/sortProps.d.ts +3 -0
  41. package/dist/sortProps.d.ts.map +1 -0
  42. package/dist/sortProps.js +19 -0
  43. package/dist/sortProps.js.map +1 -0
  44. package/dist/stripPrefix.d.ts +3 -0
  45. package/dist/stripPrefix.d.ts.map +1 -0
  46. package/dist/stripPrefix.js +11 -0
  47. package/dist/stripPrefix.js.map +1 -0
  48. package/dist/stripSuffix.d.ts +3 -0
  49. package/dist/stripSuffix.d.ts.map +1 -0
  50. package/dist/stripSuffix.js +11 -0
  51. package/dist/stripSuffix.js.map +1 -0
  52. package/docs/assets/highlight.css +14 -0
  53. package/docs/assets/main.js +1 -1
  54. package/docs/assets/search.js +1 -1
  55. package/docs/assets/style.css +4 -5
  56. package/docs/functions/cap.html +17 -6
  57. package/docs/functions/capitalize.html +17 -6
  58. package/docs/functions/coalesce.html +19 -9
  59. package/docs/functions/ensureArray.html +18 -7
  60. package/docs/functions/ensureDate.html +131 -0
  61. package/docs/functions/ensureError.html +27 -6
  62. package/docs/functions/ensurePrefix.html +133 -0
  63. package/docs/functions/ensureSuffix.html +133 -0
  64. package/docs/functions/ensureTimestamp.html +131 -0
  65. package/docs/functions/escapeRegExp.html +127 -0
  66. package/docs/functions/get.html +17 -6
  67. package/docs/functions/getMultiple.html +17 -6
  68. package/docs/functions/insertSeparator.html +17 -6
  69. package/docs/functions/isEmpty.html +17 -6
  70. package/docs/functions/isNumericString.html +17 -6
  71. package/docs/functions/isPlainObject.html +32 -6
  72. package/docs/functions/last.html +17 -6
  73. package/docs/functions/mapAsync.html +17 -6
  74. package/docs/functions/mapValues.html +17 -6
  75. package/docs/functions/match.html +17 -6
  76. package/docs/functions/merge.html +25 -14
  77. package/docs/functions/mostFrequent.html +17 -6
  78. package/docs/functions/noop.html +17 -6
  79. package/docs/functions/occurrences.html +17 -6
  80. package/docs/functions/omit.html +17 -6
  81. package/docs/functions/pick.html +17 -6
  82. package/docs/functions/pull.html +17 -6
  83. package/docs/functions/remove.html +17 -6
  84. package/docs/functions/replace.html +133 -0
  85. package/docs/functions/rethrow.html +17 -6
  86. package/docs/functions/safe.html +171 -0
  87. package/docs/functions/scale.html +17 -6
  88. package/docs/functions/seq.html +17 -6
  89. package/docs/functions/seqEarlyBreak.html +17 -6
  90. package/docs/functions/set.html +17 -6
  91. package/docs/functions/setImmutable.html +17 -6
  92. package/docs/functions/sortBy.html +17 -6
  93. package/docs/functions/sortProps.html +136 -0
  94. package/docs/functions/stripPrefix.html +127 -0
  95. package/docs/functions/stripSuffix.html +127 -0
  96. package/docs/functions/throttle.html +17 -6
  97. package/docs/functions/truthy.html +17 -6
  98. package/docs/functions/wait.html +17 -6
  99. package/docs/functions/waitFor.html +17 -6
  100. package/docs/functions/waitSync.html +17 -6
  101. package/docs/index.html +92 -25
  102. package/docs/interfaces/GetMultipleSource.html +17 -6
  103. package/docs/interfaces/GetSource.html +17 -6
  104. package/docs/interfaces/IsNumericStringOptions.html +11 -10
  105. package/docs/interfaces/OccurencesOptions.html +8 -7
  106. package/docs/interfaces/SetImmutableSource.html +17 -6
  107. package/docs/interfaces/SetSource.html +17 -6
  108. package/docs/interfaces/ThrottleOptions.html +9 -8
  109. package/docs/interfaces/ThrottledFunctionExtras.html +9 -8
  110. package/docs/modules.html +26 -5
  111. package/docs/pages/CHANGELOG.html +764 -0
  112. package/docs/pages/Introduction.html +16 -5
  113. package/docs/types/MapValuesFn.html +17 -6
  114. package/docs/types/MatchCallback.html +17 -6
  115. package/docs/types/SeqEarlyBreaker.html +17 -6
  116. package/docs/types/SeqFn.html +17 -6
  117. package/docs/types/SeqFunctions.html +17 -6
  118. package/docs/types/SetImmutablePath.html +17 -6
  119. package/docs/types/ThrottledFunction.html +17 -6
  120. package/docs/variables/mapValuesUNSET.html +17 -6
  121. package/docs/variables/mergeUNSET.html +17 -6
  122. package/esm/ensureDate.d.ts +3 -0
  123. package/esm/ensureDate.d.ts.map +1 -0
  124. package/esm/ensureDate.js +8 -0
  125. package/esm/ensureDate.js.map +1 -0
  126. package/esm/ensureError.d.ts.map +1 -1
  127. package/esm/ensureError.js.map +1 -1
  128. package/esm/ensurePrefix.d.ts +3 -0
  129. package/esm/ensurePrefix.d.ts.map +1 -0
  130. package/esm/ensurePrefix.js +8 -0
  131. package/esm/ensurePrefix.js.map +1 -0
  132. package/esm/ensureSuffix.d.ts +3 -0
  133. package/esm/ensureSuffix.d.ts.map +1 -0
  134. package/esm/ensureSuffix.js +8 -0
  135. package/esm/ensureSuffix.js.map +1 -0
  136. package/esm/ensureTimestamp.d.ts +3 -0
  137. package/esm/ensureTimestamp.d.ts.map +1 -0
  138. package/esm/ensureTimestamp.js +8 -0
  139. package/esm/ensureTimestamp.js.map +1 -0
  140. package/esm/escapeRegExp.d.ts +3 -0
  141. package/esm/escapeRegExp.d.ts.map +1 -0
  142. package/esm/escapeRegExp.js +5 -0
  143. package/esm/escapeRegExp.js.map +1 -0
  144. package/esm/index.d.ts +10 -0
  145. package/esm/index.d.ts.map +1 -1
  146. package/esm/index.js +10 -0
  147. package/esm/index.js.map +1 -1
  148. package/esm/isPlainObject.d.ts.map +1 -1
  149. package/esm/isPlainObject.js.map +1 -1
  150. package/esm/replace.d.ts +3 -0
  151. package/esm/replace.d.ts.map +1 -0
  152. package/esm/replace.js +7 -0
  153. package/esm/replace.js.map +1 -0
  154. package/esm/safe.d.ts +4 -0
  155. package/esm/safe.d.ts.map +1 -0
  156. package/esm/safe.js +10 -0
  157. package/esm/safe.js.map +1 -0
  158. package/esm/sortProps.d.ts +3 -0
  159. package/esm/sortProps.d.ts.map +1 -0
  160. package/esm/sortProps.js +16 -0
  161. package/esm/sortProps.js.map +1 -0
  162. package/esm/stripPrefix.d.ts +3 -0
  163. package/esm/stripPrefix.d.ts.map +1 -0
  164. package/esm/stripPrefix.js +8 -0
  165. package/esm/stripPrefix.js.map +1 -0
  166. package/esm/stripSuffix.d.ts +3 -0
  167. package/esm/stripSuffix.d.ts.map +1 -0
  168. package/esm/stripSuffix.js +8 -0
  169. package/esm/stripSuffix.js.map +1 -0
  170. package/package.json +23 -23
  171. package/src/coalesce.ts +2 -2
  172. package/src/ensureArray.ts +1 -1
  173. package/src/ensureDate.spec.ts +13 -0
  174. package/src/ensureDate.ts +18 -0
  175. package/src/ensureError.ts +7 -0
  176. package/src/ensurePrefix.spec.ts +11 -0
  177. package/src/ensurePrefix.ts +18 -0
  178. package/src/ensureSuffix.spec.ts +11 -0
  179. package/src/ensureSuffix.ts +18 -0
  180. package/src/ensureTimestamp.spec.ts +11 -0
  181. package/src/ensureTimestamp.ts +18 -0
  182. package/src/escapeRegExp.spec.ts +31 -0
  183. package/src/escapeRegExp.ts +17 -0
  184. package/src/index.ts +10 -0
  185. package/src/isPlainObject.spec.ts +0 -7
  186. package/src/isPlainObject.ts +5 -0
  187. package/src/replace.spec.ts +22 -0
  188. package/src/replace.ts +19 -0
  189. package/src/safe.spec.ts +52 -0
  190. package/src/safe.ts +24 -0
  191. package/src/sortProps.spec.ts +20 -0
  192. package/src/sortProps.ts +21 -0
  193. package/src/stripPrefix.spec.ts +13 -0
  194. package/src/stripPrefix.ts +15 -0
  195. package/src/stripSuffix.spec.ts +13 -0
  196. package/src/stripSuffix.ts +16 -0
  197. package/typedoc.cjs +5 -0
@@ -0,0 +1,3 @@
1
+ declare const ensurePrefix: (string: string, prefix: string) => string;
2
+ export { ensurePrefix, };
3
+ //# sourceMappingURL=ensurePrefix.d.ts.map
@@ -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,8 @@
1
+ const ensurePrefix = (string, prefix) => {
2
+ if (string.startsWith(prefix)) {
3
+ return string;
4
+ }
5
+ return prefix + string;
6
+ };
7
+ export { ensurePrefix, };
8
+ //# sourceMappingURL=ensurePrefix.js.map
@@ -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,3 @@
1
+ declare const ensureSuffix: (string: string, suffix: string) => string;
2
+ export { ensureSuffix, };
3
+ //# sourceMappingURL=ensureSuffix.d.ts.map
@@ -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,8 @@
1
+ const ensureSuffix = (string, suffix) => {
2
+ if (string.endsWith(suffix)) {
3
+ return string;
4
+ }
5
+ return string + suffix;
6
+ };
7
+ export { ensureSuffix, };
8
+ //# sourceMappingURL=ensureSuffix.js.map
@@ -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,3 @@
1
+ declare const ensureTimestamp: (date: Date | number) => number;
2
+ export { ensureTimestamp, };
3
+ //# sourceMappingURL=ensureTimestamp.d.ts.map
@@ -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,8 @@
1
+ const ensureTimestamp = (date) => {
2
+ if (typeof date === "number") {
3
+ return date;
4
+ }
5
+ return date.getTime();
6
+ };
7
+ export { ensureTimestamp, };
8
+ //# sourceMappingURL=ensureTimestamp.js.map
@@ -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,3 @@
1
+ declare const escapeRegExp: (string: string) => string;
2
+ export { escapeRegExp, };
3
+ //# sourceMappingURL=escapeRegExp.d.ts.map
@@ -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,5 @@
1
+ const escapeRegExp = (string) => {
2
+ return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
3
+ };
4
+ export { escapeRegExp, };
5
+ //# sourceMappingURL=escapeRegExp.js.map
@@ -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";
@@ -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":"AAIA,QAAA,MAAM,aAAa,UAAW,OAAO,YAQpC,CAAC;AAEF,OAAO,EACH,aAAa,GAChB,CAAC"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"isPlainObject.js","sourceRoot":"","sources":["../src/isPlainObject.ts"],"names":[],"mappings":"AAIA,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"}
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"}
@@ -0,0 +1,3 @@
1
+ declare const replace: (source: string, replaceMap: Record<string, string>) => string;
2
+ export { replace, };
3
+ //# sourceMappingURL=replace.d.ts.map
@@ -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,4 @@
1
+ declare function safe<T>(fn: () => T): T | undefined;
2
+ declare function safe<T, Y>(fn: () => T, def: Y): T | Y;
3
+ export { safe };
4
+ //# sourceMappingURL=safe.d.ts.map
@@ -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
@@ -0,0 +1,10 @@
1
+ function safe(fn, def) {
2
+ try {
3
+ return fn();
4
+ }
5
+ catch {
6
+ return def;
7
+ }
8
+ }
9
+ export { safe };
10
+ //# sourceMappingURL=safe.js.map
@@ -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,3 @@
1
+ declare const sortProps: <T extends Record<string, unknown>>(object: T, asc?: boolean) => T;
2
+ export { sortProps, };
3
+ //# sourceMappingURL=sortProps.d.ts.map
@@ -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"}
@@ -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,3 @@
1
+ declare const stripPrefix: (from: string, prefix: string) => string;
2
+ export { stripPrefix, };
3
+ //# sourceMappingURL=stripPrefix.d.ts.map
@@ -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,8 @@
1
+ const stripPrefix = (from, prefix) => {
2
+ if (from.startsWith(prefix)) {
3
+ return from.slice(prefix.length);
4
+ }
5
+ return from;
6
+ };
7
+ export { stripPrefix, };
8
+ //# sourceMappingURL=stripPrefix.js.map
@@ -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,3 @@
1
+ declare const stripSuffix: (from: string, suffix: string) => string;
2
+ export { stripSuffix, };
3
+ //# sourceMappingURL=stripSuffix.d.ts.map
@@ -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,8 @@
1
+ const stripSuffix = (from, suffix) => {
2
+ if (from.endsWith(suffix)) {
3
+ return from.slice(0, -suffix.length);
4
+ }
5
+ return from;
6
+ };
7
+ export { stripSuffix, };
8
+ //# sourceMappingURL=stripSuffix.js.map
@@ -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.1.0",
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 --pluginPages ./pagesconfig.json",
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.19.3",
39
- "@babel/preset-env": "^7.19.3",
40
- "@babel/preset-typescript": "^7.18.6",
41
- "@dzek69/eslint-config-base": "^2.3.0",
42
- "@dzek69/eslint-config-typescript": "^1.0.2",
43
- "@types/jest": "^29.0.3",
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.38.1",
46
- "@typescript-eslint/parser": "^5.38.1",
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.24.0",
49
- "fs-extra": "^10.1.0",
50
- "husky": "^8.0.1",
51
- "jest": "^29.1.1",
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.20",
58
+ "nodemon": "^2.0.22",
59
+ "prettier": "^2.8.7",
55
60
  "ts-node": "^10.9.1",
56
- "typedoc": "^0.23.15",
57
- "typescript": "^4.9.5",
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.8.0",
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 0, 5); // returns 5
6
- * @example coalesce(4, null, 6, undefined); // returns 4
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Wraps value in an array until the value is already an array
2
+ * Wraps value in an array unless the value is already an array
3
3
  * @param {*} value - value to be wrapped
4
4
  * @returns {Array}
5
5
  */
@@ -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
+ };
@@ -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";