@aglyn/shared-util-tools 1.0.0-beta.143

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 (288) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +7 -0
  3. package/package.json +39 -0
  4. package/src/index.d.ts +72 -0
  5. package/src/index.js +87 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/apply-mixins.d.ts +24 -0
  8. package/src/lib/apply-mixins.js +31 -0
  9. package/src/lib/apply-mixins.js.map +1 -0
  10. package/src/lib/array/array-copy-deep.d.ts +6 -0
  11. package/src/lib/array/array-copy-deep.js +25 -0
  12. package/src/lib/array/array-copy-deep.js.map +1 -0
  13. package/src/lib/array/array-copy-shallow.d.ts +19 -0
  14. package/src/lib/array/array-copy-shallow.js +20 -0
  15. package/src/lib/array/array-copy-shallow.js.map +1 -0
  16. package/src/lib/array/array-from-length.d.ts +18 -0
  17. package/src/lib/array/array-from-length.js +23 -0
  18. package/src/lib/array/array-from-length.js.map +1 -0
  19. package/src/lib/array/array-from.d.ts +24 -0
  20. package/src/lib/array/array-from.js +26 -0
  21. package/src/lib/array/array-from.js.map +1 -0
  22. package/src/lib/array/array-move-at-index.d.ts +24 -0
  23. package/src/lib/array/array-move-at-index.js +32 -0
  24. package/src/lib/array/array-move-at-index.js.map +1 -0
  25. package/src/lib/array/array-of-entries-to-object.d.ts +23 -0
  26. package/src/lib/array/array-of-entries-to-object.js +26 -0
  27. package/src/lib/array/array-of-entries-to-object.js.map +1 -0
  28. package/src/lib/array/array-overrides.d.ts +29 -0
  29. package/src/lib/array/array-overrides.js +71 -0
  30. package/src/lib/array/array-overrides.js.map +1 -0
  31. package/src/lib/array/array-push-at-index.d.ts +28 -0
  32. package/src/lib/array/array-push-at-index.js +32 -0
  33. package/src/lib/array/array-push-at-index.js.map +1 -0
  34. package/src/lib/array/array-remove-at-index.d.ts +23 -0
  35. package/src/lib/array/array-remove-at-index.js +26 -0
  36. package/src/lib/array/array-remove-at-index.js.map +1 -0
  37. package/src/lib/array/array-remove-item.d.ts +23 -0
  38. package/src/lib/array/array-remove-item.js +27 -0
  39. package/src/lib/array/array-remove-item.js.map +1 -0
  40. package/src/lib/array/array-safe.d.ts +21 -0
  41. package/src/lib/array/array-safe.js +29 -0
  42. package/src/lib/array/array-safe.js.map +1 -0
  43. package/src/lib/array/array-sort-by-deep-property.d.ts +26 -0
  44. package/src/lib/array/array-sort-by-deep-property.js +39 -0
  45. package/src/lib/array/array-sort-by-deep-property.js.map +1 -0
  46. package/src/lib/array/array-sort-by.d.ts +26 -0
  47. package/src/lib/array/array-sort-by.js +36 -0
  48. package/src/lib/array/array-sort-by.js.map +1 -0
  49. package/src/lib/array/array-update-at-index.d.ts +18 -0
  50. package/src/lib/array/array-update-at-index.js +22 -0
  51. package/src/lib/array/array-update-at-index.js.map +1 -0
  52. package/src/lib/array/array-update.d.ts +23 -0
  53. package/src/lib/array/array-update.js +25 -0
  54. package/src/lib/array/array-update.js.map +1 -0
  55. package/src/lib/bitwise/bitwise-has-all-attributes.d.ts +18 -0
  56. package/src/lib/bitwise/bitwise-has-all-attributes.js +21 -0
  57. package/src/lib/bitwise/bitwise-has-all-attributes.js.map +1 -0
  58. package/src/lib/bitwise/bitwise-has-attribute.d.ts +18 -0
  59. package/src/lib/bitwise/bitwise-has-attribute.js +21 -0
  60. package/src/lib/bitwise/bitwise-has-attribute.js.map +1 -0
  61. package/src/lib/bitwise/bitwise-has-only-attributes.d.ts +18 -0
  62. package/src/lib/bitwise/bitwise-has-only-attributes.js +21 -0
  63. package/src/lib/bitwise/bitwise-has-only-attributes.js.map +1 -0
  64. package/src/lib/contrast.d.ts +65 -0
  65. package/src/lib/contrast.js +78 -0
  66. package/src/lib/contrast.js.map +1 -0
  67. package/src/lib/copy-shallow.d.ts +19 -0
  68. package/src/lib/copy-shallow.js +20 -0
  69. package/src/lib/copy-shallow.js.map +1 -0
  70. package/src/lib/copy.d.ts +19 -0
  71. package/src/lib/copy.js +20 -0
  72. package/src/lib/copy.js.map +1 -0
  73. package/src/lib/create-chained-function.d.ts +38 -0
  74. package/src/lib/create-chained-function.js +46 -0
  75. package/src/lib/create-chained-function.js.map +1 -0
  76. package/src/lib/crud.d.ts +46 -0
  77. package/src/lib/crud.js +55 -0
  78. package/src/lib/crud.js.map +1 -0
  79. package/src/lib/css.d.ts +41 -0
  80. package/src/lib/css.js +54 -0
  81. package/src/lib/css.js.map +1 -0
  82. package/src/lib/escape-html.d.ts +38 -0
  83. package/src/lib/escape-html.js +47 -0
  84. package/src/lib/escape-html.js.map +1 -0
  85. package/src/lib/falsy.d.ts +23 -0
  86. package/src/lib/falsy.js +25 -0
  87. package/src/lib/falsy.js.map +1 -0
  88. package/src/lib/get-display-name.d.ts +46 -0
  89. package/src/lib/get-display-name.js +64 -0
  90. package/src/lib/get-display-name.js.map +1 -0
  91. package/src/lib/get-property.d.ts +30 -0
  92. package/src/lib/get-property.js +36 -0
  93. package/src/lib/get-property.js.map +1 -0
  94. package/src/lib/get-static-field.d.ts +23 -0
  95. package/src/lib/get-static-field.js +25 -0
  96. package/src/lib/get-static-field.js.map +1 -0
  97. package/src/lib/guards/index.d.ts +46 -0
  98. package/src/lib/guards/index.js +47 -0
  99. package/src/lib/guards/index.js.map +1 -0
  100. package/src/lib/guards/lib/_has-own-property.d.ts +24 -0
  101. package/src/lib/guards/lib/_has-own-property.js +27 -0
  102. package/src/lib/guards/lib/_has-own-property.js.map +1 -0
  103. package/src/lib/guards/lib/_is-arr-empty.d.ts +23 -0
  104. package/src/lib/guards/lib/_is-arr-empty.js +25 -0
  105. package/src/lib/guards/lib/_is-arr-empty.js.map +1 -0
  106. package/src/lib/guards/lib/_is-arr-of-arr.d.ts +25 -0
  107. package/src/lib/guards/lib/_is-arr-of-arr.js +31 -0
  108. package/src/lib/guards/lib/_is-arr-of-arr.js.map +1 -0
  109. package/src/lib/guards/lib/_is-arr.d.ts +21 -0
  110. package/src/lib/guards/lib/_is-arr.js +23 -0
  111. package/src/lib/guards/lib/_is-arr.js.map +1 -0
  112. package/src/lib/guards/lib/_is-big.d.ts +25 -0
  113. package/src/lib/guards/lib/_is-big.js +27 -0
  114. package/src/lib/guards/lib/_is-big.js.map +1 -0
  115. package/src/lib/guards/lib/_is-bool.d.ts +25 -0
  116. package/src/lib/guards/lib/_is-bool.js +27 -0
  117. package/src/lib/guards/lib/_is-bool.js.map +1 -0
  118. package/src/lib/guards/lib/_is-buff.d.ts +25 -0
  119. package/src/lib/guards/lib/_is-buff.js +29 -0
  120. package/src/lib/guards/lib/_is-buff.js.map +1 -0
  121. package/src/lib/guards/lib/_is-ctor.d.ts +25 -0
  122. package/src/lib/guards/lib/_is-ctor.js +30 -0
  123. package/src/lib/guards/lib/_is-ctor.js.map +1 -0
  124. package/src/lib/guards/lib/_is-empty-str-or-arr.d.ts +25 -0
  125. package/src/lib/guards/lib/_is-empty-str-or-arr.js +29 -0
  126. package/src/lib/guards/lib/_is-empty-str-or-arr.js.map +1 -0
  127. package/src/lib/guards/lib/_is-equality-same-type.d.ts +25 -0
  128. package/src/lib/guards/lib/_is-equality-same-type.js +33 -0
  129. package/src/lib/guards/lib/_is-equality-same-type.js.map +1 -0
  130. package/src/lib/guards/lib/_is-fn-t.d.ts +25 -0
  131. package/src/lib/guards/lib/_is-fn-t.js +27 -0
  132. package/src/lib/guards/lib/_is-fn-t.js.map +1 -0
  133. package/src/lib/guards/lib/_is-length-of.d.ts +47 -0
  134. package/src/lib/guards/lib/_is-length-of.js +49 -0
  135. package/src/lib/guards/lib/_is-length-of.js.map +1 -0
  136. package/src/lib/guards/lib/_is-length.d.ts +25 -0
  137. package/src/lib/guards/lib/_is-length.js +34 -0
  138. package/src/lib/guards/lib/_is-length.js.map +1 -0
  139. package/src/lib/guards/lib/_is-null.d.ts +25 -0
  140. package/src/lib/guards/lib/_is-null.js +27 -0
  141. package/src/lib/guards/lib/_is-null.js.map +1 -0
  142. package/src/lib/guards/lib/_is-num-neg.d.ts +25 -0
  143. package/src/lib/guards/lib/_is-num-neg.js +28 -0
  144. package/src/lib/guards/lib/_is-num-neg.js.map +1 -0
  145. package/src/lib/guards/lib/_is-num-pos.d.ts +25 -0
  146. package/src/lib/guards/lib/_is-num-pos.js +28 -0
  147. package/src/lib/guards/lib/_is-num-pos.js.map +1 -0
  148. package/src/lib/guards/lib/_is-num-t.d.ts +25 -0
  149. package/src/lib/guards/lib/_is-num-t.js +27 -0
  150. package/src/lib/guards/lib/_is-num-t.js.map +1 -0
  151. package/src/lib/guards/lib/_is-num-zero.d.ts +25 -0
  152. package/src/lib/guards/lib/_is-num-zero.js +28 -0
  153. package/src/lib/guards/lib/_is-num-zero.js.map +1 -0
  154. package/src/lib/guards/lib/_is-num.d.ts +26 -0
  155. package/src/lib/guards/lib/_is-num.js +29 -0
  156. package/src/lib/guards/lib/_is-num.js.map +1 -0
  157. package/src/lib/guards/lib/_is-obj-t.d.ts +26 -0
  158. package/src/lib/guards/lib/_is-obj-t.js +28 -0
  159. package/src/lib/guards/lib/_is-obj-t.js.map +1 -0
  160. package/src/lib/guards/lib/_is-obj.d.ts +27 -0
  161. package/src/lib/guards/lib/_is-obj.js +32 -0
  162. package/src/lib/guards/lib/_is-obj.js.map +1 -0
  163. package/src/lib/guards/lib/_is-prim.d.ts +27 -0
  164. package/src/lib/guards/lib/_is-prim.js +35 -0
  165. package/src/lib/guards/lib/_is-prim.js.map +1 -0
  166. package/src/lib/guards/lib/_is-promise-like.d.ts +24 -0
  167. package/src/lib/guards/lib/_is-promise-like.js +28 -0
  168. package/src/lib/guards/lib/_is-promise-like.js.map +1 -0
  169. package/src/lib/guards/lib/_is-str-empty.d.ts +25 -0
  170. package/src/lib/guards/lib/_is-str-empty.js +28 -0
  171. package/src/lib/guards/lib/_is-str-empty.js.map +1 -0
  172. package/src/lib/guards/lib/_is-str-t.d.ts +26 -0
  173. package/src/lib/guards/lib/_is-str-t.js +28 -0
  174. package/src/lib/guards/lib/_is-str-t.js.map +1 -0
  175. package/src/lib/guards/lib/_is-sym-t.d.ts +25 -0
  176. package/src/lib/guards/lib/_is-sym-t.js +27 -0
  177. package/src/lib/guards/lib/_is-sym-t.js.map +1 -0
  178. package/src/lib/guards/lib/_is-und-or-null.d.ts +25 -0
  179. package/src/lib/guards/lib/_is-und-or-null.js +29 -0
  180. package/src/lib/guards/lib/_is-und-or-null.js.map +1 -0
  181. package/src/lib/guards/lib/_is-und-t.d.ts +25 -0
  182. package/src/lib/guards/lib/_is-und-t.js +27 -0
  183. package/src/lib/guards/lib/_is-und-t.js.map +1 -0
  184. package/src/lib/interop-default.d.ts +18 -0
  185. package/src/lib/interop-default.js +21 -0
  186. package/src/lib/interop-default.js.map +1 -0
  187. package/src/lib/length.d.ts +22 -0
  188. package/src/lib/length.js +28 -0
  189. package/src/lib/length.js.map +1 -0
  190. package/src/lib/linear-regex.d.ts +136 -0
  191. package/src/lib/linear-regex.js +1140 -0
  192. package/src/lib/linear-regex.js.map +1 -0
  193. package/src/lib/no-side-effects.d.ts +29 -0
  194. package/src/lib/no-side-effects.js +33 -0
  195. package/src/lib/no-side-effects.js.map +1 -0
  196. package/src/lib/noop.d.ts +21 -0
  197. package/src/lib/noop.js +22 -0
  198. package/src/lib/noop.js.map +1 -0
  199. package/src/lib/normalized.d.ts +164 -0
  200. package/src/lib/normalized.js +232 -0
  201. package/src/lib/normalized.js.map +1 -0
  202. package/src/lib/number/number-from-hexadecimal.d.ts +24 -0
  203. package/src/lib/number/number-from-hexadecimal.js +29 -0
  204. package/src/lib/number/number-from-hexadecimal.js.map +1 -0
  205. package/src/lib/number/number-to-hexadecimal.d.ts +22 -0
  206. package/src/lib/number/number-to-hexadecimal.js +24 -0
  207. package/src/lib/number/number-to-hexadecimal.js.map +1 -0
  208. package/src/lib/number/to-num.d.ts +41 -0
  209. package/src/lib/number/to-num.js +41 -0
  210. package/src/lib/number/to-num.js.map +1 -0
  211. package/src/lib/numeronym.d.ts +41 -0
  212. package/src/lib/numeronym.js +54 -0
  213. package/src/lib/numeronym.js.map +1 -0
  214. package/src/lib/object/object-clone-deep.d.ts +21 -0
  215. package/src/lib/object/object-clone-deep.js +24 -0
  216. package/src/lib/object/object-clone-deep.js.map +1 -0
  217. package/src/lib/object/object-clone.d.ts +21 -0
  218. package/src/lib/object/object-clone.js +24 -0
  219. package/src/lib/object/object-clone.js.map +1 -0
  220. package/src/lib/object/object-delete-property.d.ts +28 -0
  221. package/src/lib/object/object-delete-property.js +32 -0
  222. package/src/lib/object/object-delete-property.js.map +1 -0
  223. package/src/lib/object/object-get-deep-property.d.ts +35 -0
  224. package/src/lib/object/object-get-deep-property.js +40 -0
  225. package/src/lib/object/object-get-deep-property.js.map +1 -0
  226. package/src/lib/object/object-get-keys-and-symbol-properties.d.ts +23 -0
  227. package/src/lib/object/object-get-keys-and-symbol-properties.js +30 -0
  228. package/src/lib/object/object-get-keys-and-symbol-properties.js.map +1 -0
  229. package/src/lib/object/object-remap.d.ts +33 -0
  230. package/src/lib/object/object-remap.js +36 -0
  231. package/src/lib/object/object-remap.js.map +1 -0
  232. package/src/lib/object/object-safe.d.ts +27 -0
  233. package/src/lib/object/object-safe.js +30 -0
  234. package/src/lib/object/object-safe.js.map +1 -0
  235. package/src/lib/object/object-set-deep-property.d.ts +35 -0
  236. package/src/lib/object/object-set-deep-property.js +44 -0
  237. package/src/lib/object/object-set-deep-property.js.map +1 -0
  238. package/src/lib/object/object-update.d.ts +28 -0
  239. package/src/lib/object/object-update.js +32 -0
  240. package/src/lib/object/object-update.js.map +1 -0
  241. package/src/lib/operator/compare.d.ts +26 -0
  242. package/src/lib/operator/compare.js +42 -0
  243. package/src/lib/operator/compare.js.map +1 -0
  244. package/src/lib/operator/definitions.d.ts +184 -0
  245. package/src/lib/operator/definitions.js +110 -0
  246. package/src/lib/operator/definitions.js.map +1 -0
  247. package/src/lib/operator/index.d.ts +19 -0
  248. package/src/lib/operator/index.js +20 -0
  249. package/src/lib/operator/index.js.map +1 -0
  250. package/src/lib/operator/inference.d.ts +66 -0
  251. package/src/lib/operator/inference.js +60 -0
  252. package/src/lib/operator/inference.js.map +1 -0
  253. package/src/lib/secret-box.d.ts +152 -0
  254. package/src/lib/secret-box.js +263 -0
  255. package/src/lib/secret-box.js.map +1 -0
  256. package/src/lib/serialize/base64-isomorphic-decode.d.ts +23 -0
  257. package/src/lib/serialize/base64-isomorphic-decode.js +28 -0
  258. package/src/lib/serialize/base64-isomorphic-decode.js.map +1 -0
  259. package/src/lib/serialize/base64-isomorphic-encode.d.ts +23 -0
  260. package/src/lib/serialize/base64-isomorphic-encode.js +28 -0
  261. package/src/lib/serialize/base64-isomorphic-encode.js.map +1 -0
  262. package/src/lib/serialize/json-deserialize.d.ts +25 -0
  263. package/src/lib/serialize/json-deserialize.js +27 -0
  264. package/src/lib/serialize/json-deserialize.js.map +1 -0
  265. package/src/lib/serialize/json-serialize.d.ts +25 -0
  266. package/src/lib/serialize/json-serialize.js +27 -0
  267. package/src/lib/serialize/json-serialize.js.map +1 -0
  268. package/src/lib/serialize/php-serial-deserialize-from-byte-stream.d.ts +77 -0
  269. package/src/lib/serialize/php-serial-deserialize-from-byte-stream.js +77 -0
  270. package/src/lib/serialize/php-serial-deserialize-from-byte-stream.js.map +1 -0
  271. package/src/lib/serialize/php-serial-is-serialized-byte-stream.d.ts +77 -0
  272. package/src/lib/serialize/php-serial-is-serialized-byte-stream.js +77 -0
  273. package/src/lib/serialize/php-serial-is-serialized-byte-stream.js.map +1 -0
  274. package/src/lib/serialize/php-serial-serialize-to-byte-stream.d.ts +77 -0
  275. package/src/lib/serialize/php-serial-serialize-to-byte-stream.js +77 -0
  276. package/src/lib/serialize/php-serial-serialize-to-byte-stream.js.map +1 -0
  277. package/src/lib/split-display-name.d.ts +36 -0
  278. package/src/lib/split-display-name.js +47 -0
  279. package/src/lib/split-display-name.js.map +1 -0
  280. package/src/lib/str.d.ts +21 -0
  281. package/src/lib/str.js +23 -0
  282. package/src/lib/str.js.map +1 -0
  283. package/src/lib/trim.d.ts +25 -0
  284. package/src/lib/trim.js +28 -0
  285. package/src/lib/trim.js.map +1 -0
  286. package/src/lib/truthy.d.ts +23 -0
  287. package/src/lib/truthy.js +30 -0
  288. package/src/lib/truthy.js.map +1 -0
@@ -0,0 +1,232 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ // eslint-disable-next-line @nx/enforce-module-boundaries
17
+ import { _ as _extends } from "@swc/helpers/_/_extends";
18
+ import { arrayMoveAtIndex } from "./array/array-move-at-index.js";
19
+ import { arrayRemoveItem } from "./array/array-remove-item.js";
20
+ import { _isNum, _isObj } from "./guards/index.js";
21
+ import { objectDeleteProperty } from "./object/object-delete-property.js";
22
+ /**
23
+ * Normalized data for 3NF
24
+ *
25
+ * @export
26
+ * @abstract
27
+ * @class Normalized
28
+ * @extends {NormalizedData<T, K>}
29
+ * @template T
30
+ * @template K
31
+ * @see https://en.wikipedia.org/wiki/Third_normal_form
32
+ */ export class Normalized {
33
+ static build() {
34
+ return {
35
+ ids: [],
36
+ byId: {}
37
+ };
38
+ }
39
+ get length() {
40
+ var _this_ids;
41
+ return ((_this_ids = this.ids) != null ? _this_ids : []).length;
42
+ }
43
+ /**
44
+ * Maps the ids/keys to their respective values in byId
45
+ *
46
+ * @static
47
+ * @template T
48
+ * @template V
49
+ * @param {T} v
50
+ * @returns {V[]}
51
+ * @memberof Normalized
52
+ */ static toArray(v) {
53
+ return Array.from(v.ids).map((id)=>v.byId[id]);
54
+ }
55
+ /**
56
+ * Resets the keys/ids and values/byId back to empty
57
+ *
58
+ * @static
59
+ * @param {NormalizedData} v
60
+ * @returns {NormalizedData}
61
+ * @memberof Normalized
62
+ */ static clear(v) {
63
+ v.ids = [];
64
+ v.byId = {};
65
+ return v;
66
+ }
67
+ /**
68
+ * Clears all values
69
+ * @returns {this}
70
+ * @memberof Normalized
71
+ */ clear() {
72
+ return Normalized.clear(this);
73
+ }
74
+ /**
75
+ * Create a new class instance from the provided params
76
+ *
77
+ * @static
78
+ * @template T
79
+ * @template K
80
+ * @param {(...T[] | [id: K, value: any][])} items
81
+ * @returns {NormalizedModel<T>}
82
+ * @memberof Normalized
83
+ */ static from(...items) {
84
+ const _items = [
85
+ ...items
86
+ ].map((i)=>_isObj(i) ? [
87
+ i['id'],
88
+ i
89
+ ] : [
90
+ ...i
91
+ ]);
92
+ const parsed = _items.reduce((acc, [id, v])=>{
93
+ var _ref;
94
+ return {
95
+ ids: ((_ref = acc == null ? void 0 : acc.ids) != null ? _ref : []).concat(id),
96
+ byId: _extends({}, acc == null ? void 0 : acc.byId, {
97
+ [id]: v
98
+ })
99
+ };
100
+ }, {
101
+ ids: [],
102
+ byId: {}
103
+ });
104
+ return new this(parsed);
105
+ }
106
+ /**
107
+ * Removes an item from an existing key value data structure object
108
+ *
109
+ * @static
110
+ * @template T
111
+ * @param {ID} id
112
+ * @param {NormalizedData<T>} model
113
+ * @returns {NormalizedData<T>}
114
+ * @memberof Normalized
115
+ */ static remove(id, model) {
116
+ model.ids = arrayRemoveItem(model.ids, id);
117
+ model.byId = objectDeleteProperty(model.byId, id);
118
+ return model;
119
+ }
120
+ /**
121
+ * Sets an item in an existing denormalized key value object.
122
+ *
123
+ * @static
124
+ * @template T
125
+ * @template V
126
+ * @template K
127
+ * @param {[id: K, value: V]} item
128
+ * @param {T} model
129
+ * @param {number} [index]
130
+ * @returns {T}
131
+ * @memberof Normalized
132
+ */ static set(item, model, index) {
133
+ const [id, value] = item;
134
+ const currentIndex = model.ids.indexOf(id);
135
+ const isUpdate = currentIndex !== -1;
136
+ model.byId[id] = value;
137
+ if (!isUpdate) {
138
+ model.ids.push(id);
139
+ } else if (_isNum(index) && currentIndex !== index) {
140
+ model.ids = arrayMoveAtIndex(model.ids, currentIndex, index);
141
+ }
142
+ return model;
143
+ }
144
+ /**
145
+ * Get a property from the key value. shortens call such as model.byId[foo]
146
+ *
147
+ * @static
148
+ * @template T
149
+ * @param {ID} id
150
+ * @param {NormalizedData<T>} model
151
+ * @returns {(undefined | T)}
152
+ * @memberof Normalized
153
+ */ static get(id, model) {
154
+ var _model_byId_id;
155
+ return (_model_byId_id = model.byId[id]) != null ? _model_byId_id : null;
156
+ }
157
+ /**
158
+ * The properties to keep when object is passed to JSON.stringify(...)
159
+ * @returns {NormalizedData<T, K>}
160
+ * @memberof Normalized
161
+ */ toJSON() {
162
+ return {
163
+ ids: this.ids,
164
+ byId: this.byId
165
+ };
166
+ }
167
+ /**
168
+ * Converts the current values into an array ordered by the
169
+ * appearance of the key in ids array
170
+ * @returns {Array<T>}
171
+ * @memberof Normalized
172
+ */ toArray() {
173
+ return Normalized.toArray(this);
174
+ }
175
+ /**
176
+ * Aliases the static method to shortcut delete operations on this instance
177
+ *
178
+ * @param {K} id
179
+ * @returns {this}
180
+ * @memberof Normalized
181
+ */ remove(id) {
182
+ Normalized.remove(id, this);
183
+ return this;
184
+ }
185
+ /**
186
+ * Returns whether or not the model byId has property key/id
187
+ *
188
+ * @param {ID} id
189
+ * @returns {boolean}
190
+ * @memberof Normalized
191
+ */ has(id) {
192
+ return this.hasOwnProperty.call(this.byId, id);
193
+ }
194
+ /**
195
+ * Aliases the static method to shortcut set operations on this instance
196
+ *
197
+ * @param {ID} id
198
+ * @param {*} [value]
199
+ * @param {number} [index]
200
+ * @returns {this}
201
+ * @memberof Normalized
202
+ */ set(id, value, index) {
203
+ return Normalized.set([
204
+ id,
205
+ value
206
+ ], this, index);
207
+ }
208
+ /**
209
+ * Shortcuts getting the value of properties of the current instance
210
+ *
211
+ * @param {ID} id
212
+ * @returns {(undefined | T)}
213
+ * @memberof Normalized
214
+ */ get(id) {
215
+ return Normalized.get(id, this);
216
+ }
217
+ /** @ignore */ get hasOwnProperty() {
218
+ return Object.prototype.hasOwnProperty;
219
+ }
220
+ constructor(props){
221
+ this.props = props;
222
+ this.ids = [];
223
+ this.byId = {};
224
+ const { ids, byId } = _extends({}, props);
225
+ this.ids = [
226
+ ...ids != null ? ids : []
227
+ ];
228
+ this.byId = _extends({}, byId);
229
+ }
230
+ }
231
+
232
+ //# sourceMappingURL=normalized.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/tools/src/lib/normalized.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// eslint-disable-next-line @nx/enforce-module-boundaries\nimport { NormalizedData, NormalizedModel } from '@aglyn/shared-data-types'\nimport { arrayMoveAtIndex } from './array/array-move-at-index'\nimport { arrayRemoveItem } from './array/array-remove-item'\nimport { _isNum, _isObj } from './guards'\nimport { objectDeleteProperty } from './object/object-delete-property'\n\n\ntype ID = string\n\n/**\n * Normalized data for 3NF\n *\n * @export\n * @abstract\n * @class Normalized\n * @extends {NormalizedData<T, K>}\n * @template T\n * @template K\n * @see https://en.wikipedia.org/wiki/Third_normal_form\n */\nexport class Normalized<T = any, K extends ID = ID>\n implements NormalizedModel<T, K>\n{\n static build<T, K extends ID>(): NormalizedData<T, K> {\n return { ids: [], byId: {} }\n }\n\n public ids: K[] = []\n public byId: { [P in K]?: T } = {}\n\n public get length(): number {\n return (this.ids ?? []).length\n }\n\n constructor(public readonly props?: NormalizedData<T, K>) {\n const { ids, byId } = { ...props }\n this.ids = [...(ids ?? [])]\n this.byId = { ...byId }\n }\n\n /**\n * Maps the ids/keys to their respective values in byId\n *\n * @static\n * @template T\n * @template V\n * @param {T} v\n * @returns {V[]}\n * @memberof Normalized\n */\n public static toArray<T extends NormalizedData<V>, V>(v: T): V[] {\n return Array.from(v.ids).map((id) => v.byId[id])\n }\n\n /**\n * Resets the keys/ids and values/byId back to empty\n *\n * @static\n * @param {NormalizedData} v\n * @returns {NormalizedData}\n * @memberof Normalized\n */\n public static clear<T extends NormalizedData<any>>(v: T): T {\n v.ids = []\n v.byId = {}\n return v\n }\n\n /**\n * Clears all values\n * @returns {this}\n * @memberof Normalized\n */\n public clear(): this {\n return Normalized.clear(this)\n }\n\n /**\n * Create a new class instance from the provided params\n *\n * @static\n * @template T\n * @template K\n * @param {(...T[] | [id: K, value: any][])} items\n * @returns {NormalizedModel<T>}\n * @memberof Normalized\n */\n public static from<T extends { id: ID }, K extends ID>(\n ...items: T[] | [id: K, value: any][]\n ): NormalizedModel<T> {\n const _items = [...items].map((i) => (_isObj(i) ? [i['id'], i] : [...i]))\n const parsed = _items.reduce<NormalizedData<T, K>>(\n (acc, [id, v]) => ({\n ids: (acc?.ids ?? []).concat(id),\n byId: { ...acc?.byId, [id]: v },\n }),\n { ids: [], byId: {} },\n )\n return new this(parsed)\n }\n\n /**\n * Removes an item from an existing key value data structure object\n *\n * @static\n * @template T\n * @param {ID} id\n * @param {NormalizedData<T>} model\n * @returns {NormalizedData<T>}\n * @memberof Normalized\n */\n public static remove<\n T extends NormalizedData<TT, any>,\n K extends ID,\n TT = any,\n >(id: K, model: T): NormalizedData<TT, ID> {\n model.ids = arrayRemoveItem(model.ids, id)\n model.byId = objectDeleteProperty(model.byId, id)\n return model\n }\n\n /**\n * Sets an item in an existing denormalized key value object.\n *\n * @static\n * @template T\n * @template V\n * @template K\n * @param {[id: K, value: V]} item\n * @param {T} model\n * @param {number} [index]\n * @returns {T}\n * @memberof Normalized\n */\n public static set<T extends NormalizedData<V, K>, V, K extends ID>(\n item: [id: K, value: V],\n model: T,\n index?: number,\n ): T {\n const [id, value] = item\n const currentIndex = model.ids.indexOf(id)\n const isUpdate = currentIndex !== -1\n\n model.byId[id] = value\n\n if (!isUpdate) {\n model.ids.push(id)\n } else if (_isNum(index) && currentIndex !== index) {\n model.ids = arrayMoveAtIndex(model.ids, currentIndex, index)\n }\n\n return model\n }\n\n /**\n * Get a property from the key value. shortens call such as model.byId[foo]\n *\n * @static\n * @template T\n * @param {ID} id\n * @param {NormalizedData<T>} model\n * @returns {(undefined | T)}\n * @memberof Normalized\n */\n public static get<T extends NormalizedData<V, K>, K extends ID, V>(\n id: K,\n model: T,\n ): V | null {\n return model.byId[id] ?? null\n }\n\n /**\n * The properties to keep when object is passed to JSON.stringify(...)\n * @returns {NormalizedData<T, K>}\n * @memberof Normalized\n */\n public toJSON(): NormalizedData<T, K> {\n return { ids: this.ids, byId: this.byId }\n }\n\n /**\n * Converts the current values into an array ordered by the\n * appearance of the key in ids array\n * @returns {Array<T>}\n * @memberof Normalized\n */\n public toArray(): Array<T> {\n return Normalized.toArray(this)\n }\n\n /**\n * Aliases the static method to shortcut delete operations on this instance\n *\n * @param {K} id\n * @returns {this}\n * @memberof Normalized\n */\n public remove(id: K): this {\n Normalized.remove(id, this)\n return this\n }\n\n /**\n * Returns whether or not the model byId has property key/id\n *\n * @param {ID} id\n * @returns {boolean}\n * @memberof Normalized\n */\n public has(id: ID): boolean {\n return this.hasOwnProperty.call(this.byId, id)\n }\n\n /**\n * Aliases the static method to shortcut set operations on this instance\n *\n * @param {ID} id\n * @param {*} [value]\n * @param {number} [index]\n * @returns {this}\n * @memberof Normalized\n */\n public set(id: ID, value?: T, index?: number): this {\n return Normalized.set([id, value], this, index)\n }\n\n /**\n * Shortcuts getting the value of properties of the current instance\n *\n * @param {ID} id\n * @returns {(undefined | T)}\n * @memberof Normalized\n */\n public get(id: ID): undefined | T {\n return Normalized.get(id, this)\n }\n\n /** @ignore */\n private get hasOwnProperty() {\n return Object.prototype.hasOwnProperty\n }\n}\n"],"names":["arrayMoveAtIndex","arrayRemoveItem","_isNum","_isObj","objectDeleteProperty","Normalized","build","ids","byId","length","toArray","v","Array","from","map","id","clear","items","_items","i","parsed","reduce","acc","concat","remove","model","set","item","index","value","currentIndex","indexOf","isUpdate","push","get","toJSON","has","hasOwnProperty","call","Object","prototype","props"],"mappings":"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"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Convert Base16/Hexadecimal string to its decimal/number equivalent
19
+ *
20
+ * @param hex - 8-bit hexadecimal string
21
+ * @returns the hexadecimal as a number
22
+ */
23
+ export declare function numberFromHexadecimal(hex: string): number;
24
+ export default numberFromHexadecimal;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { toNum } from "./to-num.js";
17
+ /**
18
+ * Convert Base16/Hexadecimal string to its decimal/number equivalent
19
+ *
20
+ * @param hex - 8-bit hexadecimal string
21
+ * @returns the hexadecimal as a number
22
+ */ export function numberFromHexadecimal(hex) {
23
+ return toNum(hex, {
24
+ radix: 16
25
+ });
26
+ }
27
+ export default numberFromHexadecimal;
28
+
29
+ //# sourceMappingURL=number-from-hexadecimal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/util/tools/src/lib/number/number-from-hexadecimal.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {toNum} from './to-num'\n\n\n/**\n * Convert Base16/Hexadecimal string to its decimal/number equivalent\n *\n * @param hex - 8-bit hexadecimal string\n * @returns the hexadecimal as a number\n */\nexport function numberFromHexadecimal(hex: string): number {\n return toNum(hex, {radix: 16})\n}\nexport default numberFromHexadecimal\n"],"names":["toNum","numberFromHexadecimal","hex","radix"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAAQA,KAAK,QAAO,cAAU;AAG9B;;;;;CAKC,GACD,OAAO,SAASC,sBAAsBC,GAAW;IAC/C,OAAOF,MAAME,KAAK;QAACC,OAAO;IAAE;AAC9B;AACA,eAAeF,sBAAqB"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Convert any value to 8-bit hexadecimal string
19
+ * @param val - value to convert
20
+ */
21
+ export declare function numberToHexadecimal<T>(val: T): string;
22
+ export default numberToHexadecimal;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ /**
17
+ * Convert any value to 8-bit hexadecimal string
18
+ * @param val - value to convert
19
+ */ export function numberToHexadecimal(val) {
20
+ return Number(val).toString(16);
21
+ }
22
+ export default numberToHexadecimal;
23
+
24
+ //# sourceMappingURL=number-to-hexadecimal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/util/tools/src/lib/number/number-to-hexadecimal.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Convert any value to 8-bit hexadecimal string\n * @param val - value to convert\n */\nexport function numberToHexadecimal<T>(val: T): string {\n return Number(val).toString(16)\n}\nexport default numberToHexadecimal\n"],"names":["numberToHexadecimal","val","Number","toString"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;CAGC,GACD,OAAO,SAASA,oBAAuBC,GAAM;IAC3C,OAAOC,OAAOD,KAAKE,QAAQ,CAAC;AAC9B;AACA,eAAeH,oBAAmB"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ type ToNumType = 'int' | 'float' | 'eval';
18
+ type ToNumResult<T extends ToNumType = never> = ConditionalNonDist<T, 'eval', any, number>;
19
+ export type ToNumOptions<T extends ToNumType = never, N = 0> = {
20
+ onNaN?: N;
21
+ type?: 'int';
22
+ radix?: number;
23
+ } | {
24
+ onNaN?: N;
25
+ type?: T;
26
+ radix?: never;
27
+ };
28
+ /**
29
+ * Ensure and parse any value to a number.
30
+ *
31
+ * - If radix, `{type: 'int'}` is provided will use {@link parseInt}
32
+ * - If `{type: 'parse'}` is provided will use {@link parseFloat}
33
+ * - If `{type: 'eval'}` is provided will use {@link eval} and {@link Number}
34
+ * - Otherwise uses {@link Number|Number(val)}
35
+ * - If parsing results in NaN will return {@link onNaN}.
36
+ *
37
+ * @param val - the value to parse into a number
38
+ * @param options - override default parsing behavior
39
+ */
40
+ export declare function toNum<T extends ToNumType, N = 0>(val: string | any, options?: ToNumOptions<T, N>): ToNumResult<T> | N;
41
+ export {};
@@ -0,0 +1,41 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2023 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ import { _isNumT } from "../guards/lib/_is-num-t.js";
18
+ /**
19
+ * Ensure and parse any value to a number.
20
+ *
21
+ * - If radix, `{type: 'int'}` is provided will use {@link parseInt}
22
+ * - If `{type: 'parse'}` is provided will use {@link parseFloat}
23
+ * - If `{type: 'eval'}` is provided will use {@link eval} and {@link Number}
24
+ * - Otherwise uses {@link Number|Number(val)}
25
+ * - If parsing results in NaN will return {@link onNaN}.
26
+ *
27
+ * @param val - the value to parse into a number
28
+ * @param options - override default parsing behavior
29
+ */ export function toNum(val, options) {
30
+ const { type, onNaN, radix } = _extends({}, options);
31
+ let parsed = NaN;
32
+ if (_isNumT(radix)) parsed = parseInt(val, radix);
33
+ else if (type === 'int') parsed = parseInt(val);
34
+ else if (type === 'float') parsed = parseFloat(val);
35
+ else if (type === 'eval') parsed = Number(eval(val));
36
+ else if (!type) parsed = Number(val);
37
+ if (isNaN(parsed)) parsed = onNaN != null ? onNaN : 0;
38
+ return parsed;
39
+ }
40
+
41
+ //# sourceMappingURL=to-num.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/util/tools/src/lib/number/to-num.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2023 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { _isNumT } from '../guards/lib/_is-num-t'\n\ntype ToNumType = 'int' | 'float' | 'eval'\ntype ToNumResult<T extends ToNumType = never> = ConditionalNonDist<\n T,\n 'eval',\n any,\n number\n>\n\nexport type ToNumOptions<T extends ToNumType = never, N = 0> =\n | { onNaN?: N; type?: 'int'; radix?: number }\n | { onNaN?: N; type?: T; radix?: never }\n\n/**\n * Ensure and parse any value to a number.\n *\n * - If radix, `{type: 'int'}` is provided will use {@link parseInt}\n * - If `{type: 'parse'}` is provided will use {@link parseFloat}\n * - If `{type: 'eval'}` is provided will use {@link eval} and {@link Number}\n * - Otherwise uses {@link Number|Number(val)}\n * - If parsing results in NaN will return {@link onNaN}.\n *\n * @param val - the value to parse into a number\n * @param options - override default parsing behavior\n */\nexport function toNum<T extends ToNumType, N = 0>(\n val: string | any,\n options?: ToNumOptions<T, N>,\n): ToNumResult<T> | N {\n const { type, onNaN, radix } = { ...options }\n let parsed: ToNumResult<T> | N = NaN\n\n if (_isNumT(radix)) parsed = parseInt(val, radix)\n else if (type === 'int') parsed = parseInt(val)\n else if (type === 'float') parsed = parseFloat(val)\n else if (type === 'eval') parsed = Number(eval(val))\n else if (!type) parsed = Number(val)\n if (isNaN(parsed)) parsed = onNaN ?? 0\n\n return parsed\n}\n"],"names":["_isNumT","toNum","val","options","type","onNaN","radix","parsed","NaN","parseInt","parseFloat","Number","eval","isNaN"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,OAAO,QAAQ,6BAAyB;AAcjD;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,MACdC,GAAiB,EACjBC,OAA4B;IAE5B,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAG,aAAKH;IACpC,IAAII,SAA6BC;IAEjC,IAAIR,QAAQM,QAAQC,SAASE,SAASP,KAAKI;SACtC,IAAIF,SAAS,OAAOG,SAASE,SAASP;SACtC,IAAIE,SAAS,SAASG,SAASG,WAAWR;SAC1C,IAAIE,SAAS,QAAQG,SAASI,OAAOC,KAAKV;SAC1C,IAAI,CAACE,MAAMG,SAASI,OAAOT;IAChC,IAAIW,MAAMN,SAASA,SAASF,gBAAAA,QAAS;IAErC,OAAOE;AACT"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export type NumeronymOpts = {
18
+ kind?: NumeronymKind;
19
+ short?: boolean;
20
+ };
21
+ export declare enum NumeronymKind {
22
+ n19s = "NumericalContractions",
23
+ A9bs = "AlphanumericAbbreviationS",
24
+ A2S = "AlphanumericAcronymS"
25
+ }
26
+ /**
27
+ * Create a numeronym string from the provided string of characters
28
+ *
29
+ * e.g.
30
+ * ```typescript
31
+ * const intl = 'Internationalization'
32
+ * numeronym(intl, {kind: NumeronymKind.n19s})
33
+ * // result: I18n
34
+ * ```
35
+ *
36
+ * @export
37
+ * @param {string} str
38
+ * @param {NumeronymOpts} [opt]
39
+ * @returns
40
+ */
41
+ export declare function numeronym(str: string, opt?: NumeronymOpts): string;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ export var NumeronymKind = /*#__PURE__*/ function(NumeronymKind) {
17
+ NumeronymKind["n19s"] = "NumericalContractions"; /* first letter + len between(+ last letter) */
18
+ NumeronymKind["A9bs"] = "AlphanumericAbbreviationS"; /* AlphaN. = A9, Abbr. = bs */
19
+ NumeronymKind["A2S"] = "AlphanumericAcronymS"; /* (2) A's and (1) S (e.g. W3 or W3C) */
20
+ return NumeronymKind;
21
+ }({});
22
+ /**
23
+ * Create a numeronym string from the provided string of characters
24
+ *
25
+ * e.g.
26
+ * ```typescript
27
+ * const intl = 'Internationalization'
28
+ * numeronym(intl, {kind: NumeronymKind.n19s})
29
+ * // result: I18n
30
+ * ```
31
+ *
32
+ * @export
33
+ * @param {string} str
34
+ * @param {NumeronymOpts} [opt]
35
+ * @returns
36
+ */ export function numeronym(str, opt) {
37
+ const { kind, short } = opt != null ? opt : {};
38
+ const builder = {
39
+ ["NumericalContractions"]: ()=>{
40
+ const v = String(str);
41
+ const ln = v.length;
42
+ if (ln < 2) {
43
+ return v;
44
+ }
45
+ if (ln < 3 || short) {
46
+ return `${v[0]}${ln - 1}`;
47
+ }
48
+ return `${v[0]}${ln - 2}${v[ln - 1]}`;
49
+ }
50
+ };
51
+ return builder[kind != null ? kind : "NumericalContractions"]();
52
+ }
53
+
54
+ //# sourceMappingURL=numeronym.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/tools/src/lib/numeronym.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\n\nexport type NumeronymOpts = {\n kind?: NumeronymKind\n short?: boolean\n}\n\nexport enum NumeronymKind {\n n19s = 'NumericalContractions' /* first letter + len between(+ last letter) */,\n A9bs = 'AlphanumericAbbreviationS' /* AlphaN. = A9, Abbr. = bs */,\n A2S = 'AlphanumericAcronymS' /* (2) A's and (1) S (e.g. W3 or W3C) */,\n}\n\n/**\n * Create a numeronym string from the provided string of characters\n *\n * e.g.\n * ```typescript\n * const intl = 'Internationalization'\n * numeronym(intl, {kind: NumeronymKind.n19s})\n * // result: I18n\n * ```\n *\n * @export\n * @param {string} str\n * @param {NumeronymOpts} [opt]\n * @returns\n */\nexport function numeronym(str: string, opt?: NumeronymOpts) {\n const {kind, short} = opt ?? {}\n const builder = {\n [NumeronymKind.n19s]: () => {\n const v = String(str)\n const ln = v.length\n if (ln < 2) {\n return v\n }\n if (ln < 3 || short) {\n return `${v[0]}${ln - 1}`\n }\n return `${v[0]}${ln - 2}${v[ln - 1]}`\n },\n }\n\n return (builder as Record<string, () => string>)[kind ?? NumeronymKind.n19s]()\n}\n"],"names":["NumeronymKind","numeronym","str","opt","kind","short","builder","v","String","ln","length"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GASD,OAAO,IAAA,AAAKA,uCAAAA;qDACqB,6CAA6C;yDACzC,4BAA4B;mDAClC,sCAAsC;WAHzDA;MAIX;AAED;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,UAAUC,GAAW,EAAEC,GAAmB;IACxD,MAAM,EAACC,IAAI,EAAEC,KAAK,EAAC,GAAGF,cAAAA,MAAO,CAAC;IAC9B,MAAMG,UAAU;QACd,yBAAoB,EAAE;YACpB,MAAMC,IAAIC,OAAON;YACjB,MAAMO,KAAKF,EAAEG,MAAM;YACnB,IAAID,KAAK,GAAG;gBACV,OAAOF;YACT;YACA,IAAIE,KAAK,KAAKJ,OAAO;gBACnB,OAAO,GAAGE,CAAC,CAAC,EAAE,GAAGE,KAAK,GAAG;YAC3B;YACA,OAAO,GAAGF,CAAC,CAAC,EAAE,GAAGE,KAAK,IAAIF,CAAC,CAACE,KAAK,EAAE,EAAE;QACvC;IACF;IAEA,OAAO,AAACH,OAAwC,CAACF,eAAAA,+BAA2B;AAC9E"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Copy deep
19
+ */
20
+ export declare function objectCloneDeep<K extends keyof any, T>(target: Record<K, T>): Record<K, T>;
21
+ export default objectCloneDeep;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import cloneDeep from "../copy.js";
17
+ /**
18
+ * Copy deep
19
+ */ export function objectCloneDeep(target) {
20
+ return cloneDeep(target);
21
+ }
22
+ export default objectCloneDeep;
23
+
24
+ //# sourceMappingURL=object-clone-deep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/util/tools/src/lib/object/object-clone-deep.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport cloneDeep from '../copy'\n\n/**\n * Copy deep\n */\nexport function objectCloneDeep<K extends keyof any, T>(\n target: Record<K, T>,\n): Record<K, T> {\n return cloneDeep(target)\n}\nexport default objectCloneDeep\n"],"names":["cloneDeep","objectCloneDeep","target"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,OAAOA,eAAe,aAAS;AAE/B;;CAEC,GACD,OAAO,SAASC,gBACdC,MAAoB;IAEpB,OAAOF,UAAUE;AACnB;AACA,eAAeD,gBAAe"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Shallow copy iterable properties in iterable or array
19
+ */
20
+ export declare function objectClone<T>(target: Record<keyof any, T>): Record<keyof any, T>;
21
+ export default objectClone;
@@ -0,0 +1,24 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2022 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ /**
18
+ * Shallow copy iterable properties in iterable or array
19
+ */ export function objectClone(target) {
20
+ return _extends({}, target);
21
+ }
22
+ export default objectClone;
23
+
24
+ //# sourceMappingURL=object-clone.js.map