@naturalcycles/js-lib 14.276.0 → 15.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 (353) hide show
  1. package/cfg/frontend/tsconfig.json +3 -3
  2. package/dist/abort.js +1 -4
  3. package/dist/array/array.util.d.ts +1 -1
  4. package/dist/array/array.util.js +47 -88
  5. package/dist/array/range.d.ts +2 -2
  6. package/dist/array/range.js +7 -12
  7. package/dist/bot.js +6 -10
  8. package/dist/browser/adminService.d.ts +1 -1
  9. package/dist/browser/adminService.js +10 -14
  10. package/dist/browser/analytics.util.js +10 -15
  11. package/dist/browser/i18n/fetchTranslationLoader.d.ts +3 -3
  12. package/dist/browser/i18n/fetchTranslationLoader.js +1 -5
  13. package/dist/browser/i18n/translation.service.d.ts +1 -1
  14. package/dist/browser/i18n/translation.service.js +5 -10
  15. package/dist/browser/imageFitter.js +1 -5
  16. package/dist/browser/script.util.js +8 -12
  17. package/dist/browser/topbar.js +7 -10
  18. package/dist/datetime/dateInterval.d.ts +2 -2
  19. package/dist/datetime/dateInterval.js +7 -11
  20. package/dist/datetime/localDate.d.ts +3 -3
  21. package/dist/datetime/localDate.js +40 -44
  22. package/dist/datetime/localTime.d.ts +3 -3
  23. package/dist/datetime/localTime.js +36 -40
  24. package/dist/datetime/timeInterval.d.ts +2 -2
  25. package/dist/datetime/timeInterval.js +6 -10
  26. package/dist/datetime/wallTime.d.ts +3 -3
  27. package/dist/datetime/wallTime.js +5 -9
  28. package/dist/decorators/asyncMemo.decorator.d.ts +3 -3
  29. package/dist/decorators/asyncMemo.decorator.js +12 -17
  30. package/dist/decorators/createPromiseDecorator.js +3 -6
  31. package/dist/decorators/debounce.d.ts +1 -1
  32. package/dist/decorators/debounce.decorator.d.ts +1 -1
  33. package/dist/decorators/debounce.decorator.js +5 -9
  34. package/dist/decorators/debounce.js +2 -6
  35. package/dist/decorators/decorator.util.d.ts +1 -1
  36. package/dist/decorators/decorator.util.js +3 -8
  37. package/dist/decorators/logMethod.decorator.d.ts +1 -1
  38. package/dist/decorators/logMethod.decorator.js +11 -14
  39. package/dist/decorators/memo.decorator.d.ts +3 -3
  40. package/dist/decorators/memo.decorator.js +11 -16
  41. package/dist/decorators/memo.util.d.ts +2 -2
  42. package/dist/decorators/memo.util.js +11 -17
  43. package/dist/decorators/memoFn.d.ts +3 -3
  44. package/dist/decorators/memoFn.js +3 -6
  45. package/dist/decorators/memoFnAsync.d.ts +3 -3
  46. package/dist/decorators/memoFnAsync.js +5 -8
  47. package/dist/decorators/memoSimple.decorator.d.ts +1 -1
  48. package/dist/decorators/memoSimple.decorator.js +6 -10
  49. package/dist/decorators/retry.decorator.d.ts +1 -1
  50. package/dist/decorators/retry.decorator.js +3 -6
  51. package/dist/decorators/swarmSafe.decorator.js +3 -7
  52. package/dist/decorators/timeout.decorator.d.ts +1 -1
  53. package/dist/decorators/timeout.decorator.js +7 -10
  54. package/dist/define.d.ts +1 -1
  55. package/dist/define.js +11 -19
  56. package/dist/deviceIdService.js +7 -11
  57. package/dist/enum.util.d.ts +1 -1
  58. package/dist/enum.util.js +20 -42
  59. package/dist/env/buildInfo.d.ts +1 -1
  60. package/dist/env/buildInfo.js +3 -6
  61. package/dist/env.js +2 -6
  62. package/dist/error/assert.d.ts +3 -3
  63. package/dist/error/assert.js +30 -44
  64. package/dist/error/error.model.d.ts +2 -2
  65. package/dist/error/error.model.js +1 -2
  66. package/dist/error/error.util.d.ts +1 -1
  67. package/dist/error/error.util.js +25 -44
  68. package/dist/error/errorMode.js +2 -5
  69. package/dist/error/try.d.ts +2 -2
  70. package/dist/error/try.js +15 -23
  71. package/dist/error/tryCatch.d.ts +2 -2
  72. package/dist/error/tryCatch.js +6 -11
  73. package/dist/form.util.d.ts +1 -1
  74. package/dist/form.util.js +2 -6
  75. package/dist/http/fetcher.d.ts +3 -3
  76. package/dist/http/fetcher.js +48 -53
  77. package/dist/http/fetcher.model.d.ts +5 -5
  78. package/dist/http/fetcher.model.js +1 -2
  79. package/dist/http/http.model.js +1 -4
  80. package/dist/index.d.ts +96 -96
  81. package/dist/index.js +96 -99
  82. package/dist/is.util.d.ts +2 -2
  83. package/dist/is.util.js +12 -27
  84. package/dist/iter/asyncIterable2.d.ts +3 -3
  85. package/dist/iter/asyncIterable2.js +8 -12
  86. package/dist/iter/iterable2.d.ts +2 -2
  87. package/dist/iter/iterable2.js +8 -12
  88. package/dist/json-schema/from-data/generateJsonSchemaFromData.d.ts +1 -1
  89. package/dist/json-schema/from-data/generateJsonSchemaFromData.js +4 -7
  90. package/dist/json-schema/jsonSchema.cnst.d.ts +1 -1
  91. package/dist/json-schema/jsonSchema.cnst.js +1 -4
  92. package/dist/json-schema/jsonSchema.model.d.ts +1 -1
  93. package/dist/json-schema/jsonSchema.model.js +1 -2
  94. package/dist/json-schema/jsonSchema.util.d.ts +2 -2
  95. package/dist/json-schema/jsonSchema.util.js +5 -8
  96. package/dist/json-schema/jsonSchemaBuilder.d.ts +2 -2
  97. package/dist/json-schema/jsonSchemaBuilder.js +16 -25
  98. package/dist/json-schema/jsonSchemas.d.ts +2 -2
  99. package/dist/json-schema/jsonSchemas.js +5 -8
  100. package/dist/log/commonLogger.js +14 -21
  101. package/dist/math/accumulatingAverage.js +1 -5
  102. package/dist/math/math.util.js +11 -19
  103. package/dist/math/sma.js +1 -5
  104. package/dist/math/stack.util.js +11 -16
  105. package/dist/nanoid.js +2 -6
  106. package/dist/number/createDeterministicRandom.js +1 -4
  107. package/dist/number/number.util.d.ts +1 -1
  108. package/dist/number/number.util.js +9 -20
  109. package/dist/object/deepEquals.js +3 -8
  110. package/dist/object/map2.js +1 -5
  111. package/dist/object/object.util.d.ts +2 -2
  112. package/dist/object/object.util.js +40 -70
  113. package/dist/object/set2.js +1 -5
  114. package/dist/object/sortObject.d.ts +1 -1
  115. package/dist/object/sortObject.js +1 -4
  116. package/dist/object/sortObjectDeep.js +1 -4
  117. package/dist/polyfill.js +1 -4
  118. package/dist/promise/abortable.d.ts +1 -1
  119. package/dist/promise/abortable.js +2 -7
  120. package/dist/promise/pDefer.js +1 -4
  121. package/dist/promise/pDelay.d.ts +2 -2
  122. package/dist/promise/pDelay.js +4 -8
  123. package/dist/promise/pFilter.d.ts +1 -1
  124. package/dist/promise/pFilter.js +1 -4
  125. package/dist/promise/pHang.js +1 -4
  126. package/dist/promise/pMap.d.ts +2 -2
  127. package/dist/promise/pMap.js +17 -20
  128. package/dist/promise/pProps.js +1 -4
  129. package/dist/promise/pQueue.d.ts +2 -2
  130. package/dist/promise/pQueue.js +7 -11
  131. package/dist/promise/pRetry.d.ts +1 -1
  132. package/dist/promise/pRetry.js +8 -12
  133. package/dist/promise/pState.js +1 -4
  134. package/dist/promise/pTimeout.d.ts +3 -3
  135. package/dist/promise/pTimeout.js +7 -11
  136. package/dist/semver.d.ts +1 -1
  137. package/dist/semver.js +13 -18
  138. package/dist/string/case.js +9 -14
  139. package/dist/string/escape.js +2 -6
  140. package/dist/string/hash.util.d.ts +1 -1
  141. package/dist/string/hash.util.js +4 -10
  142. package/dist/string/json.util.d.ts +1 -1
  143. package/dist/string/json.util.js +5 -10
  144. package/dist/string/leven.js +1 -4
  145. package/dist/string/lodash/unicodeWords.js +1 -4
  146. package/dist/string/lodash/words.js +3 -6
  147. package/dist/string/pupa.d.ts +1 -1
  148. package/dist/string/pupa.js +4 -9
  149. package/dist/string/readingTime.d.ts +1 -1
  150. package/dist/string/readingTime.js +1 -4
  151. package/dist/string/regex.js +1 -4
  152. package/dist/string/safeJsonStringify.d.ts +1 -1
  153. package/dist/string/safeJsonStringify.js +1 -4
  154. package/dist/string/slugify.js +1 -4
  155. package/dist/string/string.util.js +15 -32
  156. package/dist/string/stringify.d.ts +1 -1
  157. package/dist/string/stringify.js +10 -14
  158. package/dist/string/url.util.d.ts +1 -1
  159. package/dist/string/url.util.js +2 -6
  160. package/dist/time/time.util.d.ts +1 -1
  161. package/dist/time/time.util.js +3 -8
  162. package/dist/typeFest.js +1 -2
  163. package/dist/types.d.ts +7 -3
  164. package/dist/types.js +21 -23
  165. package/dist/unit/size.util.js +5 -12
  166. package/dist/web.d.ts +1 -1
  167. package/dist/web.js +1 -5
  168. package/dist/zod/index.d.ts +2 -2
  169. package/dist/zod/index.js +4 -10
  170. package/dist/zod/zod.shared.schemas.js +36 -39
  171. package/dist/zod/zod.util.js +7 -14
  172. package/package.json +7 -8
  173. package/src/array/array.util.ts +3 -3
  174. package/src/array/range.ts +2 -2
  175. package/src/bot.ts +1 -1
  176. package/src/browser/adminService.ts +4 -4
  177. package/src/browser/analytics.util.ts +1 -1
  178. package/src/browser/i18n/fetchTranslationLoader.ts +3 -3
  179. package/src/browser/i18n/translation.service.ts +2 -2
  180. package/src/browser/script.util.ts +2 -2
  181. package/src/datetime/dateInterval.ts +3 -3
  182. package/src/datetime/localDate.ts +5 -5
  183. package/src/datetime/localTime.ts +6 -6
  184. package/src/datetime/timeInterval.ts +3 -3
  185. package/src/datetime/wallTime.ts +4 -4
  186. package/src/decorators/asyncMemo.decorator.ts +7 -7
  187. package/src/decorators/createPromiseDecorator.ts +1 -1
  188. package/src/decorators/debounce.decorator.ts +2 -2
  189. package/src/decorators/debounce.ts +1 -1
  190. package/src/decorators/decorator.util.ts +1 -1
  191. package/src/decorators/logMethod.decorator.ts +4 -4
  192. package/src/decorators/memo.decorator.ts +7 -7
  193. package/src/decorators/memo.util.ts +4 -4
  194. package/src/decorators/memoFn.ts +4 -4
  195. package/src/decorators/memoFnAsync.ts +5 -5
  196. package/src/decorators/memoSimple.decorator.ts +4 -4
  197. package/src/decorators/retry.decorator.ts +2 -2
  198. package/src/decorators/swarmSafe.decorator.ts +2 -2
  199. package/src/decorators/timeout.decorator.ts +4 -4
  200. package/src/define.ts +3 -3
  201. package/src/deviceIdService.ts +3 -3
  202. package/src/enum.util.ts +1 -1
  203. package/src/env/buildInfo.ts +2 -2
  204. package/src/error/assert.ts +7 -7
  205. package/src/error/error.model.ts +2 -2
  206. package/src/error/error.util.ts +5 -5
  207. package/src/error/try.ts +5 -5
  208. package/src/error/tryCatch.ts +3 -3
  209. package/src/form.util.ts +1 -1
  210. package/src/http/fetcher.model.ts +5 -5
  211. package/src/http/fetcher.ts +20 -15
  212. package/src/index.ts +96 -96
  213. package/src/is.util.ts +2 -2
  214. package/src/iter/asyncIterable2.ts +3 -3
  215. package/src/iter/iterable2.ts +2 -2
  216. package/src/json-schema/from-data/generateJsonSchemaFromData.ts +2 -2
  217. package/src/json-schema/jsonSchema.cnst.ts +1 -1
  218. package/src/json-schema/jsonSchema.model.ts +1 -1
  219. package/src/json-schema/jsonSchema.util.ts +4 -4
  220. package/src/json-schema/jsonSchemaBuilder.ts +5 -5
  221. package/src/json-schema/jsonSchemas.ts +2 -2
  222. package/src/math/math.util.ts +2 -2
  223. package/src/math/stack.util.ts +1 -1
  224. package/src/number/number.util.ts +1 -1
  225. package/src/object/object.util.ts +3 -3
  226. package/src/object/sortObject.ts +1 -1
  227. package/src/promise/abortable.ts +1 -1
  228. package/src/promise/pDelay.ts +3 -3
  229. package/src/promise/pFilter.ts +1 -1
  230. package/src/promise/pMap.ts +2 -2
  231. package/src/promise/pQueue.ts +4 -4
  232. package/src/promise/pRetry.ts +2 -2
  233. package/src/promise/pTimeout.ts +4 -4
  234. package/src/semver.ts +3 -3
  235. package/src/string/case.ts +2 -2
  236. package/src/string/hash.util.ts +1 -1
  237. package/src/string/json.util.ts +2 -2
  238. package/src/string/lodash/words.ts +1 -1
  239. package/src/string/pupa.ts +2 -2
  240. package/src/string/readingTime.ts +1 -1
  241. package/src/string/safeJsonStringify.ts +1 -1
  242. package/src/string/stringify.ts +4 -4
  243. package/src/string/url.util.ts +1 -1
  244. package/src/time/time.util.ts +1 -1
  245. package/src/types.ts +15 -3
  246. package/src/web.ts +1 -1
  247. package/src/zod/index.ts +2 -2
  248. package/src/zod/zod.util.ts +1 -1
  249. package/dist-esm/abort.js +0 -12
  250. package/dist-esm/array/array.util.js +0 -458
  251. package/dist-esm/array/range.js +0 -34
  252. package/dist-esm/bot.js +0 -130
  253. package/dist-esm/browser/adminService.js +0 -94
  254. package/dist-esm/browser/analytics.util.js +0 -54
  255. package/dist-esm/browser/i18n/fetchTranslationLoader.js +0 -13
  256. package/dist-esm/browser/i18n/translation.service.js +0 -56
  257. package/dist-esm/browser/imageFitter.js +0 -65
  258. package/dist-esm/browser/script.util.js +0 -46
  259. package/dist-esm/browser/topbar.js +0 -135
  260. package/dist-esm/datetime/dateInterval.js +0 -80
  261. package/dist-esm/datetime/localDate.js +0 -719
  262. package/dist-esm/datetime/localTime.js +0 -996
  263. package/dist-esm/datetime/timeInterval.js +0 -88
  264. package/dist-esm/datetime/wallTime.js +0 -70
  265. package/dist-esm/decorators/asyncMemo.decorator.js +0 -111
  266. package/dist-esm/decorators/createPromiseDecorator.js +0 -82
  267. package/dist-esm/decorators/debounce.decorator.js +0 -17
  268. package/dist-esm/decorators/debounce.js +0 -114
  269. package/dist-esm/decorators/decorator.util.js +0 -31
  270. package/dist-esm/decorators/logMethod.decorator.js +0 -85
  271. package/dist-esm/decorators/memo.decorator.js +0 -80
  272. package/dist-esm/decorators/memo.util.js +0 -97
  273. package/dist-esm/decorators/memoFn.js +0 -29
  274. package/dist-esm/decorators/memoFnAsync.js +0 -35
  275. package/dist-esm/decorators/memoSimple.decorator.js +0 -55
  276. package/dist-esm/decorators/retry.decorator.js +0 -9
  277. package/dist-esm/decorators/swarmSafe.decorator.js +0 -38
  278. package/dist-esm/decorators/timeout.decorator.js +0 -19
  279. package/dist-esm/define.js +0 -109
  280. package/dist-esm/deviceIdService.js +0 -105
  281. package/dist-esm/enum.util.js +0 -157
  282. package/dist-esm/env/buildInfo.js +0 -19
  283. package/dist-esm/env.js +0 -19
  284. package/dist-esm/error/assert.js +0 -122
  285. package/dist-esm/error/error.model.js +0 -1
  286. package/dist-esm/error/error.util.js +0 -337
  287. package/dist-esm/error/errorMode.js +0 -20
  288. package/dist-esm/error/try.js +0 -105
  289. package/dist-esm/error/tryCatch.js +0 -41
  290. package/dist-esm/form.util.js +0 -16
  291. package/dist-esm/http/fetcher.js +0 -704
  292. package/dist-esm/http/fetcher.model.js +0 -3
  293. package/dist-esm/http/http.model.js +0 -1
  294. package/dist-esm/index.js +0 -96
  295. package/dist-esm/is.util.js +0 -70
  296. package/dist-esm/iter/asyncIterable2.js +0 -103
  297. package/dist-esm/iter/iterable2.js +0 -87
  298. package/dist-esm/json-schema/from-data/generateJsonSchemaFromData.js +0 -86
  299. package/dist-esm/json-schema/jsonSchema.cnst.js +0 -38
  300. package/dist-esm/json-schema/jsonSchema.model.js +0 -1
  301. package/dist-esm/json-schema/jsonSchema.util.js +0 -27
  302. package/dist-esm/json-schema/jsonSchemaBuilder.js +0 -352
  303. package/dist-esm/json-schema/jsonSchemas.js +0 -6
  304. package/dist-esm/log/commonLogger.js +0 -78
  305. package/dist-esm/math/accumulatingAverage.js +0 -32
  306. package/dist-esm/math/math.util.js +0 -85
  307. package/dist-esm/math/sma.js +0 -43
  308. package/dist-esm/math/stack.util.js +0 -82
  309. package/dist-esm/nanoid.js +0 -57
  310. package/dist-esm/number/createDeterministicRandom.js +0 -18
  311. package/dist-esm/number/number.util.js +0 -109
  312. package/dist-esm/object/deepEquals.js +0 -170
  313. package/dist-esm/object/map2.js +0 -21
  314. package/dist-esm/object/object.util.js +0 -435
  315. package/dist-esm/object/set2.js +0 -15
  316. package/dist-esm/object/sortObject.js +0 -21
  317. package/dist-esm/object/sortObjectDeep.js +0 -17
  318. package/dist-esm/polyfill.js +0 -6
  319. package/dist-esm/promise/abortable.js +0 -31
  320. package/dist-esm/promise/pDefer.js +0 -17
  321. package/dist-esm/promise/pDelay.js +0 -37
  322. package/dist-esm/promise/pFilter.js +0 -5
  323. package/dist-esm/promise/pHang.js +0 -6
  324. package/dist-esm/promise/pMap.js +0 -174
  325. package/dist-esm/promise/pProps.js +0 -20
  326. package/dist-esm/promise/pQueue.js +0 -101
  327. package/dist-esm/promise/pRetry.js +0 -64
  328. package/dist-esm/promise/pState.js +0 -14
  329. package/dist-esm/promise/pTimeout.js +0 -64
  330. package/dist-esm/semver.js +0 -149
  331. package/dist-esm/string/case.js +0 -24
  332. package/dist-esm/string/escape.js +0 -49
  333. package/dist-esm/string/hash.util.js +0 -67
  334. package/dist-esm/string/json.util.js +0 -46
  335. package/dist-esm/string/leven.js +0 -77
  336. package/dist-esm/string/lodash/unicodeWords.js +0 -68
  337. package/dist-esm/string/lodash/words.js +0 -31
  338. package/dist-esm/string/pupa.js +0 -54
  339. package/dist-esm/string/readingTime.js +0 -102
  340. package/dist-esm/string/regex.js +0 -6
  341. package/dist-esm/string/safeJsonStringify.js +0 -39
  342. package/dist-esm/string/slugify.js +0 -66
  343. package/dist-esm/string/string.util.js +0 -99
  344. package/dist-esm/string/stringify.js +0 -133
  345. package/dist-esm/string/url.util.js +0 -42
  346. package/dist-esm/time/time.util.js +0 -61
  347. package/dist-esm/typeFest.js +0 -2
  348. package/dist-esm/types.js +0 -59
  349. package/dist-esm/unit/size.util.js +0 -43
  350. package/dist-esm/web.js +0 -40
  351. package/dist-esm/zod/index.js +0 -4
  352. package/dist-esm/zod/zod.shared.schemas.js +0 -92
  353. package/dist-esm/zod/zod.util.js +0 -52
@@ -1,435 +0,0 @@
1
- import { _isEmpty, _isObject } from '../is.util';
2
- import { _objectEntries, SKIP } from '../types';
3
- /**
4
- * Returns clone of `obj` with only `props` preserved.
5
- * Opposite of Omit.
6
- */
7
- export function _pick(obj, props, mutate = false) {
8
- if (mutate) {
9
- // Start as original object (mutable), DELETE properties that are not whitelisted
10
- for (const k of Object.keys(obj)) {
11
- if (!props.includes(k))
12
- delete obj[k];
13
- }
14
- return obj;
15
- }
16
- // Start as empty object, pick/add needed properties
17
- const r = {};
18
- for (const k of props) {
19
- if (k in obj)
20
- r[k] = obj[k];
21
- }
22
- return r;
23
- }
24
- /**
25
- * Sets all properties of an object except passed ones to `undefined`.
26
- * This is a more performant alternative to `_pick` that does picking/deleting.
27
- */
28
- export function _pickWithUndefined(obj, props, mutate = false) {
29
- const r = mutate ? obj : { ...obj };
30
- for (const k of Object.keys(r)) {
31
- if (!props.includes(k)) {
32
- r[k] = undefined;
33
- }
34
- }
35
- return r;
36
- }
37
- /**
38
- * Returns clone of `obj` with `props` omitted.
39
- * Opposite of Pick.
40
- */
41
- export function _omit(obj, props, mutate = false) {
42
- if (mutate) {
43
- for (const k of props) {
44
- delete obj[k];
45
- }
46
- return obj;
47
- }
48
- const r = {};
49
- for (const k of Object.keys(obj)) {
50
- if (!props.includes(k))
51
- r[k] = obj[k];
52
- }
53
- return r;
54
- }
55
- /**
56
- * Sets all passed properties of an object to `undefined`.
57
- * This is a more performant alternative to `_omit` that does picking/deleting.
58
- */
59
- export function _omitWithUndefined(obj, props, mutate = false) {
60
- const r = mutate ? obj : { ...obj };
61
- for (const k of props) {
62
- r[k] = undefined;
63
- }
64
- return r;
65
- }
66
- /**
67
- * Returns object with filtered keys from `props` array.
68
- * E.g:
69
- * _mask({...}, [
70
- * 'account.id',
71
- * 'account.updated',
72
- * ])
73
- */
74
- export function _mask(obj, props, mutate = false) {
75
- const r = mutate ? obj : _deepCopy(obj);
76
- for (const k of props) {
77
- _unset(r, k);
78
- }
79
- return r;
80
- }
81
- /**
82
- * Removes "falsy" values from the object.
83
- */
84
- export function _filterFalsyValues(obj, mutate = false) {
85
- return _filterObject(obj, (_k, v) => !!v, mutate);
86
- }
87
- /**
88
- * Removes values from the object that are `null` or `undefined`.
89
- */
90
- export function _filterNullishValues(obj, mutate = false) {
91
- return _filterObject(obj, (_k, v) => v !== undefined && v !== null, mutate);
92
- }
93
- /**
94
- * Removes values from the object that are `undefined`.
95
- * Only `undefined` values are removed. `null` values are kept!
96
- */
97
- export function _filterUndefinedValues(obj, mutate = false) {
98
- return _filterObject(obj, (_k, v) => v !== undefined, mutate);
99
- }
100
- export function _filterEmptyArrays(obj, mutate = false) {
101
- return _filterObject(obj, (_k, v) => !Array.isArray(v) || v.length > 0, mutate);
102
- }
103
- /**
104
- * Returns clone of `obj` without properties that does not pass `predicate`.
105
- * Allows filtering by both key and value.
106
- */
107
- export function _filterObject(obj, predicate, mutate = false) {
108
- if (mutate) {
109
- for (const [k, v] of _objectEntries(obj)) {
110
- if (!predicate(k, v, obj)) {
111
- delete obj[k];
112
- }
113
- }
114
- return obj;
115
- }
116
- const r = {};
117
- for (const [k, v] of _objectEntries(obj)) {
118
- if (predicate(k, v, obj)) {
119
- r[k] = v;
120
- }
121
- }
122
- return r;
123
- }
124
- /**
125
- * var users = {
126
- * 'fred': { 'user': 'fred', 'age': 40 },
127
- * 'pebbles': { 'user': 'pebbles', 'age': 1 }
128
- * }
129
- *
130
- * _mapValues(users, (_key, value) => value.age)
131
- * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
132
- *
133
- * To skip some key-value pairs - use _mapObject instead.
134
- */
135
- export function _mapValues(obj, mapper, mutate = false) {
136
- const map = mutate ? obj : {};
137
- for (const [k, v] of Object.entries(obj)) {
138
- map[k] = mapper(k, v, obj);
139
- }
140
- return map;
141
- }
142
- /**
143
- * _.mapKeys({ 'a': 1, 'b': 2 }, (key, value) => key + value)
144
- * // => { 'a1': 1, 'b2': 2 }
145
- *
146
- * Does not support `mutate` flag.
147
- *
148
- * To skip some key-value pairs - use _mapObject instead.
149
- */
150
- export function _mapKeys(obj, mapper) {
151
- const map = {};
152
- for (const [k, v] of Object.entries(obj)) {
153
- map[mapper(k, v, obj)] = v;
154
- }
155
- return map;
156
- }
157
- /**
158
- * Maps object through predicate - a function that receives (k, v, obj)
159
- * k - key
160
- * v - value
161
- * obj - whole object
162
- *
163
- * Order of arguments in the predicate is different form _mapValues / _mapKeys!
164
- *
165
- * Predicate should return a _tuple_ [0, 1], where:
166
- * 0 - key of returned object (string)
167
- * 1 - value of returned object (any)
168
- *
169
- * If predicate returns SKIP symbol - such key/value pair is ignored (filtered out).
170
- *
171
- * Non-string keys are passed via String(...)
172
- */
173
- export function _mapObject(obj, mapper) {
174
- const map = {};
175
- for (const [k, v] of Object.entries(obj)) {
176
- const r = mapper(k, v, obj);
177
- if (r === SKIP)
178
- continue;
179
- map[r[0]] = r[1];
180
- }
181
- return map;
182
- }
183
- export function _findKeyByValue(obj, v) {
184
- return Object.entries(obj).find(([_, value]) => value === v)?.[0];
185
- }
186
- export function _objectNullValuesToUndefined(obj, mutate = false) {
187
- return _mapValues(obj, (_k, v) => (v === null ? undefined : v), mutate);
188
- }
189
- /**
190
- * Deep copy object (by json parse/stringify, since it has unbeatable performance+simplicity combo).
191
- */
192
- export function _deepCopy(o, reviver) {
193
- return JSON.parse(JSON.stringify(o), reviver);
194
- }
195
- /**
196
- * Returns `undefined` if it's empty (according to `_isEmpty()` specification),
197
- * otherwise returns the original object.
198
- */
199
- export function _undefinedIfEmpty(obj) {
200
- return _isEmpty(obj) ? undefined : obj;
201
- }
202
- /**
203
- * Filters the object by removing all key-value pairs where Value is Empty (according to _isEmpty() specification).
204
- */
205
- export function _filterEmptyValues(obj, mutate = false) {
206
- return _filterObject(obj, (_k, v) => !_isEmpty(v), mutate);
207
- }
208
- /**
209
- * Recursively merges own and inherited enumerable properties of source
210
- * objects into the destination object, skipping source properties that resolve
211
- * to `undefined`. Array and plain object properties are merged recursively.
212
- * Other objects and value types are overridden by assignment. Source objects
213
- * are applied from left to right. Subsequent sources overwrite property
214
- * assignments of previous sources.
215
- *
216
- * Works as "recursive Object.assign".
217
- *
218
- * **Note:** This method mutates `object`.
219
- *
220
- * @category Object
221
- * @param target The destination object.
222
- * @param sources The source objects.
223
- * @returns Returns `object`.
224
- * @example
225
- *
226
- * var users = {
227
- * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
228
- * };
229
- *
230
- * var ages = {
231
- * 'data': [{ 'age': 36 }, { 'age': 40 }]
232
- * };
233
- *
234
- * _.merge(users, ages);
235
- * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
236
- *
237
- * Based on: https://gist.github.com/Salakar/1d7137de9cb8b704e48a
238
- */
239
- export function _merge(target, ...sources) {
240
- sources.forEach(source => {
241
- if (!_isObject(source))
242
- return;
243
- Object.keys(source).forEach(key => {
244
- var _a;
245
- if (_isObject(source[key])) {
246
- ;
247
- (_a = target)[key] || (_a[key] = {});
248
- _merge(target[key], source[key]);
249
- }
250
- else {
251
- ;
252
- target[key] = source[key];
253
- }
254
- });
255
- });
256
- return target;
257
- }
258
- /**
259
- * Trims all object VALUES deeply.
260
- * Doesn't touch object KEYS.
261
- * Mutates.
262
- */
263
- export function _deepTrim(o) {
264
- if (!o)
265
- return o;
266
- if (typeof o === 'string') {
267
- return o.trim();
268
- }
269
- if (typeof o === 'object') {
270
- Object.keys(o).forEach(k => {
271
- o[k] = _deepTrim(o[k]);
272
- });
273
- }
274
- return o;
275
- }
276
- // from: https://github.com/jonschlinkert/unset-value
277
- // mutates obj
278
- export function _unset(obj, prop) {
279
- if (!_isObject(obj)) {
280
- return;
281
- }
282
- if (obj.hasOwnProperty(prop)) {
283
- delete obj[prop];
284
- return;
285
- }
286
- const segs = prop.split('.');
287
- let last = segs.pop();
288
- while (segs.length && segs[segs.length - 1].endsWith('\\')) {
289
- last = segs.pop().slice(0, -1) + '.' + last;
290
- }
291
- while (segs.length && _isObject(obj)) {
292
- const k = segs.shift();
293
- obj = obj[k];
294
- }
295
- if (!_isObject(obj))
296
- return;
297
- delete obj[last];
298
- }
299
- export function _invert(o) {
300
- const inv = {};
301
- Object.keys(o).forEach(k => {
302
- inv[o[k]] = k;
303
- });
304
- return inv;
305
- }
306
- export function _invertMap(m) {
307
- const inv = new Map();
308
- m.forEach((v, k) => inv.set(v, k));
309
- return inv;
310
- }
311
- /**
312
- * Gets the property value at path of object.
313
- *
314
- * @example
315
- * const obj = {a: 'a', b: 'b', c: { cc: 'cc' }}
316
- * _get(obj, 'a') // 'a'
317
- * _get(obj, 'c.cc') // 'cc'
318
- * _get(obj, 'c[cc]') // 'cc'
319
- * _get(obj, 'unknown.path') // undefined
320
- */
321
- export function _get(obj = {}, path = '') {
322
- return (path
323
- .replaceAll(/\[([^\]]+)]/g, '.$1')
324
- .split('.')
325
- // eslint-disable-next-line unicorn/no-array-reduce
326
- .reduce((o, p) => o?.[p], obj));
327
- }
328
- /**
329
- * Sets the value at path of object. If a portion of path doesn’t exist it’s created. Arrays are created for
330
- * missing index properties while objects are created for all other missing properties.
331
- *
332
- * @param obj The object to modify.
333
- * @param path The path of the property to set.
334
- * @param value The value to set.
335
- * @return Returns object.
336
- *
337
- * Based on: https://stackoverflow.com/a/54733755/4919972
338
- */
339
- export function _set(obj, path, value) {
340
- // biome-ignore lint/style/useConsistentBuiltinInstantiation: ok
341
- if (!obj || Object(obj) !== obj || !path)
342
- return obj; // When obj is not an object
343
- // If not yet an array, get the keys from the string-path
344
- if (!Array.isArray(path)) {
345
- path = String(path).match(/[^.[\]]+/g) || [];
346
- }
347
- else if (!path.length) {
348
- return obj;
349
- }
350
- // eslint-disable-next-line unicorn/no-array-reduce
351
- ;
352
- path.slice(0, -1).reduce((a, c, i) =>
353
- // biome-ignore lint/style/useConsistentBuiltinInstantiation: ok
354
- Object(a[c]) === a[c] // Does the key exist and is its value an object?
355
- ? // Yes: then follow that path
356
- a[c]
357
- : // No: create the key. Is the next key a potential array-index?
358
- (a[c] =
359
- // eslint-disable-next-line
360
- Math.abs(path[i + 1]) >> 0 === +path[i + 1]
361
- ? [] // Yes: assign a new array object
362
- : {}), // No: assign a new plain object
363
- obj)[path[path.length - 1]] = value; // Finally assign the value to the last key
364
- return obj; // allow chaining
365
- }
366
- /**
367
- * Checks if `path` is a direct property of `object` (not null, not undefined).
368
- *
369
- * @category Object
370
- * @param obj The object to query.
371
- * @param path The path to check.
372
- * @returns Returns `true` if `path` exists, else `false`.
373
- * @example
374
- *
375
- * var object = { 'a': { 'b': { 'c': 3 } } };
376
- * var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
377
- *
378
- * _.has(object, 'a');
379
- * // => true
380
- *
381
- * _.has(object, 'a.b.c');
382
- * // => true
383
- *
384
- * _.has(object, ['a', 'b', 'c']);
385
- * // => true
386
- *
387
- * _.has(other, 'a');
388
- * // => false
389
- */
390
- export function _has(obj, path) {
391
- const v = _get(obj, path);
392
- return v !== undefined && v !== null;
393
- }
394
- /**
395
- * Does Object.freeze recursively for given object.
396
- *
397
- * Based on: https://github.com/substack/deep-freeze/blob/master/index.js
398
- */
399
- export function _deepFreeze(o) {
400
- Object.freeze(o);
401
- Object.getOwnPropertyNames(o).forEach(prop => {
402
- if (o.hasOwnProperty(prop) &&
403
- o[prop] !== null &&
404
- (typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
405
- !Object.isFrozen(o[prop])) {
406
- _deepFreeze(o[prop]);
407
- }
408
- });
409
- }
410
- /**
411
- * let target: T = { a: 'a', n: 1}
412
- * let source: T = { a: 'a2', b: 'b' }
413
- *
414
- * _objectAssignExact(target, source)
415
- *
416
- * Does the same as `target = source`,
417
- * except that it mutates the target to make it exactly the same as source,
418
- * while keeping the reference to the same object.
419
- *
420
- * This way it can "propagate deletions".
421
- * E.g source doesn't have the `n` property, so it'll be deleted from target.
422
- * With normal Object.assign - it'll override the keys that `source` has, but not the
423
- * "missing/deleted keys".
424
- *
425
- * To make mutation extra clear - function returns void (unlike Object.assign).
426
- */
427
- export function _objectAssignExact(target, source) {
428
- Object.assign(target, source);
429
- for (const k of Object.keys(target)) {
430
- if (!(k in source)) {
431
- // consider setting it to undefined maybe?
432
- delete target[k];
433
- }
434
- }
435
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Like Set, but serializes to JSON as an array.
3
- *
4
- * Fixes the "issue" of stock Set being json-serialized as `{}`.
5
- *
6
- * @experimental
7
- */
8
- export class Set2 extends Set {
9
- toArray() {
10
- return [...this];
11
- }
12
- toJSON() {
13
- return [...this];
14
- }
15
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * Returns new object with keys sorder in the given order.
3
- * All keys that are not listed in `keyOrder` go last.
4
- * Does not mutate original object.
5
- */
6
- export function _sortObject(obj, keyOrder) {
7
- const r = {};
8
- // First, go over ordered keys
9
- for (const k of keyOrder) {
10
- if (k in obj) {
11
- r[k] = obj[k];
12
- }
13
- }
14
- // Second, go over all other keys
15
- for (const [k, v] of Object.entries(obj)) {
16
- if (keyOrder.includes(k))
17
- continue;
18
- r[k] = v;
19
- }
20
- return r;
21
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * based on: https://github.com/IndigoUnited/js-deep-sort-object
3
- */
4
- export function _sortObjectDeep(o) {
5
- // array
6
- if (Array.isArray(o)) {
7
- return o.map(_sortObjectDeep);
8
- }
9
- if (o && typeof o === 'object') {
10
- const r = {};
11
- for (const k of Object.keys(o).sort((a, b) => a.localeCompare(b))) {
12
- r[k] = _sortObjectDeep(o[k]);
13
- }
14
- return r;
15
- }
16
- return o;
17
- }
@@ -1,6 +0,0 @@
1
- export function polyfillDispose() {
2
- // @ts-expect-error polyfill
3
- Symbol.dispose ?? (Symbol.dispose = Symbol('Symbol.dispose'));
4
- // @ts-expect-error polyfill
5
- Symbol.asyncDispose ?? (Symbol.asyncDispose = Symbol('Symbol.asyncDispose'));
6
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * Similar to AbortController and AbortSignal.
3
- * Similar to pDefer and Promise.
4
- * Similar to Subject and Observable.
5
- *
6
- * Minimal interface for something that can be aborted in the future,
7
- * but not necessary.
8
- * Allows to listen to `onAbort` event.
9
- *
10
- * @experimental
11
- */
12
- export class Abortable {
13
- constructor(onAbort) {
14
- this.onAbort = onAbort;
15
- this.aborted = false;
16
- }
17
- abort() {
18
- if (this.aborted)
19
- return;
20
- this.aborted = true;
21
- this.onAbort?.();
22
- this.onAbort = undefined; // cleanup listener
23
- }
24
- clear() {
25
- this.onAbort = undefined;
26
- }
27
- }
28
- // convenience function
29
- export function abortable(onAbort) {
30
- return new Abortable(onAbort);
31
- }
@@ -1,17 +0,0 @@
1
- /* eslint-disable @typescript-eslint/promise-function-async */
2
- /**
3
- * Returns DeferredPromise - a Promise that has .resolve() and .reject() methods.
4
- */
5
- export function pDefer() {
6
- let resolve;
7
- let reject;
8
- const promise = new Promise((_resolve, _reject) => {
9
- resolve = _resolve;
10
- reject = _reject;
11
- });
12
- promise.resolve = resolve;
13
- promise.reject = reject;
14
- promise.rejectAborted = reason => reject(new Error(['Aborted', reason].filter(Boolean).join(': ')));
15
- promise.abort = reason => promise.rejectAborted(reason);
16
- return promise;
17
- }
@@ -1,37 +0,0 @@
1
- import { pDefer } from './pDefer';
2
- /**
3
- * Promisified version of setTimeout.
4
- *
5
- * Can return a value.
6
- * If value is instanceof Error - rejects the Promise instead of resolving.
7
- */
8
- export async function pDelay(ms = 0, value) {
9
- return await new Promise((resolve, reject) => setTimeout(value instanceof Error ? reject : resolve, ms, value));
10
- }
11
- /* eslint-disable @typescript-eslint/promise-function-async */
12
- /**
13
- * Promisified version of setTimeout.
14
- *
15
- * Wraps the passed function with try/catch,
16
- * catch will propagate to pDelayFn rejection,
17
- * otherwise pDelayFn will resolve with returned value.
18
- *
19
- * On abort() - clears the Timeout and immediately resolves the Promise with void.
20
- */
21
- export function pDelayFn(ms, fn) {
22
- const p = pDefer();
23
- const timer = setTimeout(async () => {
24
- try {
25
- p.resolve(await fn());
26
- }
27
- catch (err) {
28
- p.reject(err);
29
- }
30
- }, ms);
31
- p.abort = () => {
32
- clearTimeout(timer);
33
- // p.rejectAborted(reason) // nope
34
- p.resolve();
35
- };
36
- return p;
37
- }
@@ -1,5 +0,0 @@
1
- export async function pFilter(iterable, filterFn) {
2
- const items = [...iterable];
3
- const predicates = await Promise.all(items.map((item, i) => filterFn(item, i)));
4
- return items.filter((_item, i) => predicates[i]);
5
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Returns Promise that never resolves ("hanging").
3
- */
4
- export async function pHang() {
5
- return await new Promise(() => void 0);
6
- }