@spscommerce/utils 5.20.0 → 5.20.3-ie

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 (209) hide show
  1. package/dist/out-tsc/array/flatten.d.ts +1 -0
  2. package/dist/out-tsc/array/flatten.js +7 -0
  3. package/dist/out-tsc/array/flatten.js.map +1 -0
  4. package/dist/out-tsc/array/flatten.spec.d.ts +1 -0
  5. package/dist/out-tsc/array/flatten.spec.js +10 -0
  6. package/dist/out-tsc/array/flatten.spec.js.map +1 -0
  7. package/dist/out-tsc/array/index.d.ts +3 -0
  8. package/dist/out-tsc/array/index.js +4 -0
  9. package/dist/out-tsc/array/index.js.map +1 -0
  10. package/dist/out-tsc/array/is-subset.d.ts +4 -0
  11. package/dist/out-tsc/array/is-subset.js +41 -0
  12. package/dist/out-tsc/array/is-subset.js.map +1 -0
  13. package/dist/out-tsc/array/is-subset.spec.d.ts +1 -0
  14. package/dist/out-tsc/array/is-subset.spec.js +41 -0
  15. package/dist/out-tsc/array/is-subset.spec.js.map +1 -0
  16. package/dist/out-tsc/array/range.d.ts +5 -0
  17. package/dist/out-tsc/array/range.js +16 -0
  18. package/dist/out-tsc/array/range.js.map +1 -0
  19. package/dist/out-tsc/array/range.spec.d.ts +1 -0
  20. package/dist/out-tsc/array/range.spec.js +26 -0
  21. package/dist/out-tsc/array/range.spec.js.map +1 -0
  22. package/dist/out-tsc/classes/custom-event.d.ts +4 -0
  23. package/dist/out-tsc/classes/custom-event.js +87 -0
  24. package/dist/out-tsc/classes/custom-event.js.map +1 -0
  25. package/dist/out-tsc/classes/index.d.ts +1 -0
  26. package/dist/out-tsc/classes/index.js +2 -0
  27. package/dist/out-tsc/classes/index.js.map +1 -0
  28. package/dist/out-tsc/data/doctypes.d.ts +4 -0
  29. package/dist/out-tsc/data/doctypes.js +302 -0
  30. package/dist/out-tsc/data/doctypes.js.map +1 -0
  31. package/dist/out-tsc/data/index.d.ts +1 -0
  32. package/dist/out-tsc/data/index.js +2 -0
  33. package/dist/out-tsc/data/index.js.map +1 -0
  34. package/dist/out-tsc/decorators/cast-to-number.d.ts +5 -0
  35. package/dist/out-tsc/decorators/cast-to-number.js +29 -0
  36. package/dist/out-tsc/decorators/cast-to-number.js.map +1 -0
  37. package/dist/out-tsc/decorators/debounced.broken_spec.d.ts +0 -0
  38. package/dist/out-tsc/decorators/debounced.broken_spec.js +38 -0
  39. package/dist/out-tsc/decorators/debounced.broken_spec.js.map +1 -0
  40. package/dist/out-tsc/decorators/debounced.d.ts +11 -0
  41. package/dist/out-tsc/decorators/debounced.js +35 -0
  42. package/dist/out-tsc/decorators/debounced.js.map +1 -0
  43. package/dist/out-tsc/decorators/index.d.ts +5 -0
  44. package/dist/out-tsc/decorators/index.js +6 -0
  45. package/dist/out-tsc/decorators/index.js.map +1 -0
  46. package/dist/out-tsc/decorators/locked-to-animation-frames.d.ts +4 -0
  47. package/dist/out-tsc/decorators/locked-to-animation-frames.js +34 -0
  48. package/dist/out-tsc/decorators/locked-to-animation-frames.js.map +1 -0
  49. package/dist/out-tsc/decorators/locked-to-animation-frames.spec.d.ts +0 -0
  50. package/dist/out-tsc/decorators/locked-to-animation-frames.spec.js +63 -0
  51. package/dist/out-tsc/decorators/locked-to-animation-frames.spec.js.map +1 -0
  52. package/dist/out-tsc/decorators/simple-metadata-decorator-applicator.d.ts +11 -0
  53. package/dist/out-tsc/decorators/simple-metadata-decorator-applicator.js +80 -0
  54. package/dist/out-tsc/decorators/simple-metadata-decorator-applicator.js.map +1 -0
  55. package/dist/out-tsc/decorators/tick-delay.d.ts +6 -0
  56. package/dist/out-tsc/decorators/tick-delay.js +31 -0
  57. package/dist/out-tsc/decorators/tick-delay.js.map +1 -0
  58. package/dist/out-tsc/function/debounce.d.ts +9 -0
  59. package/dist/out-tsc/function/debounce.js +102 -0
  60. package/dist/out-tsc/function/debounce.js.map +1 -0
  61. package/dist/out-tsc/function/debounce.spec.d.ts +1 -0
  62. package/dist/out-tsc/function/debounce.spec.js +150 -0
  63. package/dist/out-tsc/function/debounce.spec.js.map +1 -0
  64. package/dist/out-tsc/function/debounced-function.interface.d.ts +10 -0
  65. package/dist/out-tsc/function/debounced-function.interface.js +2 -0
  66. package/dist/out-tsc/function/debounced-function.interface.js.map +1 -0
  67. package/dist/out-tsc/function/delayed-function.interface.d.ts +10 -0
  68. package/dist/out-tsc/function/delayed-function.interface.js +2 -0
  69. package/dist/out-tsc/function/delayed-function.interface.js.map +1 -0
  70. package/dist/out-tsc/function/index.d.ts +6 -0
  71. package/dist/out-tsc/function/index.js +7 -0
  72. package/dist/out-tsc/function/index.js.map +1 -0
  73. package/dist/out-tsc/function/lock-to-animation-frames.d.ts +7 -0
  74. package/dist/out-tsc/function/lock-to-animation-frames.js +43 -0
  75. package/dist/out-tsc/function/lock-to-animation-frames.js.map +1 -0
  76. package/dist/out-tsc/function/lock-to-animation-frames.spec.d.ts +0 -0
  77. package/dist/out-tsc/function/lock-to-animation-frames.spec.js +53 -0
  78. package/dist/out-tsc/function/lock-to-animation-frames.spec.js.map +1 -0
  79. package/dist/out-tsc/function/on-next-tick.d.ts +8 -0
  80. package/dist/out-tsc/function/on-next-tick.js +12 -0
  81. package/dist/out-tsc/function/on-next-tick.js.map +1 -0
  82. package/dist/out-tsc/function/on-next-tick.spec.d.ts +1 -0
  83. package/dist/out-tsc/function/on-next-tick.spec.js +13 -0
  84. package/dist/out-tsc/function/on-next-tick.spec.js.map +1 -0
  85. package/dist/out-tsc/function/op.d.ts +32 -0
  86. package/dist/out-tsc/function/op.js +34 -0
  87. package/dist/out-tsc/function/op.js.map +1 -0
  88. package/dist/out-tsc/function/op.spec.d.ts +1 -0
  89. package/dist/out-tsc/function/op.spec.js +94 -0
  90. package/dist/out-tsc/function/op.spec.js.map +1 -0
  91. package/dist/out-tsc/index.d.ts +9 -0
  92. package/dist/out-tsc/index.js +10 -0
  93. package/dist/out-tsc/index.js.map +1 -0
  94. package/dist/out-tsc/number/constrain.d.ts +7 -0
  95. package/dist/out-tsc/number/constrain.js +16 -0
  96. package/dist/out-tsc/number/constrain.js.map +1 -0
  97. package/dist/out-tsc/number/decimal-round.d.ts +7 -0
  98. package/dist/out-tsc/number/decimal-round.js +19 -0
  99. package/dist/out-tsc/number/decimal-round.js.map +1 -0
  100. package/dist/out-tsc/number/decimal-round.spec.d.ts +1 -0
  101. package/dist/out-tsc/number/decimal-round.spec.js +10 -0
  102. package/dist/out-tsc/number/decimal-round.spec.js.map +1 -0
  103. package/dist/out-tsc/number/index.d.ts +3 -0
  104. package/dist/out-tsc/number/index.js +4 -0
  105. package/dist/out-tsc/number/index.js.map +1 -0
  106. package/dist/out-tsc/number/to-file-size-string.d.ts +5 -0
  107. package/dist/out-tsc/number/to-file-size-string.js +24 -0
  108. package/dist/out-tsc/number/to-file-size-string.js.map +1 -0
  109. package/dist/out-tsc/object/copy-property.d.ts +6 -0
  110. package/dist/out-tsc/object/copy-property.js +9 -0
  111. package/dist/out-tsc/object/copy-property.js.map +1 -0
  112. package/dist/out-tsc/object/copy-property.spec.d.ts +1 -0
  113. package/dist/out-tsc/object/copy-property.spec.js +16 -0
  114. package/dist/out-tsc/object/copy-property.spec.js.map +1 -0
  115. package/dist/out-tsc/object/crumble-path.d.ts +6 -0
  116. package/dist/out-tsc/object/crumble-path.js +9 -0
  117. package/dist/out-tsc/object/crumble-path.js.map +1 -0
  118. package/dist/out-tsc/object/crumble-path.spec.d.ts +1 -0
  119. package/dist/out-tsc/object/crumble-path.spec.js +24 -0
  120. package/dist/out-tsc/object/crumble-path.spec.js.map +1 -0
  121. package/dist/out-tsc/object/deep-freeze.d.ts +1 -0
  122. package/dist/out-tsc/object/deep-freeze.js +36 -0
  123. package/dist/out-tsc/object/deep-freeze.js.map +1 -0
  124. package/dist/out-tsc/object/deep-freeze.spec.d.ts +1 -0
  125. package/dist/out-tsc/object/deep-freeze.spec.js +14 -0
  126. package/dist/out-tsc/object/deep-freeze.spec.js.map +1 -0
  127. package/dist/out-tsc/object/diff.d.ts +12 -0
  128. package/dist/out-tsc/object/diff.js +92 -0
  129. package/dist/out-tsc/object/diff.js.map +1 -0
  130. package/dist/out-tsc/object/diff.spec.d.ts +1 -0
  131. package/dist/out-tsc/object/diff.spec.js +40 -0
  132. package/dist/out-tsc/object/diff.spec.js.map +1 -0
  133. package/dist/out-tsc/object/for-each-entry-deep.d.ts +4 -0
  134. package/dist/out-tsc/object/for-each-entry-deep.js +38 -0
  135. package/dist/out-tsc/object/for-each-entry-deep.js.map +1 -0
  136. package/dist/out-tsc/object/for-each-entry-deep.spec.d.ts +1 -0
  137. package/dist/out-tsc/object/for-each-entry-deep.spec.js +24 -0
  138. package/dist/out-tsc/object/for-each-entry-deep.spec.js.map +1 -0
  139. package/dist/out-tsc/object/for-each-nested-object.d.ts +4 -0
  140. package/dist/out-tsc/object/for-each-nested-object.js +38 -0
  141. package/dist/out-tsc/object/for-each-nested-object.js.map +1 -0
  142. package/dist/out-tsc/object/for-each-nested-object.spec.d.ts +1 -0
  143. package/dist/out-tsc/object/for-each-nested-object.spec.js +46 -0
  144. package/dist/out-tsc/object/for-each-nested-object.spec.js.map +1 -0
  145. package/dist/out-tsc/object/get-path.d.ts +5 -0
  146. package/dist/out-tsc/object/get-path.js +67 -0
  147. package/dist/out-tsc/object/get-path.js.map +1 -0
  148. package/dist/out-tsc/object/get-path.spec.d.ts +1 -0
  149. package/dist/out-tsc/object/get-path.spec.js +44 -0
  150. package/dist/out-tsc/object/get-path.spec.js.map +1 -0
  151. package/dist/out-tsc/object/index.d.ts +13 -0
  152. package/dist/out-tsc/object/index.js +14 -0
  153. package/dist/out-tsc/object/index.js.map +1 -0
  154. package/dist/out-tsc/object/merge-deep.d.ts +4 -0
  155. package/dist/out-tsc/object/merge-deep.js +60 -0
  156. package/dist/out-tsc/object/merge-deep.js.map +1 -0
  157. package/dist/out-tsc/object/merge-deep.spec.d.ts +1 -0
  158. package/dist/out-tsc/object/merge-deep.spec.js +16 -0
  159. package/dist/out-tsc/object/merge-deep.spec.js.map +1 -0
  160. package/dist/out-tsc/object/merge-properties-deep.d.ts +4 -0
  161. package/dist/out-tsc/object/merge-properties-deep.js +61 -0
  162. package/dist/out-tsc/object/merge-properties-deep.js.map +1 -0
  163. package/dist/out-tsc/object/merge-properties-deep.spec.d.ts +1 -0
  164. package/dist/out-tsc/object/merge-properties-deep.spec.js +24 -0
  165. package/dist/out-tsc/object/merge-properties-deep.spec.js.map +1 -0
  166. package/dist/out-tsc/object/omit.d.ts +1 -0
  167. package/dist/out-tsc/object/omit.js +40 -0
  168. package/dist/out-tsc/object/omit.js.map +1 -0
  169. package/dist/out-tsc/object/omit.spec.d.ts +1 -0
  170. package/dist/out-tsc/object/omit.spec.js +10 -0
  171. package/dist/out-tsc/object/omit.spec.js.map +1 -0
  172. package/dist/out-tsc/object/set-path.d.ts +2 -0
  173. package/dist/out-tsc/object/set-path.js +45 -0
  174. package/dist/out-tsc/object/set-path.js.map +1 -0
  175. package/dist/out-tsc/object/set-path.spec.d.ts +1 -0
  176. package/dist/out-tsc/object/set-path.spec.js +36 -0
  177. package/dist/out-tsc/object/set-path.spec.js.map +1 -0
  178. package/dist/out-tsc/object/traverse-path.d.ts +2 -0
  179. package/dist/out-tsc/object/traverse-path.js +81 -0
  180. package/dist/out-tsc/object/traverse-path.js.map +1 -0
  181. package/dist/out-tsc/object/values.d.ts +2 -0
  182. package/dist/out-tsc/object/values.js +31 -0
  183. package/dist/out-tsc/object/values.js.map +1 -0
  184. package/dist/out-tsc/object/values.spec.d.ts +1 -0
  185. package/dist/out-tsc/object/values.spec.js +7 -0
  186. package/dist/out-tsc/object/values.spec.js.map +1 -0
  187. package/dist/out-tsc/string/code.template-tag.d.ts +2 -0
  188. package/dist/out-tsc/string/code.template-tag.js +38 -0
  189. package/dist/out-tsc/string/code.template-tag.js.map +1 -0
  190. package/dist/out-tsc/string/index.d.ts +3 -0
  191. package/dist/out-tsc/string/index.js +4 -0
  192. package/dist/out-tsc/string/index.js.map +1 -0
  193. package/dist/out-tsc/string/parse-file-size.d.ts +5 -0
  194. package/dist/out-tsc/string/parse-file-size.js +43 -0
  195. package/dist/out-tsc/string/parse-file-size.js.map +1 -0
  196. package/dist/out-tsc/string/template.d.ts +15 -0
  197. package/dist/out-tsc/string/template.js +28 -0
  198. package/dist/out-tsc/string/template.js.map +1 -0
  199. package/dist/out-tsc/string/template.spec.d.ts +1 -0
  200. package/dist/out-tsc/string/template.spec.js +39 -0
  201. package/dist/out-tsc/string/template.spec.js.map +1 -0
  202. package/dist/out-tsc/typings.d.ts +1 -0
  203. package/dist/out-tsc/typings.js +2 -0
  204. package/dist/out-tsc/typings.js.map +1 -0
  205. package/lib/index.cjs.js +2437 -1
  206. package/lib/index.es.js +2268 -893
  207. package/package.json +5 -5
  208. package/rollup.config.js +22 -0
  209. package/vite.config.js +1 -1
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Progressively rounds `num` to `decimalPlaces` places. This differs from other
3
+ * rounding methods out there such as lodash's, which are not progressive. For example,
4
+ * `(0.149).toFixed(1)` and lodash `_.round(0.149, 1)` both return `0.1`, but this
5
+ * function rounds `0.149` to `0.15` and then `0.15` to `0.2` and returns `0.2`.
6
+ */
7
+ export function decimalRound(num, decimalPlaces) {
8
+ if (decimalPlaces === void 0) { decimalPlaces = 0; }
9
+ var integralAndFractionalSplit = String(num).split(".");
10
+ var allDecimalPlaces = integralAndFractionalSplit.length > 1
11
+ ? integralAndFractionalSplit[1].length
12
+ : 0;
13
+ var roundedNum = num;
14
+ for (var i = allDecimalPlaces - 1; i >= decimalPlaces; i -= 1) {
15
+ roundedNum = Number(Math.round(Number(roundedNum + "e" + i)) + "e-" + i);
16
+ }
17
+ return roundedNum;
18
+ }
19
+ //# sourceMappingURL=decimal-round.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal-round.js","sourceRoot":"","sources":["../../../src/number/decimal-round.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,aAAiB;IAAjB,8BAAA,EAAA,iBAAiB;IACzD,IAAM,0BAA0B,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1D,IAAM,gBAAgB,GAAG,0BAA0B,CAAC,MAAM,GAAG,CAAC;QAC5D,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,MAAM;QACtC,CAAC,CAAC,CAAC,CAAC;IAEN,IAAI,UAAU,GAAG,GAAG,CAAC;IACrB,KAAK,IAAI,CAAC,GAAG,gBAAgB,GAAG,CAAC,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE;QAC7D,UAAU,GAAG,MAAM,CAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAI,UAAU,SAAI,CAAG,CAAC,CAAC,UAAK,CAAG,CAAC,CAAC;KAC1E;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { decimalRound } from "./decimal-round";
2
+ describe("decimalRound", function () {
3
+ test("does decimal rounding", function () {
4
+ expect(decimalRound(1.49)).toEqual(2);
5
+ });
6
+ test("rounds to a given number of places", function () {
7
+ expect(decimalRound(0.0149, 2)).toEqual(0.02);
8
+ });
9
+ });
10
+ //# sourceMappingURL=decimal-round.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal-round.spec.js","sourceRoot":"","sources":["../../../src/number/decimal-round.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,QAAQ,CAAC,cAAc,EAAE;IACvB,IAAI,CAAC,uBAAuB,EAAE;QAC5B,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,oCAAoC,EAAE;QACzC,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./constrain";
2
+ export * from "./decimal-round";
3
+ export * from "./to-file-size-string";
@@ -0,0 +1,4 @@
1
+ export * from "./constrain";
2
+ export * from "./decimal-round";
3
+ export * from "./to-file-size-string";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/number/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Converts a file size in bytes to a human-friendly string. For example,
3
+ * `toFileSizeString(2048)` will return `"2.00KB"`.
4
+ */
5
+ export declare function toFileSizeString(n: number, precision?: number): string;
@@ -0,0 +1,24 @@
1
+ import { decimalRound } from "./decimal-round";
2
+ /**
3
+ * Converts a file size in bytes to a human-friendly string. For example,
4
+ * `toFileSizeString(2048)` will return `"2.00KB"`.
5
+ */
6
+ export function toFileSizeString(n, precision) {
7
+ if (precision === void 0) { precision = 2; }
8
+ if (n > Number.MAX_SAFE_INTEGER) {
9
+ throw new Error("Number is greater than MAX_SAFE_INTEGER; "
10
+ + "toFileSizeString does not support orders of magnitude "
11
+ + "higher than petabytes for this reason until BigInt "
12
+ + "achieves broad browser support.");
13
+ }
14
+ var magnitude = Math.min(Math.floor(Math.log(n) / Math.log(1024)), 5);
15
+ var unit = ["B",
16
+ "KB",
17
+ "MB",
18
+ "GB",
19
+ "TB",
20
+ "PB"][magnitude];
21
+ var decimalPlaces = magnitude ? precision : 0;
22
+ return decimalRound(n / (Math.pow(1024, magnitude)), decimalPlaces).toFixed(decimalPlaces) + unit;
23
+ }
24
+ //# sourceMappingURL=to-file-size-string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-file-size-string.js","sourceRoot":"","sources":["../../../src/number/to-file-size-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,CAAS,EAAE,SAAa;IAAb,0BAAA,EAAA,aAAa;IACvD,IAAI,CAAC,GAAG,MAAM,CAAC,gBAAgB,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,2CAA2C;cAC/B,wDAAwD;cACxD,qDAAqD;cACrD,iCAAiC,CAC9C,CAAC;KACH;IACD,IAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,IAAM,IAAI,GAAG,CAAC,GAAG;QACf,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC;IACnB,IAAM,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,OAAO,YAAY,CAAC,CAAC,GAAG,CAAC,SAAA,IAAI,EAAI,SAAS,CAAA,CAAC,EAAE,aAAa,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;AAC5F,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copy a property from one object to another using its property descriptor.
3
+ * In other words, if it's a getter/setter on `sourceObject` it'll be the same
4
+ * getter/setter on `destObject`. If it's just a value it'll be just a value.
5
+ */
6
+ export declare function copyProperty(propName: PropertyKey, sourceObject: any, destObject: any): void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copy a property from one object to another using its property descriptor.
3
+ * In other words, if it's a getter/setter on `sourceObject` it'll be the same
4
+ * getter/setter on `destObject`. If it's just a value it'll be just a value.
5
+ */
6
+ export function copyProperty(propName, sourceObject, destObject) {
7
+ Object.defineProperty(destObject, propName, Object.getOwnPropertyDescriptor(sourceObject, propName));
8
+ }
9
+ //# sourceMappingURL=copy-property.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-property.js","sourceRoot":"","sources":["../../../src/object/copy-property.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,QAAqB,EAAE,YAAiB,EAAE,UAAe;IACpF,MAAM,CAAC,cAAc,CACnB,UAAU,EACV,QAAQ,EACR,MAAM,CAAC,wBAAwB,CAAC,YAAY,EAAE,QAAQ,CAAC,CACxD,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { copyProperty } from "./copy-property";
2
+ describe("copyProperty", function () {
3
+ test("copies a property from sourceObject to destObject", function () {
4
+ var sourceObject = {
5
+ n: 2,
6
+ get nn() {
7
+ return this.n * this.n;
8
+ },
9
+ };
10
+ var destObject = { n: 4, nn: null };
11
+ copyProperty("nn", sourceObject, destObject);
12
+ expect(sourceObject.nn).toBe(4);
13
+ expect(destObject.nn).toBe(16);
14
+ });
15
+ });
16
+ //# sourceMappingURL=copy-property.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-property.spec.js","sourceRoot":"","sources":["../../../src/object/copy-property.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,QAAQ,CAAC,cAAc,EAAE;IACvB,IAAI,CAAC,mDAAmD,EAAE;QACxD,IAAM,YAAY,GAAG;YACnB,CAAC,EAAE,CAAC;YACJ,IAAI,EAAE;gBACJ,OAAO,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;YACzB,CAAC;SACF,CAAC;QACF,IAAM,UAAU,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;QAEtC,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QAE7C,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Converts a path to crumbs.
3
+ * For example:
4
+ * "a.b[0].c" -> ["a", "b", "0", "c"]
5
+ */
6
+ export declare function crumblePath(path: string | PropertyKey | PropertyKey[]): PropertyKey[];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Converts a path to crumbs.
3
+ * For example:
4
+ * "a.b[0].c" -> ["a", "b", "0", "c"]
5
+ */
6
+ export function crumblePath(path) {
7
+ return typeof path === "string" ? path.match(/[^.[\]]+/g) || [] : [].concat(path);
8
+ }
9
+ //# sourceMappingURL=crumble-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crumble-path.js","sourceRoot":"","sources":["../../../src/object/crumble-path.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAA0C;IACpE,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACpF,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import { crumblePath } from "./crumble-path";
2
+ describe("crumblePath", function () {
3
+ test("crumbles a dot path", function () {
4
+ expect(crumblePath("a.b.c")).toEqual(["a",
5
+ "b",
6
+ "c"]);
7
+ });
8
+ test("crumbles a bracket path", function () {
9
+ expect(crumblePath("[0][1][2]")).toEqual(["0",
10
+ "1",
11
+ "2"]);
12
+ });
13
+ test("crumbles a mixed path", function () {
14
+ expect(crumblePath("a.b[0].c")).toEqual(["a",
15
+ "b",
16
+ "0",
17
+ "c"]);
18
+ });
19
+ test("doesn't break on a single-crumb path", function () {
20
+ expect(crumblePath("a")).toEqual(["a"]);
21
+ expect(crumblePath("[0]")).toEqual(["0"]);
22
+ });
23
+ });
24
+ //# sourceMappingURL=crumble-path.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crumble-path.spec.js","sourceRoot":"","sources":["../../../src/object/crumble-path.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,QAAQ,CAAC,aAAa,EAAE;IACtB,IAAI,CAAC,qBAAqB,EAAE;QAC1B,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG;YACvC,GAAG;YACH,GAAG,CAAC,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yBAAyB,EAAE;QAC9B,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG;YAC3C,GAAG;YACH,GAAG,CAAC,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uBAAuB,EAAE;QAC5B,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG;YAC1C,GAAG;YACH,GAAG;YACH,GAAG,CAAC,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,sCAAsC,EAAE;QAC3C,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACxC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function deepFreeze(obj: any): void;
@@ -0,0 +1,36 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ import isPlainObject from "lodash.isplainobject";
13
+ /*
14
+ * Recursive Object.freeze on plain objects and arrays
15
+ */
16
+ export function deepFreeze(obj) {
17
+ var e_1, _a;
18
+ Object.freeze(obj);
19
+ try {
20
+ for (var _b = __values(Object.keys(obj)), _c = _b.next(); !_c.done; _c = _b.next()) {
21
+ var key = _c.value;
22
+ var val = obj[key];
23
+ if (isPlainObject(val) || Array.isArray(val)) {
24
+ deepFreeze(val);
25
+ }
26
+ }
27
+ }
28
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
29
+ finally {
30
+ try {
31
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
32
+ }
33
+ finally { if (e_1) throw e_1.error; }
34
+ }
35
+ }
36
+ //# sourceMappingURL=deep-freeze.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-freeze.js","sourceRoot":"","sources":["../../../src/object/deep-freeze.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAG;;IAC5B,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;;QACnB,KAAkB,IAAA,KAAA,SAAA,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,gBAAA,4BAAE;YAA/B,IAAM,GAAG,WAAA;YACZ,IAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACrB,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBAC5C,UAAU,CAAC,GAAG,CAAC,CAAC;aACjB;SACF;;;;;;;;;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { deepFreeze } from "./deep-freeze";
2
+ describe("deepFreeze", function () {
3
+ test("should recursively freeze the input", function () {
4
+ var obj = { a: { b: 1 } };
5
+ deepFreeze(obj);
6
+ expect(function () {
7
+ obj.a = "q";
8
+ }).toThrow();
9
+ expect(function () {
10
+ obj.a.b = 2;
11
+ }).toThrow();
12
+ });
13
+ });
14
+ //# sourceMappingURL=deep-freeze.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-freeze.spec.js","sourceRoot":"","sources":["../../../src/object/deep-freeze.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,QAAQ,CAAC,YAAY,EAAE;IACrB,IAAI,CAAC,qCAAqC,EAAE;QAC1C,IAAM,GAAG,GAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACjC,UAAU,CAAC,GAAG,CAAC,CAAC;QAChB,MAAM,CAAC;YACL,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;QACd,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,CAAC;YACL,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare enum DiffChange {
2
+ ADDITION = 0,
3
+ DELETION = 1,
4
+ ALTERATION = 2
5
+ }
6
+ export interface DiffEntry {
7
+ type: DiffChange;
8
+ key: PropertyKey;
9
+ parentPath: PropertyKey[];
10
+ objects: [Record<PropertyKey, unknown>, Record<PropertyKey, unknown>];
11
+ }
12
+ export declare function diff(o1: Record<PropertyKey, unknown>, o2: Record<PropertyKey, unknown>, parentPath?: PropertyKey[]): DiffEntry[];
@@ -0,0 +1,92 @@
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
+ var __values = (this && this.__values) || function(o) {
27
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
28
+ if (m) return m.call(o);
29
+ if (o && typeof o.length === "number") return {
30
+ next: function () {
31
+ if (o && i >= o.length) o = void 0;
32
+ return { value: o && o[i++], done: !o };
33
+ }
34
+ };
35
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
36
+ };
37
+ import isPlainObject from "lodash.isplainobject";
38
+ export var DiffChange;
39
+ (function (DiffChange) {
40
+ DiffChange[DiffChange["ADDITION"] = 0] = "ADDITION";
41
+ DiffChange[DiffChange["DELETION"] = 1] = "DELETION";
42
+ DiffChange[DiffChange["ALTERATION"] = 2] = "ALTERATION";
43
+ })(DiffChange || (DiffChange = {}));
44
+ export function diff(o1, o2, parentPath) {
45
+ var e_1, _a;
46
+ if (parentPath === void 0) { parentPath = []; }
47
+ var d = [];
48
+ try {
49
+ for (var _b = __values(new Set(__spreadArray(__spreadArray([], __read(Object.keys(o1)), false), __read(Object.keys(o2)), false))), _c = _b.next(); !_c.done; _c = _b.next()) {
50
+ var key = _c.value;
51
+ var o1HasKey = Object.prototype.hasOwnProperty.call(o1, key);
52
+ var o2HasKey = Object.prototype.hasOwnProperty.call(o2, key);
53
+ if (o1HasKey && !o2HasKey) {
54
+ d.push({
55
+ type: DiffChange.DELETION,
56
+ key: key,
57
+ parentPath: parentPath,
58
+ objects: [o1, o2],
59
+ });
60
+ }
61
+ else if (!o1HasKey && o2HasKey) {
62
+ d.push({
63
+ type: DiffChange.ADDITION,
64
+ key: key,
65
+ parentPath: parentPath,
66
+ objects: [o1, o2],
67
+ });
68
+ }
69
+ else if ((isPlainObject(o1[key]) && isPlainObject(o2[key]))
70
+ || (Array.isArray(o1[key]) && Array.isArray(o2[key]))) {
71
+ d = d.concat(diff(o1[key], o2[key], __spreadArray(__spreadArray([], __read(parentPath), false), [key], false)));
72
+ }
73
+ else if (o1[key] !== o2[key]) {
74
+ d.push({
75
+ type: DiffChange.ALTERATION,
76
+ key: key,
77
+ parentPath: parentPath,
78
+ objects: [o1, o2],
79
+ });
80
+ }
81
+ }
82
+ }
83
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
84
+ finally {
85
+ try {
86
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
87
+ }
88
+ finally { if (e_1) throw e_1.error; }
89
+ }
90
+ return d;
91
+ }
92
+ //# sourceMappingURL=diff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.js","sourceRoot":"","sources":["../../../src/object/diff.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAEjD,MAAM,CAAN,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,mDAAQ,CAAA;IACR,mDAAQ,CAAA;IACR,uDAAU,CAAA;AACZ,CAAC,EAJW,UAAU,KAAV,UAAU,QAIrB;AASD,MAAM,UAAU,IAAI,CAClB,EAAgC,EAChC,EAAgC,EAChC,UAA8B;;IAA9B,2BAAA,EAAA,eAA8B;IAE9B,IAAI,CAAC,GAAgB,EAAE,CAAC;;QACxB,KAAkB,IAAA,KAAA,SAAA,IAAI,GAAG,wCAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,kBAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,UAAE,CAAA,gBAAA,4BAAE;YAAhE,IAAM,GAAG,WAAA;YACZ,IAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YAC/D,IAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YAE/D,IAAI,QAAQ,IAAI,CAAC,QAAQ,EAAE;gBACzB,CAAC,CAAC,IAAI,CAAC;oBACL,IAAI,EAAE,UAAU,CAAC,QAAQ;oBAAE,GAAG,KAAA;oBAAE,UAAU,YAAA;oBAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;iBAC9D,CAAC,CAAC;aACJ;iBAAM,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE;gBAChC,CAAC,CAAC,IAAI,CAAC;oBACL,IAAI,EAAE,UAAU,CAAC,QAAQ;oBAAE,GAAG,KAAA;oBAAE,UAAU,YAAA;oBAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;iBAC9D,CAAC,CAAC;aACJ;iBAAM,IACL,CAAC,aAAa,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,aAAa,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;mBACrC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAC/D;gBACA,CAAC,GAAG,CAAC,CAAC,MAAM,CACV,IAAI,CACF,EAAE,CAAC,GAAG,CAAiC,EACvC,EAAE,CAAC,GAAG,CAAiC,yCACnC,UAAU,YAAE,GAAG,UACpB,CACF,CAAC;aACH;iBAAM,IAAI,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE;gBAC9B,CAAC,CAAC,IAAI,CAAC;oBACL,IAAI,EAAE,UAAU,CAAC,UAAU;oBAAE,GAAG,KAAA;oBAAE,UAAU,YAAA;oBAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;iBAChE,CAAC,CAAC;aACJ;SACF;;;;;;;;;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import { diff, DiffChange } from "./diff";
2
+ describe("diff", function () {
3
+ test("should report additions", function () {
4
+ var obj1 = { a: {} };
5
+ var obj2 = { foo: "bar", a: { baz: "orp" } };
6
+ expect(diff(obj1, obj2)).toEqual([
7
+ {
8
+ type: DiffChange.ADDITION, key: "baz", parentPath: ["a"], objects: [obj1.a, obj2.a],
9
+ },
10
+ {
11
+ type: DiffChange.ADDITION, key: "foo", parentPath: [], objects: [obj1, obj2],
12
+ },
13
+ ]);
14
+ });
15
+ test("should report deletions", function () {
16
+ var obj1 = { foo: "bar", a: { baz: "orp" } };
17
+ var obj2 = { a: {} };
18
+ expect(diff(obj1, obj2)).toEqual([
19
+ {
20
+ type: DiffChange.DELETION, key: "foo", parentPath: [], objects: [obj1, obj2],
21
+ },
22
+ {
23
+ type: DiffChange.DELETION, key: "baz", parentPath: ["a"], objects: [obj1.a, obj2.a],
24
+ },
25
+ ]);
26
+ });
27
+ test("should report alterations", function () {
28
+ var obj1 = { foo: "bar", a: { baz: "orp" } };
29
+ var obj2 = { foo: "barbar", a: { baz: "orporp" } };
30
+ expect(diff(obj1, obj2)).toEqual([
31
+ {
32
+ type: DiffChange.ALTERATION, key: "foo", parentPath: [], objects: [obj1, obj2],
33
+ },
34
+ {
35
+ type: DiffChange.ALTERATION, key: "baz", parentPath: ["a"], objects: [obj1.a, obj2.a],
36
+ },
37
+ ]);
38
+ });
39
+ });
40
+ //# sourceMappingURL=diff.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.spec.js","sourceRoot":"","sources":["../../../src/object/diff.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE1C,QAAQ,CAAC,MAAM,EAAE;IACf,IAAI,CAAC,yBAAyB,EAAE;QAC9B,IAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;QACvB,IAAM,IAAI,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YAC/B;gBACE,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;aACpF;YACD;gBACE,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;aAC7E;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yBAAyB,EAAE;QAC9B,IAAM,IAAI,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/C,IAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YAC/B;gBACE,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;aAC7E;YACD;gBACE,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;aACpF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,2BAA2B,EAAE;QAChC,IAAM,IAAI,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/C,IAAM,IAAI,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC;QACrD,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YAC/B;gBACE,IAAI,EAAE,UAAU,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;aAC/E;YACD;gBACE,IAAI,EAAE,UAAU,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;aACtF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Recursively navigate a nested object & call `fn` for each key/value pair
3
+ */
4
+ export declare function forEachEntryDeep(object: any, fn: (key: string, value: any, object: any) => any): any;
@@ -0,0 +1,38 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ import isPlainObject from "lodash.isplainobject";
13
+ /**
14
+ * Recursively navigate a nested object & call `fn` for each key/value pair
15
+ */
16
+ export function forEachEntryDeep(object, fn) {
17
+ var e_1, _a;
18
+ try {
19
+ for (var _b = __values(Object.keys(object)), _c = _b.next(); !_c.done; _c = _b.next()) {
20
+ var key = _c.value;
21
+ var value = object[key];
22
+ if (isPlainObject(value) || Array.isArray(value)) {
23
+ forEachEntryDeep(value, fn);
24
+ }
25
+ else {
26
+ fn(key, value, object);
27
+ }
28
+ }
29
+ }
30
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
31
+ finally {
32
+ try {
33
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
34
+ }
35
+ finally { if (e_1) throw e_1.error; }
36
+ }
37
+ }
38
+ //# sourceMappingURL=for-each-entry-deep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for-each-entry-deep.js","sourceRoot":"","sources":["../../../src/object/for-each-entry-deep.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAW,EACX,EAAiD;;;QAEjD,KAAkB,IAAA,KAAA,SAAA,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,gBAAA,4BAAE;YAAlC,IAAM,GAAG,WAAA;YACZ,IAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAChD,gBAAgB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;aAC7B;iBAAM;gBACL,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;aACxB;SACF;;;;;;;;;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import { forEachEntryDeep } from "./for-each-entry-deep";
2
+ describe("forEachEntryDeep", function () {
3
+ test("recursively calls the given function with each key/non-object-like-value pair within the object", function () {
4
+ var targetObject = {
5
+ a: 2,
6
+ b: { bb: 3 },
7
+ c: [{ d: 4 }, { d: "5" }],
8
+ };
9
+ function squareTheThingMaybe(key, value, object) {
10
+ if (typeof value === "number") {
11
+ // eslint-disable-next-line no-param-reassign
12
+ object[key] = value * value;
13
+ }
14
+ }
15
+ var expectedResult = {
16
+ a: 4,
17
+ b: { bb: 9 },
18
+ c: [{ d: 16 }, { d: "5" }],
19
+ };
20
+ forEachEntryDeep(targetObject, squareTheThingMaybe);
21
+ expect(targetObject).toEqual(expectedResult);
22
+ });
23
+ });
24
+ //# sourceMappingURL=for-each-entry-deep.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for-each-entry-deep.spec.js","sourceRoot":"","sources":["../../../src/object/for-each-entry-deep.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,QAAQ,CAAC,kBAAkB,EAAE;IAC3B,IAAI,CAAC,iGAAiG,EAAE;QACtG,IAAM,YAAY,GAAG;YACnB,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE;YACZ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;SAC1B,CAAC;QACF,SAAS,mBAAmB,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM;YAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBAC7B,6CAA6C;gBAC7C,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;aAC7B;QACH,CAAC;QACD,IAAM,cAAc,GAAG;YACrB,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE;YACZ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;SAC3B,CAAC;QAEF,gBAAgB,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC;QAEpD,MAAM,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Recursively navigate a nested object & call `fn` for each subobject
3
+ */
4
+ export declare function forEachNestedObject(object: any, fn: (path: PropertyKey[], object: any) => any, path?: PropertyKey[]): any;
@@ -0,0 +1,38 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ import isPlainObject from "lodash.isplainobject";
13
+ /**
14
+ * Recursively navigate a nested object & call `fn` for each subobject
15
+ */
16
+ export function forEachNestedObject(object, fn, path) {
17
+ var e_1, _a;
18
+ if (path === void 0) { path = []; }
19
+ fn(path, object);
20
+ try {
21
+ for (var _b = __values(Object.keys(object)), _c = _b.next(); !_c.done; _c = _b.next()) {
22
+ var key = _c.value;
23
+ var value = object[key];
24
+ if (isPlainObject(value) || Array.isArray(value)) {
25
+ var newPath = path.concat(key);
26
+ forEachNestedObject(value, fn, newPath);
27
+ }
28
+ }
29
+ }
30
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
31
+ finally {
32
+ try {
33
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
34
+ }
35
+ finally { if (e_1) throw e_1.error; }
36
+ }
37
+ }
38
+ //# sourceMappingURL=for-each-nested-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for-each-nested-object.js","sourceRoot":"","sources":["../../../src/object/for-each-nested-object.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAW,EACX,EAA6C,EAC7C,IAAwB;;IAAxB,qBAAA,EAAA,SAAwB;IAExB,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;;QACjB,KAAkB,IAAA,KAAA,SAAA,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,gBAAA,4BAAE;YAAlC,IAAM,GAAG,WAAA;YACZ,IAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAChD,IAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACjC,mBAAmB,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;aACzC;SACF;;;;;;;;;AACH,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { forEachNestedObject } from "./for-each-nested-object";
2
+ describe("forEachNestedObject", function () {
3
+ test("calls the given function for each nested object within the given root object", function () {
4
+ var targetObject = {
5
+ path: "",
6
+ b: { c: {} },
7
+ d: [
8
+ {
9
+ path: "",
10
+ e: { f: {} },
11
+ },
12
+ { g: "" },
13
+ ],
14
+ };
15
+ function addPath(path, object) {
16
+ var joinedPath = path.join(".");
17
+ if (Array.isArray(object)) {
18
+ object.push(joinedPath);
19
+ }
20
+ else {
21
+ // eslint-disable-next-line no-param-reassign
22
+ object.path = joinedPath;
23
+ }
24
+ }
25
+ var expectedResult = {
26
+ path: "",
27
+ b: { path: "b", c: { path: "b.c" } },
28
+ d: [
29
+ {
30
+ path: "d.0",
31
+ e: { path: "d.0.e", f: { path: "d.0.e.f" } },
32
+ },
33
+ { g: "", path: "d.1" },
34
+ "d",
35
+ ],
36
+ };
37
+ forEachNestedObject(targetObject, addPath);
38
+ /*
39
+ * The fact that addPath() adds properties to the object
40
+ * makes TypeScript have a conniption, hence "as any";
41
+ * in real code one would use interfaces to address this
42
+ */
43
+ expect(targetObject).toEqual(expectedResult);
44
+ });
45
+ });
46
+ //# sourceMappingURL=for-each-nested-object.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for-each-nested-object.spec.js","sourceRoot":"","sources":["../../../src/object/for-each-nested-object.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,QAAQ,CAAC,qBAAqB,EAAE;IAC9B,IAAI,CAAC,8EAA8E,EAAE;QACnF,IAAM,YAAY,GAAG;YACnB,IAAI,EAAE,EAAE;YACR,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE;YACZ,CAAC,EAAE;gBACD;oBACE,IAAI,EAAE,EAAE;oBACR,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE;iBACb;gBACD,EAAE,CAAC,EAAE,EAAE,EAAE;aACV;SACF,CAAC;QACF,SAAS,OAAO,CAAC,IAAI,EAAE,MAAM;YAC3B,IAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBACzB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aACzB;iBAAM;gBACL,6CAA6C;gBAC7C,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC;aAC1B;QACH,CAAC;QACD,IAAM,cAAc,GAAG;YACrB,IAAI,EAAE,EAAE;YACR,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;YACpC,CAAC,EAAE;gBACD;oBACE,IAAI,EAAE,KAAK;oBACX,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;iBAC7C;gBACD,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;gBACtB,GAAG;aACJ;SACF,CAAC;QAEF,mBAAmB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAE3C;;;;WAIG;QACH,MAAM,CAAC,YAAmB,CAAC,CAAC,OAAO,CAAC,cAAqB,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Get the value at `path` starting from `object`.
3
+ * Allows optional chaining, e.g. `get(obj, 'a.b?.c')`
4
+ */
5
+ export declare function getPath<T>(object: any, path: string | PropertyKey | PropertyKey[], defaultValue?: T, allOptional?: boolean): T;