@duplojs/utils 1.4.57 → 1.4.59

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 (319) hide show
  1. package/dist/array/group.cjs +11 -11
  2. package/dist/array/group.d.ts +1 -1
  3. package/dist/array/group.mjs +11 -11
  4. package/dist/clean/constraint/base.d.ts +6 -4
  5. package/dist/clean/constraint/defaultConstraint/index.d.ts +1 -0
  6. package/dist/clean/constraint/defaultConstraint/number.d.ts +6 -6
  7. package/dist/clean/constraint/defaultConstraint/string.d.ts +4 -4
  8. package/dist/clean/constraint/defaultConstraint/time.cjs +19 -0
  9. package/dist/clean/constraint/defaultConstraint/time.d.ts +61 -0
  10. package/dist/clean/constraint/defaultConstraint/time.mjs +16 -0
  11. package/dist/clean/constraint/set.d.ts +6 -4
  12. package/dist/clean/entity.d.ts +2 -1
  13. package/dist/clean/index.cjs +3 -0
  14. package/dist/clean/index.mjs +1 -0
  15. package/dist/clean/newType.d.ts +7 -5
  16. package/dist/clean/primitive/base.d.ts +25 -34
  17. package/dist/clean/primitive/operations/date/dateAddTime.d.ts +7 -11
  18. package/dist/clean/primitive/operations/date/dateGreaterThan.d.ts +9 -7
  19. package/dist/clean/primitive/operations/date/dateLessThan.d.ts +9 -7
  20. package/dist/clean/primitive/operations/date/dateMax.d.ts +3 -10
  21. package/dist/clean/primitive/operations/date/dateMin.d.ts +3 -10
  22. package/dist/clean/primitive/operations/date/dateSubtractTime.d.ts +7 -11
  23. package/dist/clean/primitive/operations/equal.cjs +1 -1
  24. package/dist/clean/primitive/operations/equal.d.ts +3 -3
  25. package/dist/clean/primitive/operations/equal.mjs +1 -1
  26. package/dist/clean/primitive/operations/sort.d.ts +8 -10
  27. package/dist/clean/primitive/operations/time/timeGreaterThan.d.ts +11 -9
  28. package/dist/clean/primitive/operations/time/timeLessThan.d.ts +11 -9
  29. package/dist/clean/primitive/operations/time/timeMax.cjs +2 -2
  30. package/dist/clean/primitive/operations/time/timeMax.d.ts +10 -17
  31. package/dist/clean/primitive/operations/time/timeMax.mjs +2 -2
  32. package/dist/clean/primitive/operations/time/timeMin.cjs +3 -3
  33. package/dist/clean/primitive/operations/time/timeMin.d.ts +10 -17
  34. package/dist/clean/primitive/operations/time/timeMin.mjs +3 -3
  35. package/dist/clean/unwrapEntity.cjs +13 -3
  36. package/dist/clean/unwrapEntity.d.ts +57 -5
  37. package/dist/clean/unwrapEntity.mjs +13 -3
  38. package/dist/common/index.d.ts +3 -4
  39. package/dist/common/kind.d.ts +1 -0
  40. package/dist/common/path.cjs +13 -13
  41. package/dist/common/path.d.ts +17 -11
  42. package/dist/common/path.mjs +13 -13
  43. package/dist/common/toRegExp.cjs +19 -0
  44. package/dist/common/toRegExp.d.ts +31 -0
  45. package/dist/common/toRegExp.mjs +17 -0
  46. package/dist/common/transformer.cjs +45 -0
  47. package/dist/common/transformer.d.ts +61 -0
  48. package/dist/common/transformer.mjs +40 -0
  49. package/dist/common/types/DeepReadonly.d.ts +1 -1
  50. package/dist/common/types/toLargeEnsemble.d.ts +2 -2
  51. package/dist/dataParser/error.cjs +4 -2
  52. package/dist/dataParser/error.d.ts +4 -2
  53. package/dist/dataParser/error.mjs +4 -2
  54. package/dist/dataParser/extended/date.d.ts +9 -4
  55. package/dist/dataParser/extended/time.d.ts +28 -12
  56. package/dist/dataParser/identifier.d.ts +20 -8
  57. package/dist/dataParser/parsers/date.cjs +16 -12
  58. package/dist/dataParser/parsers/date.d.ts +15 -9
  59. package/dist/dataParser/parsers/date.mjs +16 -12
  60. package/dist/dataParser/parsers/time/checkers/max.cjs +3 -0
  61. package/dist/dataParser/parsers/time/checkers/max.d.ts +28 -0
  62. package/dist/dataParser/parsers/time/checkers/max.mjs +3 -0
  63. package/dist/dataParser/parsers/time/checkers/min.cjs +3 -0
  64. package/dist/dataParser/parsers/time/checkers/min.d.ts +28 -0
  65. package/dist/dataParser/parsers/time/checkers/min.mjs +3 -0
  66. package/dist/dataParser/parsers/time/index.cjs +14 -10
  67. package/dist/dataParser/parsers/time/index.d.ts +15 -9
  68. package/dist/dataParser/parsers/time/index.mjs +14 -10
  69. package/dist/date/applyTimezone.cjs +4 -4
  70. package/dist/date/applyTimezone.d.ts +18 -16
  71. package/dist/date/applyTimezone.mjs +2 -2
  72. package/dist/date/closestTo.cjs +6 -2
  73. package/dist/date/closestTo.d.ts +15 -15
  74. package/dist/date/closestTo.mjs +6 -2
  75. package/dist/date/constants.cjs +4 -4
  76. package/dist/date/constants.d.ts +2 -2
  77. package/dist/date/constants.mjs +3 -3
  78. package/dist/date/create.cjs +20 -10
  79. package/dist/date/create.d.ts +24 -38
  80. package/dist/date/create.mjs +21 -11
  81. package/dist/date/createOrThrow.d.ts +18 -20
  82. package/dist/date/createTime.cjs +16 -7
  83. package/dist/date/createTime.d.ts +19 -18
  84. package/dist/date/createTime.mjs +17 -8
  85. package/dist/date/createTimeOrThrow.d.ts +17 -20
  86. package/dist/date/each.cjs +6 -4
  87. package/dist/date/each.d.ts +21 -19
  88. package/dist/date/each.mjs +6 -4
  89. package/dist/date/format.d.ts +17 -15
  90. package/dist/date/formatTime.d.ts +17 -16
  91. package/dist/date/getTimezoneOffset.cjs +6 -3
  92. package/dist/date/getTimezoneOffset.d.ts +17 -18
  93. package/dist/date/getTimezoneOffset.mjs +6 -3
  94. package/dist/date/getters/getDayOfMonth.cjs +3 -3
  95. package/dist/date/getters/getDayOfMonth.d.ts +20 -14
  96. package/dist/date/getters/getDayOfMonth.mjs +3 -3
  97. package/dist/date/getters/getDayOfWeek.cjs +3 -3
  98. package/dist/date/getters/getDayOfWeek.d.ts +15 -12
  99. package/dist/date/getters/getDayOfWeek.mjs +3 -3
  100. package/dist/date/getters/getDayOfYear.cjs +6 -6
  101. package/dist/date/getters/getDayOfYear.d.ts +21 -13
  102. package/dist/date/getters/getDayOfYear.mjs +6 -6
  103. package/dist/date/getters/getFirstDayOfMonth.cjs +2 -3
  104. package/dist/date/getters/getFirstDayOfMonth.d.ts +16 -10
  105. package/dist/date/getters/getFirstDayOfMonth.mjs +2 -3
  106. package/dist/date/getters/getFirstDayOfWeek.cjs +2 -3
  107. package/dist/date/getters/getFirstDayOfWeek.d.ts +17 -10
  108. package/dist/date/getters/getFirstDayOfWeek.mjs +2 -3
  109. package/dist/date/getters/getHour.cjs +3 -3
  110. package/dist/date/getters/getHour.d.ts +16 -14
  111. package/dist/date/getters/getHour.mjs +3 -3
  112. package/dist/date/getters/getLastDayOfMonth.cjs +2 -3
  113. package/dist/date/getters/getLastDayOfMonth.d.ts +16 -10
  114. package/dist/date/getters/getLastDayOfMonth.mjs +2 -3
  115. package/dist/date/getters/getLastDayOfWeek.cjs +2 -3
  116. package/dist/date/getters/getLastDayOfWeek.d.ts +17 -10
  117. package/dist/date/getters/getLastDayOfWeek.mjs +2 -3
  118. package/dist/date/getters/getMilliseconds.cjs +2 -2
  119. package/dist/date/getters/getMilliseconds.d.ts +11 -9
  120. package/dist/date/getters/getMilliseconds.mjs +2 -2
  121. package/dist/date/getters/getMinute.cjs +3 -3
  122. package/dist/date/getters/getMinute.d.ts +17 -15
  123. package/dist/date/getters/getMinute.mjs +3 -3
  124. package/dist/date/getters/getMonth.cjs +3 -3
  125. package/dist/date/getters/getMonth.d.ts +20 -15
  126. package/dist/date/getters/getMonth.mjs +3 -3
  127. package/dist/date/getters/getSecond.cjs +3 -3
  128. package/dist/date/getters/getSecond.d.ts +17 -15
  129. package/dist/date/getters/getSecond.mjs +3 -3
  130. package/dist/date/getters/getWeekOfYear.cjs +12 -11
  131. package/dist/date/getters/getWeekOfYear.d.ts +17 -11
  132. package/dist/date/getters/getWeekOfYear.mjs +12 -11
  133. package/dist/date/getters/getYear.cjs +3 -3
  134. package/dist/date/getters/getYear.d.ts +16 -15
  135. package/dist/date/getters/getYear.mjs +3 -3
  136. package/dist/date/index.cjs +12 -6
  137. package/dist/date/index.d.ts +5 -2
  138. package/dist/date/index.mjs +6 -3
  139. package/dist/date/is.cjs +3 -8
  140. package/dist/date/is.d.ts +9 -14
  141. package/dist/date/is.mjs +3 -8
  142. package/dist/date/isSafeTimeValue.d.ts +9 -13
  143. package/dist/date/isSafeTimestamp.d.ts +7 -16
  144. package/dist/date/isSerializedTheDate.cjs +20 -0
  145. package/dist/date/isSerializedTheDate.d.ts +31 -0
  146. package/dist/date/isSerializedTheDate.mjs +18 -0
  147. package/dist/date/isSerializedTheTime.cjs +20 -0
  148. package/dist/date/isSerializedTheTime.d.ts +31 -0
  149. package/dist/date/isSerializedTheTime.mjs +18 -0
  150. package/dist/date/isTime.cjs +3 -8
  151. package/dist/date/isTime.d.ts +7 -14
  152. package/dist/date/isTime.mjs +3 -8
  153. package/dist/date/kind.cjs +9 -0
  154. package/dist/date/kind.d.ts +1 -0
  155. package/dist/date/kind.mjs +7 -0
  156. package/dist/date/makeSafeTimeValue.d.ts +12 -11
  157. package/dist/date/makeSafeTimestamp.d.ts +12 -11
  158. package/dist/date/max.cjs +2 -2
  159. package/dist/date/max.d.ts +13 -13
  160. package/dist/date/max.mjs +2 -2
  161. package/dist/date/maxTime.cjs +2 -2
  162. package/dist/date/maxTime.d.ts +13 -21
  163. package/dist/date/maxTime.mjs +2 -2
  164. package/dist/date/min.cjs +2 -2
  165. package/dist/date/min.d.ts +13 -13
  166. package/dist/date/min.mjs +2 -2
  167. package/dist/date/minTime.cjs +2 -2
  168. package/dist/date/minTime.d.ts +13 -21
  169. package/dist/date/minTime.mjs +2 -2
  170. package/dist/date/now.cjs +3 -1
  171. package/dist/date/now.d.ts +9 -7
  172. package/dist/date/now.mjs +3 -1
  173. package/dist/date/operators/addDays.cjs +3 -5
  174. package/dist/date/operators/addDays.d.ts +14 -11
  175. package/dist/date/operators/addDays.mjs +3 -5
  176. package/dist/date/operators/addHours.cjs +3 -5
  177. package/dist/date/operators/addHours.d.ts +14 -11
  178. package/dist/date/operators/addHours.mjs +3 -5
  179. package/dist/date/operators/addMilliseconds.cjs +3 -5
  180. package/dist/date/operators/addMilliseconds.d.ts +14 -11
  181. package/dist/date/operators/addMilliseconds.mjs +3 -5
  182. package/dist/date/operators/addMinutes.cjs +3 -5
  183. package/dist/date/operators/addMinutes.d.ts +14 -11
  184. package/dist/date/operators/addMinutes.mjs +3 -5
  185. package/dist/date/operators/addMonths.cjs +2 -2
  186. package/dist/date/operators/addMonths.d.ts +13 -13
  187. package/dist/date/operators/addMonths.mjs +2 -2
  188. package/dist/date/operators/addSeconds.cjs +3 -5
  189. package/dist/date/operators/addSeconds.d.ts +14 -11
  190. package/dist/date/operators/addSeconds.mjs +3 -5
  191. package/dist/date/operators/addTime.cjs +13 -6
  192. package/dist/date/operators/addTime.d.ts +20 -18
  193. package/dist/date/operators/addTime.mjs +13 -6
  194. package/dist/date/operators/addWeeks.cjs +6 -5
  195. package/dist/date/operators/addWeeks.d.ts +14 -11
  196. package/dist/date/operators/addWeeks.mjs +6 -5
  197. package/dist/date/operators/addYears.cjs +2 -2
  198. package/dist/date/operators/addYears.d.ts +13 -13
  199. package/dist/date/operators/addYears.mjs +2 -2
  200. package/dist/date/operators/between.d.ts +11 -11
  201. package/dist/date/operators/betweenThan.d.ts +11 -11
  202. package/dist/date/operators/betweenThanTime.d.ts +18 -22
  203. package/dist/date/operators/betweenTime.d.ts +17 -21
  204. package/dist/date/operators/greater.d.ts +12 -9
  205. package/dist/date/operators/greaterThan.d.ts +14 -11
  206. package/dist/date/operators/greaterThanTime.d.ts +17 -21
  207. package/dist/date/operators/greaterTime.d.ts +16 -20
  208. package/dist/date/operators/less.d.ts +12 -9
  209. package/dist/date/operators/lessThan.d.ts +13 -10
  210. package/dist/date/operators/lessThanTime.d.ts +17 -21
  211. package/dist/date/operators/lessTime.d.ts +16 -20
  212. package/dist/date/operators/subtractDays.cjs +3 -5
  213. package/dist/date/operators/subtractDays.d.ts +14 -11
  214. package/dist/date/operators/subtractDays.mjs +3 -5
  215. package/dist/date/operators/subtractHours.cjs +3 -5
  216. package/dist/date/operators/subtractHours.d.ts +14 -11
  217. package/dist/date/operators/subtractHours.mjs +3 -5
  218. package/dist/date/operators/subtractMilliseconds.cjs +3 -5
  219. package/dist/date/operators/subtractMilliseconds.d.ts +14 -11
  220. package/dist/date/operators/subtractMilliseconds.mjs +3 -5
  221. package/dist/date/operators/subtractMinutes.cjs +3 -5
  222. package/dist/date/operators/subtractMinutes.d.ts +14 -11
  223. package/dist/date/operators/subtractMinutes.mjs +3 -5
  224. package/dist/date/operators/subtractMonths.cjs +2 -2
  225. package/dist/date/operators/subtractMonths.d.ts +17 -11
  226. package/dist/date/operators/subtractMonths.mjs +2 -2
  227. package/dist/date/operators/subtractSeconds.cjs +3 -5
  228. package/dist/date/operators/subtractSeconds.d.ts +14 -11
  229. package/dist/date/operators/subtractSeconds.mjs +3 -5
  230. package/dist/date/operators/subtractTime.cjs +13 -6
  231. package/dist/date/operators/subtractTime.d.ts +20 -18
  232. package/dist/date/operators/subtractTime.mjs +13 -6
  233. package/dist/date/operators/subtractWeeks.cjs +3 -5
  234. package/dist/date/operators/subtractWeeks.d.ts +14 -11
  235. package/dist/date/operators/subtractWeeks.mjs +3 -5
  236. package/dist/date/operators/subtractYears.cjs +2 -2
  237. package/dist/date/operators/subtractYears.d.ts +17 -11
  238. package/dist/date/operators/subtractYears.mjs +2 -2
  239. package/dist/date/round.cjs +2 -2
  240. package/dist/date/round.d.ts +11 -14
  241. package/dist/date/round.mjs +2 -2
  242. package/dist/date/serialize.cjs +14 -0
  243. package/dist/date/serialize.d.ts +41 -0
  244. package/dist/date/serialize.mjs +12 -0
  245. package/dist/date/sort.cjs +2 -2
  246. package/dist/date/sort.d.ts +16 -15
  247. package/dist/date/sort.mjs +2 -2
  248. package/dist/date/sortTimes.cjs +2 -2
  249. package/dist/date/sortTimes.d.ts +15 -21
  250. package/dist/date/sortTimes.mjs +2 -2
  251. package/dist/date/theDate.cjs +124 -0
  252. package/dist/date/theDate.d.ts +114 -0
  253. package/dist/date/theDate.mjs +122 -0
  254. package/dist/date/theTime.cjs +36 -0
  255. package/dist/date/theTime.d.ts +53 -0
  256. package/dist/date/theTime.mjs +34 -0
  257. package/dist/date/timezone.cjs +3 -0
  258. package/dist/date/timezone.d.ts +27 -0
  259. package/dist/date/timezone.mjs +3 -0
  260. package/dist/date/toISOString.cjs +5 -2
  261. package/dist/date/toISOString.d.ts +12 -10
  262. package/dist/date/toISOString.mjs +5 -2
  263. package/dist/date/toNative.cjs +4 -0
  264. package/dist/date/toNative.d.ts +12 -10
  265. package/dist/date/toNative.mjs +4 -0
  266. package/dist/date/toTimeValue.cjs +6 -2
  267. package/dist/date/toTimeValue.d.ts +14 -12
  268. package/dist/date/toTimeValue.mjs +6 -2
  269. package/dist/date/toTimestamp.cjs +5 -3
  270. package/dist/date/toTimestamp.d.ts +11 -9
  271. package/dist/date/toTimestamp.mjs +6 -4
  272. package/dist/date/today.cjs +3 -1
  273. package/dist/date/today.d.ts +14 -7
  274. package/dist/date/today.mjs +3 -1
  275. package/dist/date/tomorrow.cjs +2 -1
  276. package/dist/date/tomorrow.d.ts +12 -7
  277. package/dist/date/tomorrow.mjs +2 -1
  278. package/dist/date/types/index.d.ts +2 -2
  279. package/dist/date/types/serializedTheDate.d.ts +1 -0
  280. package/dist/date/types/serializedTheTime.d.ts +42 -0
  281. package/dist/date/types/spoolingDate.d.ts +2 -1
  282. package/dist/date/yesterday.cjs +2 -1
  283. package/dist/date/yesterday.d.ts +12 -7
  284. package/dist/date/yesterday.mjs +2 -1
  285. package/dist/generator/asyncGroup.cjs +31 -0
  286. package/dist/generator/asyncGroup.d.ts +39 -0
  287. package/dist/generator/asyncGroup.mjs +29 -0
  288. package/dist/generator/group.cjs +39 -0
  289. package/dist/generator/group.d.ts +101 -0
  290. package/dist/generator/group.mjs +36 -0
  291. package/dist/generator/index.cjs +5 -0
  292. package/dist/generator/index.d.ts +3 -0
  293. package/dist/generator/index.mjs +2 -0
  294. package/dist/index.cjs +7 -6
  295. package/dist/index.mjs +2 -3
  296. package/dist/metadata.json +94 -40
  297. package/dist/object/entries.cjs +7 -2
  298. package/dist/object/entries.mjs +7 -2
  299. package/dist/object/keys.cjs +7 -2
  300. package/dist/object/keys.d.ts +1 -1
  301. package/dist/object/keys.mjs +7 -2
  302. package/package.json +1 -1
  303. package/dist/common/toJSON.cjs +0 -37
  304. package/dist/common/toJSON.d.ts +0 -44
  305. package/dist/common/toJSON.mjs +0 -35
  306. package/dist/common/toString.cjs +0 -10
  307. package/dist/common/toString.d.ts +0 -17
  308. package/dist/common/toString.mjs +0 -8
  309. package/dist/common/toTransform.cjs +0 -37
  310. package/dist/common/toTransform.d.ts +0 -50
  311. package/dist/common/toTransform.mjs +0 -35
  312. package/dist/date/createTheDate.cjs +0 -13
  313. package/dist/date/createTheDate.d.ts +0 -28
  314. package/dist/date/createTheDate.mjs +0 -11
  315. package/dist/date/createTheTime.cjs +0 -13
  316. package/dist/date/createTheTime.d.ts +0 -25
  317. package/dist/date/createTheTime.mjs +0 -11
  318. package/dist/date/types/theDate.d.ts +0 -11
  319. package/dist/date/types/theTime.d.ts +0 -10
@@ -0,0 +1,39 @@
1
+ import type { MaybePromise } from "../common";
2
+ import { type GroupFunctionOutput, type GroupFunctionParams, type GroupResult } from "./group";
3
+ /**
4
+ * Groups elements from an async iterable into an object by a group name.
5
+ *
6
+ * **Supported call styles:**
7
+ * - Classic: `asyncGroup(asyncIterator, theFunction)` → returns a promise of grouped object
8
+ * - Curried: `asyncGroup(theFunction)` → returns a function waiting for the async iterator
9
+ *
10
+ * Behavior:
11
+ * - The function receives `(element, { index, output })`
12
+ * - `theFunction` can return a value or a promise of value
13
+ * - `output` is `groupOutput` and returns `{ group, value }`
14
+ * - The input async iterator is not mutated
15
+ *
16
+ * ```ts
17
+ * const asyncValues = (async function *() {
18
+ * yield Promise.resolve(1);
19
+ * yield 2;
20
+ * yield 3;
21
+ * yield 4;
22
+ * })();
23
+ *
24
+ * await G.asyncGroup(
25
+ * asyncValues,
26
+ * (value, { output }) => output(value % 2 ? "odd" : "even", value),
27
+ * );
28
+ * // { odd: [1, 3], even: [2, 4] }
29
+ * ```
30
+ *
31
+ * @see [`G.group`](https://utils.duplojs.dev/en/v1/api/generator/group) For sync iterables
32
+ * @see [`G.groupOutput`](https://utils.duplojs.dev/en/v1/api/generator/groupOutput) For creating group outputs
33
+ * @see https://utils.duplojs.dev/en/v1/api/generator/asyncGroup
34
+ *
35
+ * @namespace G
36
+ *
37
+ */
38
+ export declare function asyncGroup<GenericElement extends unknown, GenericOutput extends GroupFunctionOutput>(theFunction: (element: GenericElement, params: GroupFunctionParams) => MaybePromise<GenericOutput>): (asyncIterator: AsyncIterable<GenericElement>) => Promise<GroupResult<GenericOutput>>;
39
+ export declare function asyncGroup<GenericElement extends unknown, GenericOutput extends GroupFunctionOutput>(asyncIterator: AsyncIterable<GenericElement>, theFunction: (element: GenericElement, params: GroupFunctionParams) => MaybePromise<GenericOutput>): Promise<GroupResult<GenericOutput>>;
@@ -0,0 +1,29 @@
1
+ import { groupOutput } from './group.mjs';
2
+
3
+ function asyncGroup(...args) {
4
+ if (args.length === 1) {
5
+ const [theFunction] = args;
6
+ return (asyncIterator) => asyncGroup(asyncIterator, theFunction);
7
+ }
8
+ const [asyncIterator, theFunction] = args;
9
+ const result = {};
10
+ let index = 0;
11
+ return (async () => {
12
+ for await (const element of asyncIterator) {
13
+ const { group, value } = await theFunction(element, {
14
+ index,
15
+ output: groupOutput,
16
+ });
17
+ if (result[group]) {
18
+ result[group].push(value);
19
+ }
20
+ else {
21
+ result[group] = [value];
22
+ }
23
+ index++;
24
+ }
25
+ return result;
26
+ })();
27
+ }
28
+
29
+ export { asyncGroup };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ function groupOutput(...args) {
4
+ if (args.length === 1) {
5
+ const [group] = args;
6
+ return (input) => groupOutput(group, input);
7
+ }
8
+ const [group, value] = args;
9
+ return {
10
+ group,
11
+ value,
12
+ };
13
+ }
14
+ function group(...args) {
15
+ if (args.length === 1) {
16
+ const [theFunction] = args;
17
+ return (iterator) => group(iterator, theFunction);
18
+ }
19
+ const [iterator, theFunction] = args;
20
+ const result = {};
21
+ let index = 0;
22
+ for (const element of iterator) {
23
+ const { group, value } = theFunction(element, {
24
+ index,
25
+ output: groupOutput,
26
+ });
27
+ if (result[group]) {
28
+ result[group].push(value);
29
+ }
30
+ else {
31
+ result[group] = [value];
32
+ }
33
+ index++;
34
+ }
35
+ return result;
36
+ }
37
+
38
+ exports.group = group;
39
+ exports.groupOutput = groupOutput;
@@ -0,0 +1,101 @@
1
+ import type { SimplifyTopLevel } from "../common";
2
+ export interface GroupFunctionOutput<GenericGroupName extends string = string, GenericGroupValue extends unknown = unknown> {
3
+ group: GenericGroupName;
4
+ value: GenericGroupValue;
5
+ }
6
+ /**
7
+ * Creates a group output object for `group` and `asyncGroup`.
8
+ *
9
+ * **Supported call styles:**
10
+ * - Classic: `groupOutput(group, value)` → returns a group output
11
+ * - Curried: `groupOutput(group)` → returns a function waiting for the value
12
+ *
13
+ * Behavior:
14
+ * - The returned object always has `{ group, value }`
15
+ * - The `group` name is preserved as a string literal when possible
16
+ *
17
+ * ```ts
18
+ * G.groupOutput(
19
+ * "even",
20
+ * 2,
21
+ * ); // { group: "even", value: 2 }
22
+ *
23
+ * pipe(
24
+ * "alpha",
25
+ * G.groupOutput("word"),
26
+ * ); // { group: "word", value: "alpha" }
27
+ *
28
+ * G.groupOutput(
29
+ * "status",
30
+ * {
31
+ * ok: true,
32
+ * },
33
+ * ); // { group: "status", value: { ok: true } }
34
+ * ```
35
+ *
36
+ * @see [`G.group`](https://utils.duplojs.dev/en/v1/api/generator/group) For grouping sync iterables
37
+ * @see [`G.asyncGroup`](https://utils.duplojs.dev/en/v1/api/generator/asyncGroup) For grouping async iterables
38
+ * @see https://utils.duplojs.dev/en/v1/api/generator/groupOutput
39
+ *
40
+ * @namespace G
41
+ *
42
+ */
43
+ export declare function groupOutput<const GenericGroupName extends string, GenericGroupValue extends unknown>(group: GenericGroupName): (value: GenericGroupValue) => GroupFunctionOutput<GenericGroupName, GenericGroupValue>;
44
+ export declare function groupOutput<const GenericGroupName extends string, GenericGroupValue extends unknown>(group: GenericGroupName, value: GenericGroupValue): GroupFunctionOutput<GenericGroupName, GenericGroupValue>;
45
+ export interface GroupFunctionParams {
46
+ index: number;
47
+ output: typeof groupOutput;
48
+ }
49
+ export type GroupResult<GenericOutput extends GroupFunctionOutput> = SimplifyTopLevel<{
50
+ [Output in GenericOutput as Output["group"]]?: Output["value"][];
51
+ }>;
52
+ /**
53
+ * Groups elements from an iterable into an object by a group name.
54
+ *
55
+ * **Supported call styles:**
56
+ * - Classic: `group(iterator, theFunction)` → returns a grouped object
57
+ * - Curried: `group(theFunction)` → returns a function waiting for the iterator
58
+ *
59
+ * Behavior:
60
+ * - The function receives `(element, { index, output })`
61
+ * - `output` is `groupOutput` and returns `{ group, value }`
62
+ * - The input iterator is not mutated
63
+ *
64
+ * ```ts
65
+ * G.group(
66
+ * [1, 2, 3, 4],
67
+ * (value, { output }) => output(value % 2 ? "odd" : "even", value),
68
+ * );
69
+ * // { odd: [1, 3], even: [2, 4] }
70
+ *
71
+ * pipe(
72
+ * new Set(["alpha", "beta", "gamma"]),
73
+ * G.group((value, { index, output }) => output(
74
+ * "entry",
75
+ * {
76
+ * index,
77
+ * value,
78
+ * },
79
+ * )),
80
+ * );
81
+ * // { entry: [{ index: 0, value: "alpha" }, ...] }
82
+ *
83
+ * G.group(
84
+ * ["apple", "pear", "plum"],
85
+ * (value, { output }) => output(
86
+ * value.startsWith("p") ? "startsWithP" : "other",
87
+ * value.length,
88
+ * ),
89
+ * );
90
+ * // { startsWithP: [5, 4, 4] }
91
+ * ```
92
+ *
93
+ * @see [`G.groupOutput`](https://utils.duplojs.dev/en/v1/api/generator/groupOutput) For creating group outputs
94
+ * @see [`G.asyncGroup`](https://utils.duplojs.dev/en/v1/api/generator/asyncGroup) For async iterables
95
+ * @see https://utils.duplojs.dev/en/v1/api/generator/group
96
+ *
97
+ * @namespace G
98
+ *
99
+ */
100
+ export declare function group<GenericElement extends unknown, GenericOutput extends GroupFunctionOutput>(theFunction: (element: GenericElement, params: GroupFunctionParams) => GenericOutput): (iterator: Iterable<GenericElement>) => GroupResult<GenericOutput>;
101
+ export declare function group<GenericElement extends unknown, GenericOutput extends GroupFunctionOutput>(iterator: Iterable<GenericElement>, theFunction: (element: GenericElement, params: GroupFunctionParams) => GenericOutput): GroupResult<GenericOutput>;
@@ -0,0 +1,36 @@
1
+ function groupOutput(...args) {
2
+ if (args.length === 1) {
3
+ const [group] = args;
4
+ return (input) => groupOutput(group, input);
5
+ }
6
+ const [group, value] = args;
7
+ return {
8
+ group,
9
+ value,
10
+ };
11
+ }
12
+ function group(...args) {
13
+ if (args.length === 1) {
14
+ const [theFunction] = args;
15
+ return (iterator) => group(iterator, theFunction);
16
+ }
17
+ const [iterator, theFunction] = args;
18
+ const result = {};
19
+ let index = 0;
20
+ for (const element of iterator) {
21
+ const { group, value } = theFunction(element, {
22
+ index,
23
+ output: groupOutput,
24
+ });
25
+ if (result[group]) {
26
+ result[group].push(value);
27
+ }
28
+ else {
29
+ result[group] = [value];
30
+ }
31
+ index++;
32
+ }
33
+ return result;
34
+ }
35
+
36
+ export { group, groupOutput };
@@ -11,6 +11,8 @@ var loop = require('./loop.cjs');
11
11
  var asyncLoop = require('./asyncLoop.cjs');
12
12
  var chunk = require('./chunk.cjs');
13
13
  var asyncChunk = require('./asyncChunk.cjs');
14
+ var group = require('./group.cjs');
15
+ var asyncGroup = require('./asyncGroup.cjs');
14
16
 
15
17
  /**
16
18
  * {@include generator/index.md}
@@ -28,3 +30,6 @@ exports.loop = loop.loop;
28
30
  exports.asyncLoop = asyncLoop.asyncLoop;
29
31
  exports.chunk = chunk.chunk;
30
32
  exports.asyncChunk = asyncChunk.asyncChunk;
33
+ exports.group = group.group;
34
+ exports.groupOutput = group.groupOutput;
35
+ exports.asyncGroup = asyncGroup.asyncGroup;
@@ -17,6 +17,7 @@
17
17
  * - reduce helpers (`G.reduceFrom`)
18
18
  * - control and execution (`G.loop`, `G.execute`)
19
19
  * - batching (`G.chunk`)
20
+ * - grouping (`G.group`, `G.groupOutput`, `G.asyncGroup`)
20
21
  * - async variants (`G.asyncMap`, `G.asyncFilter`, `G.asyncReduce`, `G.asyncLoop`, `G.asyncChunk`)
21
22
  *
22
23
  * @see https://utils.duplojs.dev/en/v1/api/generator
@@ -35,3 +36,5 @@ export * from "./loop";
35
36
  export * from "./asyncLoop";
36
37
  export * from "./chunk";
37
38
  export * from "./asyncChunk";
39
+ export * from "./group";
40
+ export * from "./asyncGroup";
@@ -9,6 +9,8 @@ export { loop } from './loop.mjs';
9
9
  export { asyncLoop } from './asyncLoop.mjs';
10
10
  export { chunk } from './chunk.mjs';
11
11
  export { asyncChunk } from './asyncChunk.mjs';
12
+ export { group, groupOutput } from './group.mjs';
13
+ export { asyncGroup } from './asyncGroup.mjs';
12
14
 
13
15
  /**
14
16
  * {@include generator/index.md}
package/dist/index.cjs CHANGED
@@ -27,15 +27,12 @@ var sleep = require('./common/sleep.cjs');
27
27
  var stringToBytes = require('./common/stringToBytes.cjs');
28
28
  var mimeType = require('./common/mimeType.cjs');
29
29
  var stringToMillisecond = require('./common/stringToMillisecond.cjs');
30
- var toJSON = require('./common/toJSON.cjs');
31
- var toTransform = require('./common/toTransform.cjs');
32
30
  var toWrappedValue = require('./common/toWrappedValue.cjs');
33
31
  var unwrap = require('./common/unwrap.cjs');
34
32
  var unwrapGroup = require('./common/unwrapGroup.cjs');
35
33
  var asyncLoop = require('./common/asyncLoop.cjs');
36
34
  var asyncRetry = require('./common/asyncRetry.cjs');
37
35
  var wrapValue = require('./common/wrapValue.cjs');
38
- var toString = require('./common/toString.cjs');
39
36
  var innerPipe = require('./common/innerPipe.cjs');
40
37
  var asyncInnerPipe = require('./common/asyncInnerPipe.cjs');
41
38
  var loop = require('./common/loop.cjs');
@@ -65,6 +62,8 @@ var toCurriedPredicate = require('./common/toCurriedPredicate.cjs');
65
62
  var pipeCall = require('./common/pipeCall.cjs');
66
63
  var asserts = require('./common/asserts.cjs');
67
64
  var path = require('./common/path.cjs');
65
+ var transformer = require('./common/transformer.cjs');
66
+ var toRegExp = require('./common/toRegExp.cjs');
68
67
 
69
68
 
70
69
 
@@ -113,8 +112,6 @@ exports.stringToBytes = stringToBytes.stringToBytes;
113
112
  exports.mimeType = mimeType.mimeType;
114
113
  exports.InvalidMillisecondInStringError = stringToMillisecond.InvalidMillisecondInStringError;
115
114
  exports.stringToMillisecond = stringToMillisecond.stringToMillisecond;
116
- exports.toJSON = toJSON.toJSON;
117
- exports.toTransform = toTransform.toTransform;
118
115
  exports.toWrappedValue = toWrappedValue.toWrappedValue;
119
116
  exports.unwrap = unwrap.unwrap;
120
117
  exports.unwrapGroup = unwrapGroup.unwrapGroup;
@@ -125,7 +122,6 @@ exports.isRuntimeWrappedValueKey = wrapValue.isRuntimeWrappedValueKey;
125
122
  exports.isWrappedValue = wrapValue.isWrappedValue;
126
123
  exports.keyWrappedValue = wrapValue.keyWrappedValue;
127
124
  exports.wrapValue = wrapValue.wrapValue;
128
- exports.toString = toString.toString;
129
125
  exports.innerPipe = innerPipe.innerPipe;
130
126
  exports.asyncInnerPipe = asyncInnerPipe.asyncInnerPipe;
131
127
  exports.loop = loop.loop;
@@ -161,3 +157,8 @@ Object.defineProperty(exports, "Path", {
161
157
  enumerable: true,
162
158
  get: function () { return path.Path; }
163
159
  });
160
+ exports.createTransformer = transformer.createTransformer;
161
+ exports.toJSON = transformer.toJSON;
162
+ exports.toNative = transformer.toNative;
163
+ exports.transformer = transformer.transformer;
164
+ exports.toRegExp = toRegExp.toRegExp;
package/dist/index.mjs CHANGED
@@ -49,15 +49,12 @@ export { sleep } from './common/sleep.mjs';
49
49
  export { InvalidBytesInStringError, stringToBytes } from './common/stringToBytes.mjs';
50
50
  export { mimeType } from './common/mimeType.mjs';
51
51
  export { InvalidMillisecondInStringError, stringToMillisecond } from './common/stringToMillisecond.mjs';
52
- export { toJSON } from './common/toJSON.mjs';
53
- export { toTransform } from './common/toTransform.mjs';
54
52
  export { toWrappedValue } from './common/toWrappedValue.mjs';
55
53
  export { unwrap } from './common/unwrap.mjs';
56
54
  export { unwrapGroup } from './common/unwrapGroup.mjs';
57
55
  export { asyncLoop } from './common/asyncLoop.mjs';
58
56
  export { createAsyncRetry, useAsyncRetry } from './common/asyncRetry.mjs';
59
57
  export { isRuntimeWrappedValueKey, isWrappedValue, keyWrappedValue, wrapValue } from './common/wrapValue.mjs';
60
- export { toString } from './common/toString.mjs';
61
58
  export { innerPipe } from './common/innerPipe.mjs';
62
59
  export { asyncInnerPipe } from './common/asyncInnerPipe.mjs';
63
60
  export { loop } from './common/loop.mjs';
@@ -87,3 +84,5 @@ export { toCurriedPredicate } from './common/toCurriedPredicate.mjs';
87
84
  export { pipeCall } from './common/pipeCall.mjs';
88
85
  export { AssertsError, asserts } from './common/asserts.mjs';
89
86
  export { Path } from './common/path.mjs';
87
+ export { createTransformer, toJSON, toNative, transformer } from './common/transformer.mjs';
88
+ export { toRegExp } from './common/toRegExp.mjs';
@@ -612,6 +612,15 @@
612
612
  },
613
613
  {
614
614
  "name": "string.mjs"
615
+ },
616
+ {
617
+ "name": "time.cjs"
618
+ },
619
+ {
620
+ "name": "time.d.ts"
621
+ },
622
+ {
623
+ "name": "time.mjs"
615
624
  }
616
625
  ]
617
626
  },
@@ -1551,40 +1560,31 @@
1551
1560
  "name": "toCurriedPredicate.mjs"
1552
1561
  },
1553
1562
  {
1554
- "name": "toJSON.cjs"
1563
+ "name": "toRegExp.cjs"
1555
1564
  },
1556
1565
  {
1557
- "name": "toJSON.d.ts"
1566
+ "name": "toRegExp.d.ts"
1558
1567
  },
1559
1568
  {
1560
- "name": "toJSON.mjs"
1569
+ "name": "toRegExp.mjs"
1561
1570
  },
1562
1571
  {
1563
- "name": "toString.cjs"
1564
- },
1565
- {
1566
- "name": "toString.d.ts"
1567
- },
1568
- {
1569
- "name": "toString.mjs"
1572
+ "name": "toWrappedValue.cjs"
1570
1573
  },
1571
1574
  {
1572
- "name": "toTransform.cjs"
1575
+ "name": "toWrappedValue.d.ts"
1573
1576
  },
1574
1577
  {
1575
- "name": "toTransform.d.ts"
1578
+ "name": "toWrappedValue.mjs"
1576
1579
  },
1577
1580
  {
1578
- "name": "toTransform.mjs"
1581
+ "name": "transformer.cjs"
1579
1582
  },
1580
1583
  {
1581
- "name": "toWrappedValue.cjs"
1584
+ "name": "transformer.d.ts"
1582
1585
  },
1583
1586
  {
1584
- "name": "toWrappedValue.d.ts"
1585
- },
1586
- {
1587
- "name": "toWrappedValue.mjs"
1587
+ "name": "transformer.mjs"
1588
1588
  },
1589
1589
  {
1590
1590
  "name": "truthy.cjs"
@@ -3032,16 +3032,16 @@
3032
3032
  "name": "month.d.ts"
3033
3033
  },
3034
3034
  {
3035
- "name": "spoolingDate.d.ts"
3035
+ "name": "serializedTheDate.d.ts"
3036
3036
  },
3037
3037
  {
3038
- "name": "spoolingTime.d.ts"
3038
+ "name": "serializedTheTime.d.ts"
3039
3039
  },
3040
3040
  {
3041
- "name": "theDate.d.ts"
3041
+ "name": "spoolingDate.d.ts"
3042
3042
  },
3043
3043
  {
3044
- "name": "theTime.d.ts"
3044
+ "name": "spoolingTime.d.ts"
3045
3045
  },
3046
3046
  {
3047
3047
  "name": "time.d.ts"
@@ -3096,24 +3096,6 @@
3096
3096
  {
3097
3097
  "name": "createOrThrow.mjs"
3098
3098
  },
3099
- {
3100
- "name": "createTheDate.cjs"
3101
- },
3102
- {
3103
- "name": "createTheDate.d.ts"
3104
- },
3105
- {
3106
- "name": "createTheDate.mjs"
3107
- },
3108
- {
3109
- "name": "createTheTime.cjs"
3110
- },
3111
- {
3112
- "name": "createTheTime.d.ts"
3113
- },
3114
- {
3115
- "name": "createTheTime.mjs"
3116
- },
3117
3099
  {
3118
3100
  "name": "createTime.cjs"
3119
3101
  },
@@ -3204,6 +3186,24 @@
3204
3186
  {
3205
3187
  "name": "isSafeTimeValue.mjs"
3206
3188
  },
3189
+ {
3190
+ "name": "isSerializedTheDate.cjs"
3191
+ },
3192
+ {
3193
+ "name": "isSerializedTheDate.d.ts"
3194
+ },
3195
+ {
3196
+ "name": "isSerializedTheDate.mjs"
3197
+ },
3198
+ {
3199
+ "name": "isSerializedTheTime.cjs"
3200
+ },
3201
+ {
3202
+ "name": "isSerializedTheTime.d.ts"
3203
+ },
3204
+ {
3205
+ "name": "isSerializedTheTime.mjs"
3206
+ },
3207
3207
  {
3208
3208
  "name": "isTime.cjs"
3209
3209
  },
@@ -3213,6 +3213,15 @@
3213
3213
  {
3214
3214
  "name": "isTime.mjs"
3215
3215
  },
3216
+ {
3217
+ "name": "kind.cjs"
3218
+ },
3219
+ {
3220
+ "name": "kind.d.ts"
3221
+ },
3222
+ {
3223
+ "name": "kind.mjs"
3224
+ },
3216
3225
  {
3217
3226
  "name": "makeSafeTimestamp.cjs"
3218
3227
  },
@@ -3285,6 +3294,15 @@
3285
3294
  {
3286
3295
  "name": "round.mjs"
3287
3296
  },
3297
+ {
3298
+ "name": "serialize.cjs"
3299
+ },
3300
+ {
3301
+ "name": "serialize.d.ts"
3302
+ },
3303
+ {
3304
+ "name": "serialize.mjs"
3305
+ },
3288
3306
  {
3289
3307
  "name": "sort.cjs"
3290
3308
  },
@@ -3303,6 +3321,24 @@
3303
3321
  {
3304
3322
  "name": "sortTimes.mjs"
3305
3323
  },
3324
+ {
3325
+ "name": "theDate.cjs"
3326
+ },
3327
+ {
3328
+ "name": "theDate.d.ts"
3329
+ },
3330
+ {
3331
+ "name": "theDate.mjs"
3332
+ },
3333
+ {
3334
+ "name": "theTime.cjs"
3335
+ },
3336
+ {
3337
+ "name": "theTime.d.ts"
3338
+ },
3339
+ {
3340
+ "name": "theTime.mjs"
3341
+ },
3306
3342
  {
3307
3343
  "name": "timezone.cjs"
3308
3344
  },
@@ -3813,6 +3849,15 @@
3813
3849
  {
3814
3850
  "name": "asyncFilter.mjs"
3815
3851
  },
3852
+ {
3853
+ "name": "asyncGroup.cjs"
3854
+ },
3855
+ {
3856
+ "name": "asyncGroup.d.ts"
3857
+ },
3858
+ {
3859
+ "name": "asyncGroup.mjs"
3860
+ },
3816
3861
  {
3817
3862
  "name": "asyncLoop.cjs"
3818
3863
  },
@@ -3867,6 +3912,15 @@
3867
3912
  {
3868
3913
  "name": "filter.mjs"
3869
3914
  },
3915
+ {
3916
+ "name": "group.cjs"
3917
+ },
3918
+ {
3919
+ "name": "group.d.ts"
3920
+ },
3921
+ {
3922
+ "name": "group.mjs"
3923
+ },
3870
3924
  {
3871
3925
  "name": "index.cjs"
3872
3926
  },
@@ -7,8 +7,13 @@ var kind = require('../common/kind.cjs');
7
7
  * {@include object/entries/index.md}
8
8
  */
9
9
  function entries(object) {
10
- return Object.entries(object)
11
- .filter(([key]) => !wrapValue.isRuntimeWrappedValueKey(key) && !kind.isRuntimeKind(key));
10
+ const result = [];
11
+ for (const key in object) {
12
+ if (!wrapValue.isRuntimeWrappedValueKey(key) && !kind.isRuntimeKind(key)) {
13
+ result.push([key, object[key]]);
14
+ }
15
+ }
16
+ return result;
12
17
  }
13
18
  /**
14
19
  * @deprecated Not ignore kind key.
@@ -5,8 +5,13 @@ import { isRuntimeKind } from '../common/kind.mjs';
5
5
  * {@include object/entries/index.md}
6
6
  */
7
7
  function entries(object) {
8
- return Object.entries(object)
9
- .filter(([key]) => !isRuntimeWrappedValueKey(key) && !isRuntimeKind(key));
8
+ const result = [];
9
+ for (const key in object) {
10
+ if (!isRuntimeWrappedValueKey(key) && !isRuntimeKind(key)) {
11
+ result.push([key, object[key]]);
12
+ }
13
+ }
14
+ return result;
10
15
  }
11
16
  /**
12
17
  * @deprecated Not ignore kind key.
@@ -7,8 +7,13 @@ var kind = require('../common/kind.cjs');
7
7
  * {@include object/keys/index.md}
8
8
  */
9
9
  function keys(object) {
10
- return Object.keys(object)
11
- .filter((key) => !wrapValue.isRuntimeWrappedValueKey(key) && !kind.isRuntimeKind(key));
10
+ const result = [];
11
+ for (const key in object) {
12
+ if (!wrapValue.isRuntimeWrappedValueKey(key) && !kind.isRuntimeKind(key)) {
13
+ result.push(key);
14
+ }
15
+ }
16
+ return result;
12
17
  }
13
18
 
14
19
  exports.keys = keys;
@@ -31,4 +31,4 @@
31
31
  * @namespace O
32
32
  *
33
33
  */
34
- export declare function keys<GenericObject extends object>(object: GenericObject): (Exclude<keyof GenericObject, symbol>)[];
34
+ export declare function keys<GenericObject extends object>(object: GenericObject): (`${Exclude<keyof GenericObject, symbol>}`)[];
@@ -5,8 +5,13 @@ import { isRuntimeKind } from '../common/kind.mjs';
5
5
  * {@include object/keys/index.md}
6
6
  */
7
7
  function keys(object) {
8
- return Object.keys(object)
9
- .filter((key) => !isRuntimeWrappedValueKey(key) && !isRuntimeKind(key));
8
+ const result = [];
9
+ for (const key in object) {
10
+ if (!isRuntimeWrappedValueKey(key) && !isRuntimeKind(key)) {
11
+ result.push(key);
12
+ }
13
+ }
14
+ return result;
10
15
  }
11
16
 
12
17
  export { keys };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/utils",
3
- "version": "1.4.57",
3
+ "version": "1.4.59",
4
4
  "author": {
5
5
  "name": "mathcovax",
6
6
  "url": "https://github.com/mathcovax"