@bitfiber/utils 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/CODE_OF_CONDUCT.md +127 -0
  2. package/CONTRIBUTING.md +87 -0
  3. package/LICENSE.txt +201 -0
  4. package/README.md +2516 -0
  5. package/arr/at/at.d.ts +7 -0
  6. package/arr/at/at.js +11 -0
  7. package/arr/at/at.js.map +1 -0
  8. package/arr/cnd/cnd.d.ts +55 -0
  9. package/arr/cnd/cnd.js +136 -0
  10. package/arr/cnd/cnd.js.map +1 -0
  11. package/arr/diff-arr/diff-arr.d.ts +10 -0
  12. package/arr/diff-arr/diff-arr.js +37 -0
  13. package/arr/diff-arr/diff-arr.js.map +1 -0
  14. package/arr/fill/fill.d.ts +8 -0
  15. package/arr/fill/fill.js +11 -0
  16. package/arr/fill/fill.js.map +1 -0
  17. package/arr/for-each-arr/for-each-arr.d.ts +9 -0
  18. package/arr/for-each-arr/for-each-arr.js +25 -0
  19. package/arr/for-each-arr/for-each-arr.js.map +1 -0
  20. package/arr/index-by/index-by.d.ts +9 -0
  21. package/arr/index-by/index-by.js +19 -0
  22. package/arr/index-by/index-by.js.map +1 -0
  23. package/arr/index.d.ts +9 -0
  24. package/arr/index.js +10 -0
  25. package/arr/index.js.map +1 -0
  26. package/arr/pluck/pluck.d.ts +7 -0
  27. package/arr/pluck/pluck.js +13 -0
  28. package/arr/pluck/pluck.js.map +1 -0
  29. package/arr/types.d.ts +84 -0
  30. package/arr/types.js +2 -0
  31. package/arr/types.js.map +1 -0
  32. package/arr/within/within.d.ts +9 -0
  33. package/arr/within/within.js +14 -0
  34. package/arr/within/within.js.map +1 -0
  35. package/common/copy/copy.d.ts +6 -0
  36. package/common/copy/copy.js +86 -0
  37. package/common/copy/copy.js.map +1 -0
  38. package/common/equals/equals.d.ts +12 -0
  39. package/common/equals/equals.js +127 -0
  40. package/common/equals/equals.js.map +1 -0
  41. package/common/error.d.ts +19 -0
  42. package/common/error.js +16 -0
  43. package/common/error.js.map +1 -0
  44. package/common/for-each/for-each.d.ts +9 -0
  45. package/common/for-each/for-each.js +40 -0
  46. package/common/for-each/for-each.js.map +1 -0
  47. package/common/get-unique-num-id/get-unique-num-id.d.ts +4 -0
  48. package/common/get-unique-num-id/get-unique-num-id.js +8 -0
  49. package/common/get-unique-num-id/get-unique-num-id.js.map +1 -0
  50. package/common/get-unique-str-id/get-unique-str-id.d.ts +4 -0
  51. package/common/get-unique-str-id/get-unique-str-id.js +16 -0
  52. package/common/get-unique-str-id/get-unique-str-id.js.map +1 -0
  53. package/common/has-iterator/has-iterator.d.ts +5 -0
  54. package/common/has-iterator/has-iterator.js +8 -0
  55. package/common/has-iterator/has-iterator.js.map +1 -0
  56. package/common/index.d.ts +16 -0
  57. package/common/index.js +17 -0
  58. package/common/index.js.map +1 -0
  59. package/common/is/is.d.ts +136 -0
  60. package/common/is/is.js +214 -0
  61. package/common/is/is.js.map +1 -0
  62. package/common/is-empty/is-empty.d.ts +6 -0
  63. package/common/is-empty/is-empty.js +30 -0
  64. package/common/is-empty/is-empty.js.map +1 -0
  65. package/common/random/random.d.ts +5 -0
  66. package/common/random/random.js +9 -0
  67. package/common/random/random.js.map +1 -0
  68. package/common/same/same.d.ts +6 -0
  69. package/common/same/same.js +9 -0
  70. package/common/same/same.js.map +1 -0
  71. package/common/stub/stub.d.ts +4 -0
  72. package/common/stub/stub.js +8 -0
  73. package/common/stub/stub.js.map +1 -0
  74. package/common/to-float/to-float.d.ts +6 -0
  75. package/common/to-float/to-float.js +10 -0
  76. package/common/to-float/to-float.js.map +1 -0
  77. package/common/to-int/to-int.d.ts +6 -0
  78. package/common/to-int/to-int.js +10 -0
  79. package/common/to-int/to-int.js.map +1 -0
  80. package/common/to-sorted-string/to-sorted-string.d.ts +7 -0
  81. package/common/to-sorted-string/to-sorted-string.js +53 -0
  82. package/common/to-sorted-string/to-sorted-string.js.map +1 -0
  83. package/common/types.d.ts +63 -0
  84. package/common/types.js +5 -0
  85. package/common/types.js.map +1 -0
  86. package/dom/closest/closest.d.ts +6 -0
  87. package/dom/closest/closest.js +26 -0
  88. package/dom/closest/closest.js.map +1 -0
  89. package/dom/document/document.d.ts +12 -0
  90. package/dom/document/document.js +24 -0
  91. package/dom/document/document.js.map +1 -0
  92. package/dom/download-file/download-file.d.ts +6 -0
  93. package/dom/download-file/download-file.js +32 -0
  94. package/dom/download-file/download-file.js.map +1 -0
  95. package/dom/for-each-elements/for-each-elements.d.ts +8 -0
  96. package/dom/for-each-elements/for-each-elements.js +16 -0
  97. package/dom/for-each-elements/for-each-elements.js.map +1 -0
  98. package/dom/for-each-nodes/for-each-nodes.d.ts +7 -0
  99. package/dom/for-each-nodes/for-each-nodes.js +15 -0
  100. package/dom/for-each-nodes/for-each-nodes.js.map +1 -0
  101. package/dom/get-all-styles/get-all-styles.d.ts +5 -0
  102. package/dom/get-all-styles/get-all-styles.js +10 -0
  103. package/dom/get-all-styles/get-all-styles.js.map +1 -0
  104. package/dom/get-body/get-body.d.ts +4 -0
  105. package/dom/get-body/get-body.js +9 -0
  106. package/dom/get-body/get-body.js.map +1 -0
  107. package/dom/get-html/get-html.d.ts +4 -0
  108. package/dom/get-html/get-html.js +9 -0
  109. package/dom/get-html/get-html.js.map +1 -0
  110. package/dom/get-non-static-parent/get-non-static-parent.d.ts +5 -0
  111. package/dom/get-non-static-parent/get-non-static-parent.js +9 -0
  112. package/dom/get-non-static-parent/get-non-static-parent.js.map +1 -0
  113. package/dom/get-offset-from-doc/get-offset-from-doc.d.ts +6 -0
  114. package/dom/get-offset-from-doc/get-offset-from-doc.js +18 -0
  115. package/dom/get-offset-from-doc/get-offset-from-doc.js.map +1 -0
  116. package/dom/get-offset-from-parent/get-offset-from-parent.d.ts +7 -0
  117. package/dom/get-offset-from-parent/get-offset-from-parent.js +45 -0
  118. package/dom/get-offset-from-parent/get-offset-from-parent.js.map +1 -0
  119. package/dom/get-offset-from-win/get-offset-from-win.d.ts +6 -0
  120. package/dom/get-offset-from-win/get-offset-from-win.js +8 -0
  121. package/dom/get-offset-from-win/get-offset-from-win.js.map +1 -0
  122. package/dom/get-scroll-width/get-scroll-width.d.ts +8 -0
  123. package/dom/get-scroll-width/get-scroll-width.js +28 -0
  124. package/dom/get-scroll-width/get-scroll-width.js.map +1 -0
  125. package/dom/get-style/get-style.d.ts +6 -0
  126. package/dom/get-style/get-style.js +23 -0
  127. package/dom/get-style/get-style.js.map +1 -0
  128. package/dom/get-styles/get-styles.d.ts +9 -0
  129. package/dom/get-styles/get-styles.js +12 -0
  130. package/dom/get-styles/get-styles.js.map +1 -0
  131. package/dom/get-valid-style-name/get-valid-style-name.d.ts +6 -0
  132. package/dom/get-valid-style-name/get-valid-style-name.js +41 -0
  133. package/dom/get-valid-style-name/get-valid-style-name.js.map +1 -0
  134. package/dom/get-window/get-window.d.ts +4 -0
  135. package/dom/get-window/get-window.js +17 -0
  136. package/dom/get-window/get-window.js.map +1 -0
  137. package/dom/has-name/has-name.d.ts +6 -0
  138. package/dom/has-name/has-name.js +9 -0
  139. package/dom/has-name/has-name.js.map +1 -0
  140. package/dom/index.d.ts +25 -0
  141. package/dom/index.js +26 -0
  142. package/dom/index.js.map +1 -0
  143. package/dom/is-comment/is-comment.d.ts +5 -0
  144. package/dom/is-comment/is-comment.js +8 -0
  145. package/dom/is-comment/is-comment.js.map +1 -0
  146. package/dom/is-element/is-element.d.ts +5 -0
  147. package/dom/is-element/is-element.js +8 -0
  148. package/dom/is-element/is-element.js.map +1 -0
  149. package/dom/is-text/is-text.d.ts +5 -0
  150. package/dom/is-text/is-text.js +8 -0
  151. package/dom/is-text/is-text.js.map +1 -0
  152. package/dom/set-offset-from-parent/set-offset-from-parent.d.ts +8 -0
  153. package/dom/set-offset-from-parent/set-offset-from-parent.js +42 -0
  154. package/dom/set-offset-from-parent/set-offset-from-parent.js.map +1 -0
  155. package/dom/set-style/set-style.d.ts +8 -0
  156. package/dom/set-style/set-style.js +14 -0
  157. package/dom/set-style/set-style.js.map +1 -0
  158. package/dom/set-styles/set-styles.d.ts +8 -0
  159. package/dom/set-styles/set-styles.js +16 -0
  160. package/dom/set-styles/set-styles.js.map +1 -0
  161. package/dom/types.d.ts +19 -0
  162. package/dom/types.js +2 -0
  163. package/dom/types.js.map +1 -0
  164. package/env/get-browser/get-browser.d.ts +10 -0
  165. package/env/get-browser/get-browser.js +33 -0
  166. package/env/get-browser/get-browser.js.map +1 -0
  167. package/env/get-engine/get-engine.d.ts +7 -0
  168. package/env/get-engine/get-engine.js +22 -0
  169. package/env/get-engine/get-engine.js.map +1 -0
  170. package/env/get-os/get-os.d.ts +8 -0
  171. package/env/get-os/get-os.js +26 -0
  172. package/env/get-os/get-os.js.map +1 -0
  173. package/env/get-platform/get-platform.d.ts +7 -0
  174. package/env/get-platform/get-platform.js +30 -0
  175. package/env/get-platform/get-platform.js.map +1 -0
  176. package/env/index.d.ts +21 -0
  177. package/env/index.js +22 -0
  178. package/env/index.js.map +1 -0
  179. package/env/is-browser/is-browser.d.ts +11 -0
  180. package/env/is-browser/is-browser.js +15 -0
  181. package/env/is-browser/is-browser.js.map +1 -0
  182. package/env/is-chrome-like/is-chrome-like.d.ts +4 -0
  183. package/env/is-chrome-like/is-chrome-like.js +9 -0
  184. package/env/is-chrome-like/is-chrome-like.js.map +1 -0
  185. package/env/is-desktop/is-desktop.d.ts +4 -0
  186. package/env/is-desktop/is-desktop.js +9 -0
  187. package/env/is-desktop/is-desktop.js.map +1 -0
  188. package/env/is-engine/is-engine.d.ts +8 -0
  189. package/env/is-engine/is-engine.js +12 -0
  190. package/env/is-engine/is-engine.js.map +1 -0
  191. package/env/is-firefox-like/is-firefox-like.d.ts +4 -0
  192. package/env/is-firefox-like/is-firefox-like.js +9 -0
  193. package/env/is-firefox-like/is-firefox-like.js.map +1 -0
  194. package/env/is-mobile/is-mobile.d.ts +4 -0
  195. package/env/is-mobile/is-mobile.js +9 -0
  196. package/env/is-mobile/is-mobile.js.map +1 -0
  197. package/env/is-os/is-os.d.ts +9 -0
  198. package/env/is-os/is-os.js +13 -0
  199. package/env/is-os/is-os.js.map +1 -0
  200. package/env/is-portable/is-portable.d.ts +4 -0
  201. package/env/is-portable/is-portable.js +8 -0
  202. package/env/is-portable/is-portable.js.map +1 -0
  203. package/env/is-safari-like/is-safari-like.d.ts +4 -0
  204. package/env/is-safari-like/is-safari-like.js +9 -0
  205. package/env/is-safari-like/is-safari-like.js.map +1 -0
  206. package/env/is-stationary/is-stationary.d.ts +4 -0
  207. package/env/is-stationary/is-stationary.js +8 -0
  208. package/env/is-stationary/is-stationary.js.map +1 -0
  209. package/env/is-tablet/is-tablet.d.ts +4 -0
  210. package/env/is-tablet/is-tablet.js +9 -0
  211. package/env/is-tablet/is-tablet.js.map +1 -0
  212. package/env/is-tv/is-tv.d.ts +4 -0
  213. package/env/is-tv/is-tv.js +9 -0
  214. package/env/is-tv/is-tv.js.map +1 -0
  215. package/env/matches/matches.d.ts +34 -0
  216. package/env/matches/matches.js +52 -0
  217. package/env/matches/matches.js.map +1 -0
  218. package/env/matches-with-browsers/matches-with-browsers.d.ts +23 -0
  219. package/env/matches-with-browsers/matches-with-browsers.js +53 -0
  220. package/env/matches-with-browsers/matches-with-browsers.js.map +1 -0
  221. package/env/matches-with-version/matches-with-version.d.ts +6 -0
  222. package/env/matches-with-version/matches-with-version.js +41 -0
  223. package/env/matches-with-version/matches-with-version.js.map +1 -0
  224. package/env/private/private.d.ts +4 -0
  225. package/env/private/private.js +67 -0
  226. package/env/private/private.js.map +1 -0
  227. package/env/types.d.ts +106 -0
  228. package/env/types.js +2 -0
  229. package/env/types.js.map +1 -0
  230. package/env/user-agent/user-agent.d.ts +9 -0
  231. package/env/user-agent/user-agent.js +24 -0
  232. package/env/user-agent/user-agent.js.map +1 -0
  233. package/index.d.ts +1 -0
  234. package/index.js +2 -0
  235. package/index.js.map +1 -0
  236. package/num/in-range/in-range.d.ts +8 -0
  237. package/num/in-range/in-range.js +23 -0
  238. package/num/in-range/in-range.js.map +1 -0
  239. package/num/index.d.ts +3 -0
  240. package/num/index.js +4 -0
  241. package/num/index.js.map +1 -0
  242. package/num/round/round.d.ts +7 -0
  243. package/num/round/round.js +11 -0
  244. package/num/round/round.js.map +1 -0
  245. package/num/types.d.ts +24 -0
  246. package/num/types.js +2 -0
  247. package/num/types.js.map +1 -0
  248. package/obj/constant/constant.d.ts +6 -0
  249. package/obj/constant/constant.js +8 -0
  250. package/obj/constant/constant.js.map +1 -0
  251. package/obj/deep-constant/deep-constant.d.ts +6 -0
  252. package/obj/deep-constant/deep-constant.js +18 -0
  253. package/obj/deep-constant/deep-constant.js.map +1 -0
  254. package/obj/diff-obj/diff-obj.d.ts +9 -0
  255. package/obj/diff-obj/diff-obj.js +48 -0
  256. package/obj/diff-obj/diff-obj.js.map +1 -0
  257. package/obj/exclude/exclude.d.ts +7 -0
  258. package/obj/exclude/exclude.js +18 -0
  259. package/obj/exclude/exclude.js.map +1 -0
  260. package/obj/extend/extend.d.ts +16 -0
  261. package/obj/extend/extend.js +49 -0
  262. package/obj/extend/extend.js.map +1 -0
  263. package/obj/for-each-obj/for-each-obj.d.ts +8 -0
  264. package/obj/for-each-obj/for-each-obj.js +16 -0
  265. package/obj/for-each-obj/for-each-obj.js.map +1 -0
  266. package/obj/has-own/has-own.d.ts +8 -0
  267. package/obj/has-own/has-own.js +11 -0
  268. package/obj/has-own/has-own.js.map +1 -0
  269. package/obj/include/include.d.ts +7 -0
  270. package/obj/include/include.js +17 -0
  271. package/obj/include/include.js.map +1 -0
  272. package/obj/index.d.ts +13 -0
  273. package/obj/index.js +14 -0
  274. package/obj/index.js.map +1 -0
  275. package/obj/keys/keys.d.ts +6 -0
  276. package/obj/keys/keys.js +8 -0
  277. package/obj/keys/keys.js.map +1 -0
  278. package/obj/map-obj/map-obj.d.ts +7 -0
  279. package/obj/map-obj/map-obj.js +12 -0
  280. package/obj/map-obj/map-obj.js.map +1 -0
  281. package/obj/map-obj-to-arr/map-obj-to-arr.d.ts +7 -0
  282. package/obj/map-obj-to-arr/map-obj-to-arr.js +12 -0
  283. package/obj/map-obj-to-arr/map-obj-to-arr.js.map +1 -0
  284. package/obj/types.d.ts +30 -0
  285. package/obj/types.js +2 -0
  286. package/obj/types.js.map +1 -0
  287. package/obj/values/values.d.ts +6 -0
  288. package/obj/values/values.js +11 -0
  289. package/obj/values/values.js.map +1 -0
  290. package/package.json +73 -0
  291. package/str/index.d.ts +3 -0
  292. package/str/index.js +4 -0
  293. package/str/index.js.map +1 -0
  294. package/str/to-camel-case/to-camel-case.d.ts +10 -0
  295. package/str/to-camel-case/to-camel-case.js +18 -0
  296. package/str/to-camel-case/to-camel-case.js.map +1 -0
  297. package/str/to-hash/to-hash.d.ts +7 -0
  298. package/str/to-hash/to-hash.js +21 -0
  299. package/str/to-hash/to-hash.js.map +1 -0
  300. package/str/with-capital/with-capital.d.ts +6 -0
  301. package/str/with-capital/with-capital.js +9 -0
  302. package/str/with-capital/with-capital.js.map +1 -0
package/arr/at/at.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns the array item at index, or undefined if there is no index.
3
+ * For negative indexes, returns items from the end
4
+ * @param arr - any array
5
+ * @param index - item index
6
+ */
7
+ export declare function at<T>(arr: T[], index: number): T | undefined;
package/arr/at/at.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns the array item at index, or undefined if there is no index.
3
+ * For negative indexes, returns items from the end
4
+ * @param arr - any array
5
+ * @param index - item index
6
+ */
7
+ export function at(arr, index) {
8
+ // todo: change on 'Array.at' with ES2022
9
+ return index < 0 ? arr[arr.length + index] : arr[index];
10
+ }
11
+ //# sourceMappingURL=at.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"at.js","sourceRoot":"","sources":["../../../../package/src/arr/at/at.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,EAAE,CAAI,GAAQ,EAAE,KAAa;IAC3C,yCAAyC;IACzC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { MatchConditionFn, MatchConditions } from '../';
2
+ /**
3
+ * Returns a function that checks if a value matches the conditions
4
+ * @example
5
+ * import {cnd} from '@bitfiber/utils/arr';
6
+ *
7
+ * const obj1 = {name: 'Alex'};
8
+ * const obj2 = {name: 'Mary'};
9
+ * const obj3 = {name: 'Jack'};
10
+ * const arr = [obj1, obj2, obj3];
11
+ * const strArr = ['Alex', 'Mary', 'Jack'];
12
+ *
13
+ * // Handler for comparison
14
+ * arr.filter(cnd(obj => obj.name === 'Alex')); // [{name: 'Alex'}]
15
+ *
16
+ * // Strict value comparison
17
+ * arr.filter(cnd({is: obj1})); // [{name: 'Alex'}]
18
+ * arr.filter(cnd({is: {name: 'Alex'}})); // []
19
+ * arr.filter(cnd({or: [obj1, obj2]})); // [{name: 'Alex'}, {name: 'Mary'}]
20
+ * arr.filter(cnd({or: [{name: 'Alex'}, obj2]})); // [{name: 'Mary'}]
21
+ * arr.filter(cnd({not: [obj1, obj2]})); // [{name: 'Jack'}]
22
+ * arr.filter(cnd({not: [{name: 'Alex'}, obj2]})); // [{name: 'Alex'}, {name: 'Jack'}]
23
+ *
24
+ * // Value equivalence comparison
25
+ * arr.filter(cnd({equal: obj1})); // [{name: 'Alex'}]
26
+ * arr.filter(cnd({equal: {name: 'Alex'}})); // [{name: 'Alex'}]
27
+ * arr.filter(cnd({orEqual: [obj1, obj2]})); // [{name: 'Alex'}, {name: 'Mary'}]
28
+ * arr.filter(cnd({orEqual: [{name: 'Alex'}, obj2]})); // [{name: 'Alex'}, {name: 'Mary'}]
29
+ * arr.filter(cnd({notEqual: [obj1, obj2]})); // [{name: 'Jack'}]
30
+ * arr.filter(cnd({notEqual: [{name: 'Alex'}, obj2]})); // [{name: 'Jack'}]
31
+ *
32
+ * // String value RegExp comparison
33
+ * strArr.filter(cnd({equal: /^Alex$/})); // ['Alex']
34
+ * strArr.filter(cnd({orEqual: [/^Alex$/, /^Mary$/]})); // ['Alex', 'Mary']
35
+ * strArr.filter(cnd({notEqual: [/^Alex$/, /^Mary$/]})); // ['Jack']
36
+ *
37
+ * // Strict comparison of field value in objects
38
+ * arr.filter(cnd({name: {is: 'Alex'}})); // [{name: 'Alex'}]
39
+ * arr.filter(cnd({name: {or: ['Alex', 'Mary']}})); // [{name: 'Alex'}, {name: 'Mary'}]
40
+ * arr.filter(cnd({name: {not: ['Alex', 'Mary']}})); // [{name: 'Jack'}]
41
+ *
42
+ * // Comparison of field value equivalence in objects
43
+ * arr.filter(cnd({name: {equal: 'Alex'}})); // [{name: 'Alex'}]
44
+ * arr.filter(cnd({name: {orEqual: ['Alex', 'Mary']}})); // [{name: 'Alex'}, {name: 'Mary'}]
45
+ * arr.filter(cnd({name: {notEqual: ['Alex', 'Mary']}})); // [{name: 'Jack'}]
46
+ *
47
+ * // Comparing string fields in objects using RegExp
48
+ * arr.filter(cnd({name: /^Alex$/})); // [{name: 'Alex'}]
49
+ * arr.filter(cnd({name: {equal: /^Alex$/}})); // [{name: 'Alex'}]
50
+ * arr.filter(cnd({name: {orEqual: [/^Alex$/, /^Mary$/]}})); // [{name: 'Alex'}, {name: 'Mary'}]
51
+ * arr.filter(cnd({name: {notEqual: [/^Alex$/, /^Mary$/]}})); // [{name: 'Jack'}]
52
+ *
53
+ * @param conditions
54
+ */
55
+ export declare function cnd(conditions: MatchConditions): MatchConditionFn;
package/arr/cnd/cnd.js ADDED
@@ -0,0 +1,136 @@
1
+ import { BfError, isFunction, isObject, isRegExp, isString, same, equals, isArray } from '../../';
2
+ import { hasOwn } from '../../obj';
3
+ /**
4
+ * Returns a function that checks if a value matches the conditions
5
+ * @example
6
+ * import {cnd} from '@bitfiber/utils/arr';
7
+ *
8
+ * const obj1 = {name: 'Alex'};
9
+ * const obj2 = {name: 'Mary'};
10
+ * const obj3 = {name: 'Jack'};
11
+ * const arr = [obj1, obj2, obj3];
12
+ * const strArr = ['Alex', 'Mary', 'Jack'];
13
+ *
14
+ * // Handler for comparison
15
+ * arr.filter(cnd(obj => obj.name === 'Alex')); // [{name: 'Alex'}]
16
+ *
17
+ * // Strict value comparison
18
+ * arr.filter(cnd({is: obj1})); // [{name: 'Alex'}]
19
+ * arr.filter(cnd({is: {name: 'Alex'}})); // []
20
+ * arr.filter(cnd({or: [obj1, obj2]})); // [{name: 'Alex'}, {name: 'Mary'}]
21
+ * arr.filter(cnd({or: [{name: 'Alex'}, obj2]})); // [{name: 'Mary'}]
22
+ * arr.filter(cnd({not: [obj1, obj2]})); // [{name: 'Jack'}]
23
+ * arr.filter(cnd({not: [{name: 'Alex'}, obj2]})); // [{name: 'Alex'}, {name: 'Jack'}]
24
+ *
25
+ * // Value equivalence comparison
26
+ * arr.filter(cnd({equal: obj1})); // [{name: 'Alex'}]
27
+ * arr.filter(cnd({equal: {name: 'Alex'}})); // [{name: 'Alex'}]
28
+ * arr.filter(cnd({orEqual: [obj1, obj2]})); // [{name: 'Alex'}, {name: 'Mary'}]
29
+ * arr.filter(cnd({orEqual: [{name: 'Alex'}, obj2]})); // [{name: 'Alex'}, {name: 'Mary'}]
30
+ * arr.filter(cnd({notEqual: [obj1, obj2]})); // [{name: 'Jack'}]
31
+ * arr.filter(cnd({notEqual: [{name: 'Alex'}, obj2]})); // [{name: 'Jack'}]
32
+ *
33
+ * // String value RegExp comparison
34
+ * strArr.filter(cnd({equal: /^Alex$/})); // ['Alex']
35
+ * strArr.filter(cnd({orEqual: [/^Alex$/, /^Mary$/]})); // ['Alex', 'Mary']
36
+ * strArr.filter(cnd({notEqual: [/^Alex$/, /^Mary$/]})); // ['Jack']
37
+ *
38
+ * // Strict comparison of field value in objects
39
+ * arr.filter(cnd({name: {is: 'Alex'}})); // [{name: 'Alex'}]
40
+ * arr.filter(cnd({name: {or: ['Alex', 'Mary']}})); // [{name: 'Alex'}, {name: 'Mary'}]
41
+ * arr.filter(cnd({name: {not: ['Alex', 'Mary']}})); // [{name: 'Jack'}]
42
+ *
43
+ * // Comparison of field value equivalence in objects
44
+ * arr.filter(cnd({name: {equal: 'Alex'}})); // [{name: 'Alex'}]
45
+ * arr.filter(cnd({name: {orEqual: ['Alex', 'Mary']}})); // [{name: 'Alex'}, {name: 'Mary'}]
46
+ * arr.filter(cnd({name: {notEqual: ['Alex', 'Mary']}})); // [{name: 'Jack'}]
47
+ *
48
+ * // Comparing string fields in objects using RegExp
49
+ * arr.filter(cnd({name: /^Alex$/})); // [{name: 'Alex'}]
50
+ * arr.filter(cnd({name: {equal: /^Alex$/}})); // [{name: 'Alex'}]
51
+ * arr.filter(cnd({name: {orEqual: [/^Alex$/, /^Mary$/]}})); // [{name: 'Alex'}, {name: 'Mary'}]
52
+ * arr.filter(cnd({name: {notEqual: [/^Alex$/, /^Mary$/]}})); // [{name: 'Jack'}]
53
+ *
54
+ * @param conditions
55
+ */
56
+ export function cnd(conditions) {
57
+ if (isFunction(conditions)) {
58
+ return conditions;
59
+ }
60
+ else if ('is' in conditions) {
61
+ return value => same(conditions.is, value);
62
+ }
63
+ else if ('or' in conditions) {
64
+ return value => (isArray(conditions.or) ? conditions.or.some(item => same(item, value)) : cndErr());
65
+ }
66
+ else if ('not' in conditions) {
67
+ return value => (isArray(conditions.not) ? !conditions.not.some(item => same(item, value)) : cndErr());
68
+ }
69
+ else if ('equal' in conditions) {
70
+ return value => fit(conditions.equal, value);
71
+ }
72
+ else if ('orEqual' in conditions) {
73
+ return value => (isArray(conditions.orEqual) ? conditions.orEqual.some(item => fit(item, value)) : cndErr());
74
+ }
75
+ else if ('notEqual' in conditions) {
76
+ return value => (isArray(conditions.notEqual) ? !conditions.notEqual.some(item => fit(item, value)) : cndErr());
77
+ }
78
+ else {
79
+ return obj => {
80
+ if (isObject(obj)) {
81
+ for (const key in conditions) {
82
+ if (hasOwn(conditions, key)) {
83
+ const value = obj[key];
84
+ const condition = conditions[key];
85
+ if (isRegExp(condition)) {
86
+ if (!fit(condition, value)) {
87
+ return false;
88
+ }
89
+ }
90
+ else if ('is' in condition) {
91
+ if (!same(condition.is, value)) {
92
+ return false;
93
+ }
94
+ }
95
+ else if ('or' in condition) {
96
+ if (!condition.or.some(item => same(item, value))) {
97
+ return false;
98
+ }
99
+ }
100
+ else if ('not' in condition) {
101
+ if (condition.not.some(item => same(item, value))) {
102
+ return false;
103
+ }
104
+ }
105
+ else if ('equal' in condition) {
106
+ if (!fit(condition.equal, value)) {
107
+ return false;
108
+ }
109
+ }
110
+ else if ('orEqual' in condition) {
111
+ if (!condition.orEqual.some(item => fit(item, value))) {
112
+ return false;
113
+ }
114
+ }
115
+ else if ('notEqual' in condition) {
116
+ if (condition.notEqual.some(item => fit(item, value))) {
117
+ return false;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ return true;
123
+ }
124
+ else {
125
+ return false;
126
+ }
127
+ };
128
+ }
129
+ }
130
+ function fit(condition, value) {
131
+ return isRegExp(condition) ? isString(value) && condition.test(value) : equals(condition, value);
132
+ }
133
+ function cndErr() {
134
+ throw new BfError('"or", "not", "orEqual" and "notEqual" must be an array', { code: 'bf_utils_arr_cnd_1' });
135
+ }
136
+ //# sourceMappingURL=cnd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cnd.js","sourceRoot":"","sources":["../../../../package/src/arr/cnd/cnd.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,10 @@
1
+ import { NumStr } from '../../';
2
+ import { ArrDiff } from '../';
3
+ /**
4
+ * Returns the difference between two arrays
5
+ * Strict comparison of array items is applied
6
+ * The order doesn't matter
7
+ * @param arr1 - array 1
8
+ * @param arr2 - array 2
9
+ */
10
+ export declare function diffArr<T extends NumStr>(arr1: T[], arr2: T[]): ArrDiff<T>;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Returns the difference between two arrays
3
+ * Strict comparison of array items is applied
4
+ * The order doesn't matter
5
+ * @param arr1 - array 1
6
+ * @param arr2 - array 2
7
+ */
8
+ export function diffArr(arr1, arr2) {
9
+ let isEqual = true;
10
+ const only1 = [];
11
+ const only2 = [];
12
+ const equal = [];
13
+ const map1 = new Map(arr1.map(value => [value, true]));
14
+ const map2 = new Map(arr2.map(value => [value, true]));
15
+ for (const value of map1.keys()) {
16
+ if (!map2.has(value)) {
17
+ isEqual = false;
18
+ only1.push(value);
19
+ }
20
+ else {
21
+ equal.push(value);
22
+ }
23
+ }
24
+ for (const value of map2.keys()) {
25
+ if (!map1.has(value)) {
26
+ isEqual = false;
27
+ only2.push(value);
28
+ }
29
+ }
30
+ return {
31
+ only1,
32
+ only2,
33
+ equal,
34
+ isEqual,
35
+ };
36
+ }
37
+ //# sourceMappingURL=diff-arr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff-arr.js","sourceRoot":"","sources":["../../../../package/src/arr/diff-arr/diff-arr.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAmB,IAAS,EAAE,IAAS;IAC5D,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,MAAM,KAAK,GAAQ,EAAE,CAAC;IACtB,MAAM,KAAK,GAAQ,EAAE,CAAC;IACtB,MAAM,KAAK,GAAQ,EAAE,CAAC;IACtB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACvD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAEvD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE;QAC/B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACpB,OAAO,GAAG,KAAK,CAAC;YAChB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACnB;aAAM;YACL,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACnB;KACF;IAED,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE;QAC/B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACpB,OAAO,GAAG,KAAK,CAAC;YAChB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACnB;KACF;IAED,OAAO;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,OAAO;KACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Fills a new array with items that will be returned by the handler,
3
+ * which will be called a certain number of times
4
+ * @param quantity - number of array items
5
+ * @param handler - a function that should return a new array item
6
+ * @param offset - offset for the index, which is passed to the handler
7
+ */
8
+ export declare function fill<T>(quantity: number, handler: (offsetIndex: number, index: number) => T, offset?: number): T[];
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Fills a new array with items that will be returned by the handler,
3
+ * which will be called a certain number of times
4
+ * @param quantity - number of array items
5
+ * @param handler - a function that should return a new array item
6
+ * @param offset - offset for the index, which is passed to the handler
7
+ */
8
+ export function fill(quantity, handler, offset = 1) {
9
+ return Array(quantity).fill(null).map((item, index) => handler(index + offset, index));
10
+ }
11
+ //# sourceMappingURL=fill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fill.js","sourceRoot":"","sources":["../../../../package/src/arr/fill/fill.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAAI,QAAgB,EAAE,OAAkD,EAAE,MAAM,GAAG,CAAC;IACtG,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,GAAG,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AACzF,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Arr, ValueUnion } from '../../';
2
+ /**
3
+ * Iterates through all the items of an array and calls a handler for each item
4
+ * If the handler returns INTERRUPT, the loop will be interrupted
5
+ * @param arr - an array or any typed array
6
+ * @param handler - function called for each item
7
+ * @param reverse - iterates in reverse order if true
8
+ */
9
+ export declare function forEachArr<T extends Arr, V extends ValueUnion<T>>(arr: T, handler: (value: V, index: number, arr: T) => any, reverse?: boolean): void;
@@ -0,0 +1,25 @@
1
+ import { INTERRUPT } from '../../';
2
+ /**
3
+ * Iterates through all the items of an array and calls a handler for each item
4
+ * If the handler returns INTERRUPT, the loop will be interrupted
5
+ * @param arr - an array or any typed array
6
+ * @param handler - function called for each item
7
+ * @param reverse - iterates in reverse order if true
8
+ */
9
+ export function forEachArr(arr, handler, reverse) {
10
+ if (reverse) {
11
+ for (let i = arr.length - 1; i >= 0; i--) {
12
+ if (handler(arr[i], i, arr) === INTERRUPT) {
13
+ return;
14
+ }
15
+ }
16
+ }
17
+ else {
18
+ for (let i = 0; i < arr.length; i++) {
19
+ if (handler(arr[i], i, arr) === INTERRUPT) {
20
+ return;
21
+ }
22
+ }
23
+ }
24
+ }
25
+ //# sourceMappingURL=for-each-arr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for-each-arr.js","sourceRoot":"","sources":["../../../../package/src/arr/for-each-arr/for-each-arr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,SAAS,EAAa,MAAM,QAAQ,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAyC,GAAM,EACvE,OAAiD,EAAE,OAAiB;IACpE,IAAI,OAAO,EAAE;QACX,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YACxC,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,SAAS,EAAE;gBACzC,OAAO;aACR;SACF;KACF;SAAM;QACL,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnC,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,SAAS,EAAE;gBACzC,OAAO;aACR;SACF;KACF;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Obj, Index } from '../../';
2
+ /**
3
+ * Returns an object indexed by the values from a specific field of each item
4
+ * or from a function that is executed on each item
5
+ * @param arr - array of objects
6
+ * @param fieldOrFn - the name of the field from which the index value should be taken,
7
+ * or the function that should return the index value
8
+ */
9
+ export declare function indexBy<T extends Obj>(arr: T[], fieldOrFn: string | ((item: T) => string)): Index<T>;
@@ -0,0 +1,19 @@
1
+ import { isFunction } from '../../';
2
+ /**
3
+ * Returns an object indexed by the values from a specific field of each item
4
+ * or from a function that is executed on each item
5
+ * @param arr - array of objects
6
+ * @param fieldOrFn - the name of the field from which the index value should be taken,
7
+ * or the function that should return the index value
8
+ */
9
+ export function indexBy(arr, fieldOrFn) {
10
+ const result = {};
11
+ arr.forEach(item => {
12
+ const key = isFunction(fieldOrFn) ? fieldOrFn(item) : item[fieldOrFn];
13
+ if (key) {
14
+ result[key] = item;
15
+ }
16
+ });
17
+ return result;
18
+ }
19
+ //# sourceMappingURL=index-by.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-by.js","sourceRoot":"","sources":["../../../../package/src/arr/index-by/index-by.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAa,MAAM,QAAQ,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAgB,GAAQ,EAAE,SAAyC;IACxF,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACjB,MAAM,GAAG,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtE,IAAI,GAAG,EAAE;YACP,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;SACpB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/arr/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from './types';
2
+ export * from './at/at';
3
+ export * from './within/within';
4
+ export * from './pluck/pluck';
5
+ export * from './index-by/index-by';
6
+ export * from './fill/fill';
7
+ export * from './diff-arr/diff-arr';
8
+ export * from './for-each-arr/for-each-arr';
9
+ export * from './cnd/cnd';
package/arr/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export * from './types';
2
+ export * from './at/at';
3
+ export * from './within/within';
4
+ export * from './pluck/pluck';
5
+ export * from './index-by/index-by';
6
+ export * from './fill/fill';
7
+ export * from './diff-arr/diff-arr';
8
+ export * from './for-each-arr/for-each-arr';
9
+ export * from './cnd/cnd';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../package/src/arr/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Obj } from '../../';
2
+ /**
3
+ * Returns an array with values, each of which corresponds to the value of a certain array item field
4
+ * @param arr - array of objects
5
+ * @param fieldName - name of the array item field from which the value is to be taken
6
+ */
7
+ export declare function pluck<T extends Obj, F extends keyof T>(arr: T[], fieldName: F): (T[F])[];
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns an array with values, each of which corresponds to the value of a certain array item field
3
+ * @param arr - array of objects
4
+ * @param fieldName - name of the array item field from which the value is to be taken
5
+ */
6
+ export function pluck(arr, fieldName) {
7
+ const result = [];
8
+ arr.forEach(item => {
9
+ result.push(item[fieldName]);
10
+ });
11
+ return result;
12
+ }
13
+ //# sourceMappingURL=pluck.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluck.js","sourceRoot":"","sources":["../../../../package/src/arr/pluck/pluck.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAmC,GAAQ,EAAE,SAAY;IAC5E,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACjB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/arr/types.d.ts ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Represents response of the diffArr function
3
+ */
4
+ export interface ArrDiff<T> {
5
+ /**
6
+ * Contains items that are only in array 1
7
+ */
8
+ only1: T[];
9
+ /**
10
+ * Contains items that are only in array 2
11
+ */
12
+ only2: T[];
13
+ /**
14
+ * Contains items that are in both arrays
15
+ */
16
+ equal: T[];
17
+ /**
18
+ * True if only1 and only2 are empty, otherwise false
19
+ */
20
+ isEqual: boolean;
21
+ }
22
+ /**
23
+ * Represents a condition that is true if the function returns true
24
+ * Used for the cnd function
25
+ */
26
+ export declare type MatchConditionFn = (value: any) => boolean;
27
+ /**
28
+ * Represents a condition that is true if the value is the same as the condition
29
+ * Used for the cnd function
30
+ */
31
+ export declare type MatchConditionIs = {
32
+ is: any;
33
+ };
34
+ /**
35
+ * Represents a condition that is true if the value is the same for at least one part of the condition
36
+ * Used for the cnd function
37
+ */
38
+ export declare type MatchConditionOr = {
39
+ or: any[];
40
+ };
41
+ /**
42
+ * Represents a condition that is true if the value is not the same for each part of the condition
43
+ * Used for the cnd function
44
+ */
45
+ export declare type MatchConditionNot = {
46
+ not: any[];
47
+ };
48
+ /**
49
+ * Represents a condition that is true if the value is equal to the condition
50
+ * Used for the cnd function
51
+ */
52
+ export declare type MatchConditionEqual = {
53
+ equal: any;
54
+ };
55
+ /**
56
+ * Represents a condition that is true if the value is equal to at least one part of the condition
57
+ * Used for the cnd function
58
+ */
59
+ export declare type MatchConditionOrEqual = {
60
+ orEqual: any[];
61
+ };
62
+ /**
63
+ * Represents a condition that is true if the value is not equal to each part of the condition
64
+ * Used for the cnd function
65
+ */
66
+ export declare type MatchConditionNotEqual = {
67
+ notEqual: any[];
68
+ };
69
+ /**
70
+ * Represents a group of all object condition types
71
+ * Used for the cnd function
72
+ */
73
+ export declare type MatchConditionObj = MatchConditionIs | MatchConditionOr | MatchConditionNot | MatchConditionEqual | MatchConditionOrEqual | MatchConditionNotEqual;
74
+ /**
75
+ * Represents a condition that is true if the value of each field matches each field condition
76
+ * Used for the cnd function
77
+ */
78
+ export declare type MatchConditionsByFields = {
79
+ [field: string]: MatchConditionObj | RegExp;
80
+ };
81
+ /**
82
+ * Represents all condition types for the cnd function
83
+ */
84
+ export declare type MatchConditions = MatchConditionFn | MatchConditionObj | MatchConditionsByFields;
package/arr/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../package/src/arr/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns an array item by index.
3
+ * If the index is greater than the array length,
4
+ * then the array item will be obtained like remainder of division the index by the array length.
5
+ * For negative indexes, returns items from the end
6
+ * @param arr - any array
7
+ * @param index - an array item index
8
+ */
9
+ export declare function within<T>(arr: T[], index: number): T | undefined;
@@ -0,0 +1,14 @@
1
+ import { at } from '../';
2
+ /**
3
+ * Returns an array item by index.
4
+ * If the index is greater than the array length,
5
+ * then the array item will be obtained like remainder of division the index by the array length.
6
+ * For negative indexes, returns items from the end
7
+ * @param arr - any array
8
+ * @param index - an array item index
9
+ */
10
+ export function within(arr, index) {
11
+ const max = arr.length;
12
+ return at(arr, ((index + 1) % max || max) - 1);
13
+ }
14
+ //# sourceMappingURL=within.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"within.js","sourceRoot":"","sources":["../../../../package/src/arr/within/within.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,EAAE,EAAC,MAAM,KAAK,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAI,GAAQ,EAAE,KAAa;IAC/C,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC;IACvB,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Creates a deep copy of a value of any type
3
+ * Objects, arrays, sets, maps etc. will be ignored if they have been visited to prevent looping
4
+ * @param value - anything
5
+ */
6
+ export declare function copy<T>(value: T): T;
@@ -0,0 +1,86 @@
1
+ import { isNumber, isBigInt, isBoolean, isString, isDate, isRegExp, isFunction, isMap, isSet, isObject, isArray, isTypedArray, isBlob, isArrayBuffer, isWindow, isDocument, isFile, isFormData, isPromise, isObservable, } from '../';
2
+ import { forEachObj } from '../../obj';
3
+ /**
4
+ * Creates a deep copy of a value of any type
5
+ * Objects, arrays, sets, maps etc. will be ignored if they have been visited to prevent looping
6
+ * @param value - anything
7
+ */
8
+ export function copy(value) {
9
+ return _copy(value, new Map());
10
+ }
11
+ function _copy(value, visited) {
12
+ if (!value || isString(value) || isNumber(value) || isBigInt(value) || isBoolean(value) || isFunction(value)) {
13
+ return value;
14
+ }
15
+ else if (isDate(value)) {
16
+ return new Date(value.getTime());
17
+ }
18
+ else if (isArray(value)) {
19
+ if (visited.has(value)) {
20
+ return visited.get(value);
21
+ }
22
+ const arr = [];
23
+ visited.set(value, arr);
24
+ value.forEach(item => arr.push(_copy(item, visited)));
25
+ return arr;
26
+ }
27
+ else if (isSet(value)) {
28
+ if (visited.has(value)) {
29
+ return visited.get(value);
30
+ }
31
+ const newSet = new Set();
32
+ visited.set(value, newSet);
33
+ value.forEach(item => newSet.add(_copy(item, visited)));
34
+ return newSet;
35
+ }
36
+ else if (isMap(value)) {
37
+ if (visited.has(value)) {
38
+ return visited.get(value);
39
+ }
40
+ const newMap = new Map();
41
+ visited.set(value, newMap);
42
+ value.forEach((item, key) => newMap.set(_copy(key, visited), _copy(item, visited)));
43
+ return newMap;
44
+ }
45
+ else if (isRegExp(value)) {
46
+ // @ts-ignore
47
+ const reg = new RegExp(value.source, value.toString().match(/[^/]*$/)[0]);
48
+ reg.lastIndex = value.lastIndex;
49
+ return reg;
50
+ }
51
+ else if (isBlob(value)) {
52
+ return new Blob([value], { type: value.type });
53
+ }
54
+ else if (isArrayBuffer(value)) {
55
+ return value.slice(0);
56
+ }
57
+ else if (isTypedArray(value)) {
58
+ // @ts-ignore
59
+ return new value.constructor(value.buffer.slice(0), value.byteOffset, value.length);
60
+ }
61
+ else if (isWindow(value) || isDocument(value) || isFile(value) || isFormData(value) || isPromise(value)
62
+ || isObservable(value)) {
63
+ return value;
64
+ }
65
+ else if (isObject(value)) {
66
+ if (visited.has(value)) {
67
+ return visited.get(value);
68
+ }
69
+ const obj = Object.create(Object.getPrototypeOf(value));
70
+ visited.set(value, obj);
71
+ forEachObj(value, (val, key) => {
72
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
73
+ if ((descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) || (descriptor === null || descriptor === void 0 ? void 0 : descriptor.set)) {
74
+ Object.defineProperty(obj, key, descriptor);
75
+ }
76
+ else {
77
+ obj[key] = _copy(val, visited);
78
+ }
79
+ });
80
+ return obj;
81
+ }
82
+ else {
83
+ return value;
84
+ }
85
+ }
86
+ //# sourceMappingURL=copy.js.map