@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.
- package/dist/array/group.cjs +11 -11
- package/dist/array/group.d.ts +1 -1
- package/dist/array/group.mjs +11 -11
- package/dist/clean/constraint/base.d.ts +6 -4
- package/dist/clean/constraint/defaultConstraint/index.d.ts +1 -0
- package/dist/clean/constraint/defaultConstraint/number.d.ts +6 -6
- package/dist/clean/constraint/defaultConstraint/string.d.ts +4 -4
- package/dist/clean/constraint/defaultConstraint/time.cjs +19 -0
- package/dist/clean/constraint/defaultConstraint/time.d.ts +61 -0
- package/dist/clean/constraint/defaultConstraint/time.mjs +16 -0
- package/dist/clean/constraint/set.d.ts +6 -4
- package/dist/clean/entity.d.ts +2 -1
- package/dist/clean/index.cjs +3 -0
- package/dist/clean/index.mjs +1 -0
- package/dist/clean/newType.d.ts +7 -5
- package/dist/clean/primitive/base.d.ts +25 -34
- package/dist/clean/primitive/operations/date/dateAddTime.d.ts +7 -11
- package/dist/clean/primitive/operations/date/dateGreaterThan.d.ts +9 -7
- package/dist/clean/primitive/operations/date/dateLessThan.d.ts +9 -7
- package/dist/clean/primitive/operations/date/dateMax.d.ts +3 -10
- package/dist/clean/primitive/operations/date/dateMin.d.ts +3 -10
- package/dist/clean/primitive/operations/date/dateSubtractTime.d.ts +7 -11
- package/dist/clean/primitive/operations/equal.cjs +1 -1
- package/dist/clean/primitive/operations/equal.d.ts +3 -3
- package/dist/clean/primitive/operations/equal.mjs +1 -1
- package/dist/clean/primitive/operations/sort.d.ts +8 -10
- package/dist/clean/primitive/operations/time/timeGreaterThan.d.ts +11 -9
- package/dist/clean/primitive/operations/time/timeLessThan.d.ts +11 -9
- package/dist/clean/primitive/operations/time/timeMax.cjs +2 -2
- package/dist/clean/primitive/operations/time/timeMax.d.ts +10 -17
- package/dist/clean/primitive/operations/time/timeMax.mjs +2 -2
- package/dist/clean/primitive/operations/time/timeMin.cjs +3 -3
- package/dist/clean/primitive/operations/time/timeMin.d.ts +10 -17
- package/dist/clean/primitive/operations/time/timeMin.mjs +3 -3
- package/dist/clean/unwrapEntity.cjs +13 -3
- package/dist/clean/unwrapEntity.d.ts +57 -5
- package/dist/clean/unwrapEntity.mjs +13 -3
- package/dist/common/index.d.ts +3 -4
- package/dist/common/kind.d.ts +1 -0
- package/dist/common/path.cjs +13 -13
- package/dist/common/path.d.ts +17 -11
- package/dist/common/path.mjs +13 -13
- package/dist/common/toRegExp.cjs +19 -0
- package/dist/common/toRegExp.d.ts +31 -0
- package/dist/common/toRegExp.mjs +17 -0
- package/dist/common/transformer.cjs +45 -0
- package/dist/common/transformer.d.ts +61 -0
- package/dist/common/transformer.mjs +40 -0
- package/dist/common/types/DeepReadonly.d.ts +1 -1
- package/dist/common/types/toLargeEnsemble.d.ts +2 -2
- package/dist/dataParser/error.cjs +4 -2
- package/dist/dataParser/error.d.ts +4 -2
- package/dist/dataParser/error.mjs +4 -2
- package/dist/dataParser/extended/date.d.ts +9 -4
- package/dist/dataParser/extended/time.d.ts +28 -12
- package/dist/dataParser/identifier.d.ts +20 -8
- package/dist/dataParser/parsers/date.cjs +16 -12
- package/dist/dataParser/parsers/date.d.ts +15 -9
- package/dist/dataParser/parsers/date.mjs +16 -12
- package/dist/dataParser/parsers/time/checkers/max.cjs +3 -0
- package/dist/dataParser/parsers/time/checkers/max.d.ts +28 -0
- package/dist/dataParser/parsers/time/checkers/max.mjs +3 -0
- package/dist/dataParser/parsers/time/checkers/min.cjs +3 -0
- package/dist/dataParser/parsers/time/checkers/min.d.ts +28 -0
- package/dist/dataParser/parsers/time/checkers/min.mjs +3 -0
- package/dist/dataParser/parsers/time/index.cjs +14 -10
- package/dist/dataParser/parsers/time/index.d.ts +15 -9
- package/dist/dataParser/parsers/time/index.mjs +14 -10
- package/dist/date/applyTimezone.cjs +4 -4
- package/dist/date/applyTimezone.d.ts +18 -16
- package/dist/date/applyTimezone.mjs +2 -2
- package/dist/date/closestTo.cjs +6 -2
- package/dist/date/closestTo.d.ts +15 -15
- package/dist/date/closestTo.mjs +6 -2
- package/dist/date/constants.cjs +4 -4
- package/dist/date/constants.d.ts +2 -2
- package/dist/date/constants.mjs +3 -3
- package/dist/date/create.cjs +20 -10
- package/dist/date/create.d.ts +24 -38
- package/dist/date/create.mjs +21 -11
- package/dist/date/createOrThrow.d.ts +18 -20
- package/dist/date/createTime.cjs +16 -7
- package/dist/date/createTime.d.ts +19 -18
- package/dist/date/createTime.mjs +17 -8
- package/dist/date/createTimeOrThrow.d.ts +17 -20
- package/dist/date/each.cjs +6 -4
- package/dist/date/each.d.ts +21 -19
- package/dist/date/each.mjs +6 -4
- package/dist/date/format.d.ts +17 -15
- package/dist/date/formatTime.d.ts +17 -16
- package/dist/date/getTimezoneOffset.cjs +6 -3
- package/dist/date/getTimezoneOffset.d.ts +17 -18
- package/dist/date/getTimezoneOffset.mjs +6 -3
- package/dist/date/getters/getDayOfMonth.cjs +3 -3
- package/dist/date/getters/getDayOfMonth.d.ts +20 -14
- package/dist/date/getters/getDayOfMonth.mjs +3 -3
- package/dist/date/getters/getDayOfWeek.cjs +3 -3
- package/dist/date/getters/getDayOfWeek.d.ts +15 -12
- package/dist/date/getters/getDayOfWeek.mjs +3 -3
- package/dist/date/getters/getDayOfYear.cjs +6 -6
- package/dist/date/getters/getDayOfYear.d.ts +21 -13
- package/dist/date/getters/getDayOfYear.mjs +6 -6
- package/dist/date/getters/getFirstDayOfMonth.cjs +2 -3
- package/dist/date/getters/getFirstDayOfMonth.d.ts +16 -10
- package/dist/date/getters/getFirstDayOfMonth.mjs +2 -3
- package/dist/date/getters/getFirstDayOfWeek.cjs +2 -3
- package/dist/date/getters/getFirstDayOfWeek.d.ts +17 -10
- package/dist/date/getters/getFirstDayOfWeek.mjs +2 -3
- package/dist/date/getters/getHour.cjs +3 -3
- package/dist/date/getters/getHour.d.ts +16 -14
- package/dist/date/getters/getHour.mjs +3 -3
- package/dist/date/getters/getLastDayOfMonth.cjs +2 -3
- package/dist/date/getters/getLastDayOfMonth.d.ts +16 -10
- package/dist/date/getters/getLastDayOfMonth.mjs +2 -3
- package/dist/date/getters/getLastDayOfWeek.cjs +2 -3
- package/dist/date/getters/getLastDayOfWeek.d.ts +17 -10
- package/dist/date/getters/getLastDayOfWeek.mjs +2 -3
- package/dist/date/getters/getMilliseconds.cjs +2 -2
- package/dist/date/getters/getMilliseconds.d.ts +11 -9
- package/dist/date/getters/getMilliseconds.mjs +2 -2
- package/dist/date/getters/getMinute.cjs +3 -3
- package/dist/date/getters/getMinute.d.ts +17 -15
- package/dist/date/getters/getMinute.mjs +3 -3
- package/dist/date/getters/getMonth.cjs +3 -3
- package/dist/date/getters/getMonth.d.ts +20 -15
- package/dist/date/getters/getMonth.mjs +3 -3
- package/dist/date/getters/getSecond.cjs +3 -3
- package/dist/date/getters/getSecond.d.ts +17 -15
- package/dist/date/getters/getSecond.mjs +3 -3
- package/dist/date/getters/getWeekOfYear.cjs +12 -11
- package/dist/date/getters/getWeekOfYear.d.ts +17 -11
- package/dist/date/getters/getWeekOfYear.mjs +12 -11
- package/dist/date/getters/getYear.cjs +3 -3
- package/dist/date/getters/getYear.d.ts +16 -15
- package/dist/date/getters/getYear.mjs +3 -3
- package/dist/date/index.cjs +12 -6
- package/dist/date/index.d.ts +5 -2
- package/dist/date/index.mjs +6 -3
- package/dist/date/is.cjs +3 -8
- package/dist/date/is.d.ts +9 -14
- package/dist/date/is.mjs +3 -8
- package/dist/date/isSafeTimeValue.d.ts +9 -13
- package/dist/date/isSafeTimestamp.d.ts +7 -16
- package/dist/date/isSerializedTheDate.cjs +20 -0
- package/dist/date/isSerializedTheDate.d.ts +31 -0
- package/dist/date/isSerializedTheDate.mjs +18 -0
- package/dist/date/isSerializedTheTime.cjs +20 -0
- package/dist/date/isSerializedTheTime.d.ts +31 -0
- package/dist/date/isSerializedTheTime.mjs +18 -0
- package/dist/date/isTime.cjs +3 -8
- package/dist/date/isTime.d.ts +7 -14
- package/dist/date/isTime.mjs +3 -8
- package/dist/date/kind.cjs +9 -0
- package/dist/date/kind.d.ts +1 -0
- package/dist/date/kind.mjs +7 -0
- package/dist/date/makeSafeTimeValue.d.ts +12 -11
- package/dist/date/makeSafeTimestamp.d.ts +12 -11
- package/dist/date/max.cjs +2 -2
- package/dist/date/max.d.ts +13 -13
- package/dist/date/max.mjs +2 -2
- package/dist/date/maxTime.cjs +2 -2
- package/dist/date/maxTime.d.ts +13 -21
- package/dist/date/maxTime.mjs +2 -2
- package/dist/date/min.cjs +2 -2
- package/dist/date/min.d.ts +13 -13
- package/dist/date/min.mjs +2 -2
- package/dist/date/minTime.cjs +2 -2
- package/dist/date/minTime.d.ts +13 -21
- package/dist/date/minTime.mjs +2 -2
- package/dist/date/now.cjs +3 -1
- package/dist/date/now.d.ts +9 -7
- package/dist/date/now.mjs +3 -1
- package/dist/date/operators/addDays.cjs +3 -5
- package/dist/date/operators/addDays.d.ts +14 -11
- package/dist/date/operators/addDays.mjs +3 -5
- package/dist/date/operators/addHours.cjs +3 -5
- package/dist/date/operators/addHours.d.ts +14 -11
- package/dist/date/operators/addHours.mjs +3 -5
- package/dist/date/operators/addMilliseconds.cjs +3 -5
- package/dist/date/operators/addMilliseconds.d.ts +14 -11
- package/dist/date/operators/addMilliseconds.mjs +3 -5
- package/dist/date/operators/addMinutes.cjs +3 -5
- package/dist/date/operators/addMinutes.d.ts +14 -11
- package/dist/date/operators/addMinutes.mjs +3 -5
- package/dist/date/operators/addMonths.cjs +2 -2
- package/dist/date/operators/addMonths.d.ts +13 -13
- package/dist/date/operators/addMonths.mjs +2 -2
- package/dist/date/operators/addSeconds.cjs +3 -5
- package/dist/date/operators/addSeconds.d.ts +14 -11
- package/dist/date/operators/addSeconds.mjs +3 -5
- package/dist/date/operators/addTime.cjs +13 -6
- package/dist/date/operators/addTime.d.ts +20 -18
- package/dist/date/operators/addTime.mjs +13 -6
- package/dist/date/operators/addWeeks.cjs +6 -5
- package/dist/date/operators/addWeeks.d.ts +14 -11
- package/dist/date/operators/addWeeks.mjs +6 -5
- package/dist/date/operators/addYears.cjs +2 -2
- package/dist/date/operators/addYears.d.ts +13 -13
- package/dist/date/operators/addYears.mjs +2 -2
- package/dist/date/operators/between.d.ts +11 -11
- package/dist/date/operators/betweenThan.d.ts +11 -11
- package/dist/date/operators/betweenThanTime.d.ts +18 -22
- package/dist/date/operators/betweenTime.d.ts +17 -21
- package/dist/date/operators/greater.d.ts +12 -9
- package/dist/date/operators/greaterThan.d.ts +14 -11
- package/dist/date/operators/greaterThanTime.d.ts +17 -21
- package/dist/date/operators/greaterTime.d.ts +16 -20
- package/dist/date/operators/less.d.ts +12 -9
- package/dist/date/operators/lessThan.d.ts +13 -10
- package/dist/date/operators/lessThanTime.d.ts +17 -21
- package/dist/date/operators/lessTime.d.ts +16 -20
- package/dist/date/operators/subtractDays.cjs +3 -5
- package/dist/date/operators/subtractDays.d.ts +14 -11
- package/dist/date/operators/subtractDays.mjs +3 -5
- package/dist/date/operators/subtractHours.cjs +3 -5
- package/dist/date/operators/subtractHours.d.ts +14 -11
- package/dist/date/operators/subtractHours.mjs +3 -5
- package/dist/date/operators/subtractMilliseconds.cjs +3 -5
- package/dist/date/operators/subtractMilliseconds.d.ts +14 -11
- package/dist/date/operators/subtractMilliseconds.mjs +3 -5
- package/dist/date/operators/subtractMinutes.cjs +3 -5
- package/dist/date/operators/subtractMinutes.d.ts +14 -11
- package/dist/date/operators/subtractMinutes.mjs +3 -5
- package/dist/date/operators/subtractMonths.cjs +2 -2
- package/dist/date/operators/subtractMonths.d.ts +17 -11
- package/dist/date/operators/subtractMonths.mjs +2 -2
- package/dist/date/operators/subtractSeconds.cjs +3 -5
- package/dist/date/operators/subtractSeconds.d.ts +14 -11
- package/dist/date/operators/subtractSeconds.mjs +3 -5
- package/dist/date/operators/subtractTime.cjs +13 -6
- package/dist/date/operators/subtractTime.d.ts +20 -18
- package/dist/date/operators/subtractTime.mjs +13 -6
- package/dist/date/operators/subtractWeeks.cjs +3 -5
- package/dist/date/operators/subtractWeeks.d.ts +14 -11
- package/dist/date/operators/subtractWeeks.mjs +3 -5
- package/dist/date/operators/subtractYears.cjs +2 -2
- package/dist/date/operators/subtractYears.d.ts +17 -11
- package/dist/date/operators/subtractYears.mjs +2 -2
- package/dist/date/round.cjs +2 -2
- package/dist/date/round.d.ts +11 -14
- package/dist/date/round.mjs +2 -2
- package/dist/date/serialize.cjs +14 -0
- package/dist/date/serialize.d.ts +41 -0
- package/dist/date/serialize.mjs +12 -0
- package/dist/date/sort.cjs +2 -2
- package/dist/date/sort.d.ts +16 -15
- package/dist/date/sort.mjs +2 -2
- package/dist/date/sortTimes.cjs +2 -2
- package/dist/date/sortTimes.d.ts +15 -21
- package/dist/date/sortTimes.mjs +2 -2
- package/dist/date/theDate.cjs +124 -0
- package/dist/date/theDate.d.ts +114 -0
- package/dist/date/theDate.mjs +122 -0
- package/dist/date/theTime.cjs +36 -0
- package/dist/date/theTime.d.ts +53 -0
- package/dist/date/theTime.mjs +34 -0
- package/dist/date/timezone.cjs +3 -0
- package/dist/date/timezone.d.ts +27 -0
- package/dist/date/timezone.mjs +3 -0
- package/dist/date/toISOString.cjs +5 -2
- package/dist/date/toISOString.d.ts +12 -10
- package/dist/date/toISOString.mjs +5 -2
- package/dist/date/toNative.cjs +4 -0
- package/dist/date/toNative.d.ts +12 -10
- package/dist/date/toNative.mjs +4 -0
- package/dist/date/toTimeValue.cjs +6 -2
- package/dist/date/toTimeValue.d.ts +14 -12
- package/dist/date/toTimeValue.mjs +6 -2
- package/dist/date/toTimestamp.cjs +5 -3
- package/dist/date/toTimestamp.d.ts +11 -9
- package/dist/date/toTimestamp.mjs +6 -4
- package/dist/date/today.cjs +3 -1
- package/dist/date/today.d.ts +14 -7
- package/dist/date/today.mjs +3 -1
- package/dist/date/tomorrow.cjs +2 -1
- package/dist/date/tomorrow.d.ts +12 -7
- package/dist/date/tomorrow.mjs +2 -1
- package/dist/date/types/index.d.ts +2 -2
- package/dist/date/types/serializedTheDate.d.ts +1 -0
- package/dist/date/types/serializedTheTime.d.ts +42 -0
- package/dist/date/types/spoolingDate.d.ts +2 -1
- package/dist/date/yesterday.cjs +2 -1
- package/dist/date/yesterday.d.ts +12 -7
- package/dist/date/yesterday.mjs +2 -1
- package/dist/generator/asyncGroup.cjs +31 -0
- package/dist/generator/asyncGroup.d.ts +39 -0
- package/dist/generator/asyncGroup.mjs +29 -0
- package/dist/generator/group.cjs +39 -0
- package/dist/generator/group.d.ts +101 -0
- package/dist/generator/group.mjs +36 -0
- package/dist/generator/index.cjs +5 -0
- package/dist/generator/index.d.ts +3 -0
- package/dist/generator/index.mjs +2 -0
- package/dist/index.cjs +7 -6
- package/dist/index.mjs +2 -3
- package/dist/metadata.json +94 -40
- package/dist/object/entries.cjs +7 -2
- package/dist/object/entries.mjs +7 -2
- package/dist/object/keys.cjs +7 -2
- package/dist/object/keys.d.ts +1 -1
- package/dist/object/keys.mjs +7 -2
- package/package.json +1 -1
- package/dist/common/toJSON.cjs +0 -37
- package/dist/common/toJSON.d.ts +0 -44
- package/dist/common/toJSON.mjs +0 -35
- package/dist/common/toString.cjs +0 -10
- package/dist/common/toString.d.ts +0 -17
- package/dist/common/toString.mjs +0 -8
- package/dist/common/toTransform.cjs +0 -37
- package/dist/common/toTransform.d.ts +0 -50
- package/dist/common/toTransform.mjs +0 -35
- package/dist/date/createTheDate.cjs +0 -13
- package/dist/date/createTheDate.d.ts +0 -28
- package/dist/date/createTheDate.mjs +0 -11
- package/dist/date/createTheTime.cjs +0 -13
- package/dist/date/createTheTime.d.ts +0 -25
- package/dist/date/createTheTime.mjs +0 -11
- package/dist/date/types/theDate.d.ts +0 -11
- package/dist/date/types/theTime.d.ts +0 -10
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import { type Date, type Time } from "../../base";
|
|
2
2
|
import { type TheTime } from "../../../../date";
|
|
3
3
|
/**
|
|
4
|
-
* Adds a
|
|
4
|
+
* Adds a duration to a wrapped `Date` and returns a wrapped `Date`.
|
|
5
5
|
*
|
|
6
6
|
* **Supported call styles:**
|
|
7
|
-
* - Classic: `dateAddTime(date, time)`
|
|
8
|
-
* - Curried: `dateAddTime(time)`
|
|
7
|
+
* - Classic: `dateAddTime(date, time)` → `Date`
|
|
8
|
+
* - Curried: `dateAddTime(time)` → function waiting for the date
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `time` accepts wrapped `Time` or raw `TheTime`.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const date = C.Date.createOrThrow(D.create("2024-01-01"));
|
|
14
|
-
* const oneHour = C.Time.createOrThrow(D.
|
|
14
|
+
* const oneHour = C.Time.createOrThrow(D.createTime(1, "hour"));
|
|
15
15
|
*
|
|
16
16
|
* const later = C.dateAddTime(date, oneHour);
|
|
17
17
|
* // later: C.Date
|
|
18
18
|
*
|
|
19
19
|
* const curried = pipe(
|
|
20
20
|
* date,
|
|
21
|
-
* C.dateAddTime(D.
|
|
21
|
+
* C.dateAddTime(D.createTime(1, "minute")),
|
|
22
22
|
* );
|
|
23
23
|
* // curried: C.Date
|
|
24
24
|
*
|
|
25
|
-
* const mixed = C.dateAddTime(
|
|
26
|
-
* C.Date.createOrThrow(D.create("2024-01-02")),
|
|
27
|
-
* D.createTheTime(500),
|
|
28
|
-
* );
|
|
25
|
+
* const mixed = C.dateAddTime(date, D.createTime(500, "millisecond"));
|
|
29
26
|
* // mixed: C.Date
|
|
30
|
-
*
|
|
31
27
|
* ```
|
|
32
28
|
*
|
|
33
29
|
* @see https://utils.duplojs.dev/en/v1/api/clean/primitives/operators/dateAddTime
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { type Date } from "../../base";
|
|
2
2
|
import { type TheDate } from "../../../../date";
|
|
3
3
|
/**
|
|
4
|
-
* Checks whether a Date is after a threshold.
|
|
4
|
+
* Checks whether a wrapped `Date` is strictly after a threshold.
|
|
5
5
|
*
|
|
6
6
|
* **Supported call styles:**
|
|
7
|
-
* - Classic: `dateGreaterThan(date, threshold)`
|
|
8
|
-
* - Curried: `dateGreaterThan(threshold)`
|
|
7
|
+
* - Classic: `dateGreaterThan(date, threshold)` → `boolean`
|
|
8
|
+
* - Curried: `dateGreaterThan(threshold)` → function waiting for the date
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `threshold` accepts wrapped `Date` or raw `TheDate`.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const date = C.Date.createOrThrow(D.create("2024-03-01"));
|
|
14
14
|
* const threshold = D.create("2024-02-29");
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* }
|
|
16
|
+
* const result = C.dateGreaterThan(date, threshold);
|
|
17
|
+
* // result: true
|
|
19
18
|
*
|
|
19
|
+
* pipe(
|
|
20
|
+
* date,
|
|
21
|
+
* C.dateGreaterThan(threshold),
|
|
20
22
|
* ```
|
|
21
23
|
*
|
|
22
24
|
* @see https://utils.duplojs.dev/en/v1/api/clean/primitives/operators/dateGreaterThan
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { type Date } from "../../base";
|
|
2
2
|
import { type TheDate } from "../../../../date";
|
|
3
3
|
/**
|
|
4
|
-
* Checks whether a Date is before a threshold.
|
|
4
|
+
* Checks whether a wrapped `Date` is strictly before a threshold.
|
|
5
5
|
*
|
|
6
6
|
* **Supported call styles:**
|
|
7
|
-
* - Classic: `dateLessThan(date, threshold)`
|
|
8
|
-
* - Curried: `dateLessThan(threshold)`
|
|
7
|
+
* - Classic: `dateLessThan(date, threshold)` → `boolean`
|
|
8
|
+
* - Curried: `dateLessThan(threshold)` → function waiting for the date
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `threshold` accepts wrapped `Date` or raw `TheDate`.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const date = C.Date.createOrThrow(D.create("2024-02-29"));
|
|
14
14
|
* const threshold = D.create("2024-03-01");
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* }
|
|
16
|
+
* const result = C.dateLessThan(date, threshold);
|
|
17
|
+
* // result: true
|
|
19
18
|
*
|
|
19
|
+
* pipe(
|
|
20
|
+
* date,
|
|
21
|
+
* C.dateLessThan(threshold),
|
|
20
22
|
* ```
|
|
21
23
|
*
|
|
22
24
|
* @see https://utils.duplojs.dev/en/v1/api/clean/primitives/operators/dateLessThan
|
|
@@ -2,12 +2,12 @@ import { type TheDate } from "../../../../date";
|
|
|
2
2
|
import { type Date } from "../../base";
|
|
3
3
|
import { type AnyTuple } from "../../../../common";
|
|
4
4
|
/**
|
|
5
|
-
* Returns the latest
|
|
5
|
+
* Returns the latest wrapped `Date` from a tuple.
|
|
6
6
|
*
|
|
7
7
|
* **Supported call styles:**
|
|
8
|
-
* - Classic: `dateMax(input)`
|
|
8
|
+
* - Classic: `dateMax(input)` → `Date`
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `input` can mix wrapped `Date` and raw `TheDate` values.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const latest = C.dateMax([
|
|
@@ -17,13 +17,6 @@ import { type AnyTuple } from "../../../../common";
|
|
|
17
17
|
* ]);
|
|
18
18
|
* // latest: C.Date
|
|
19
19
|
*
|
|
20
|
-
* const fromRaw = C.dateMax([
|
|
21
|
-
* D.create("2024-01-05"),
|
|
22
|
-
* D.create("2024-01-03"),
|
|
23
|
-
* D.create("2024-01-10"),
|
|
24
|
-
* ]);
|
|
25
|
-
* // fromRaw: C.Date
|
|
26
|
-
*
|
|
27
20
|
* const mixed = C.dateMax([
|
|
28
21
|
* C.Date.createOrThrow(D.create("2024-01-08")),
|
|
29
22
|
* D.create("2024-01-07"),
|
|
@@ -2,12 +2,12 @@ import { type TheDate } from "../../../../date";
|
|
|
2
2
|
import { type Date } from "../../base";
|
|
3
3
|
import { type AnyTuple } from "../../../../common";
|
|
4
4
|
/**
|
|
5
|
-
* Returns the earliest
|
|
5
|
+
* Returns the earliest wrapped `Date` from a tuple.
|
|
6
6
|
*
|
|
7
7
|
* **Supported call styles:**
|
|
8
|
-
* - Classic: `dateMin(input)`
|
|
8
|
+
* - Classic: `dateMin(input)` → `Date`
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `input` can mix wrapped `Date` and raw `TheDate` values.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const earliest = C.dateMin([
|
|
@@ -17,13 +17,6 @@ import { type AnyTuple } from "../../../../common";
|
|
|
17
17
|
* ]);
|
|
18
18
|
* // earliest: C.Date
|
|
19
19
|
*
|
|
20
|
-
* const fromRaw = C.dateMin([
|
|
21
|
-
* D.create("2024-01-05"),
|
|
22
|
-
* D.create("2024-01-03"),
|
|
23
|
-
* D.create("2024-01-10"),
|
|
24
|
-
* ]);
|
|
25
|
-
* // fromRaw: C.Date
|
|
26
|
-
*
|
|
27
20
|
* const mixed = C.dateMin([
|
|
28
21
|
* C.Date.createOrThrow(D.create("2024-01-08")),
|
|
29
22
|
* D.create("2024-01-07"),
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import { type Date, type Time } from "../../base";
|
|
2
2
|
import { type TheTime } from "../../../../date";
|
|
3
3
|
/**
|
|
4
|
-
* Subtracts a
|
|
4
|
+
* Subtracts a duration from a wrapped `Date` and returns a wrapped `Date`.
|
|
5
5
|
*
|
|
6
6
|
* **Supported call styles:**
|
|
7
|
-
* - Classic: `dateSubtractTime(date, time)`
|
|
8
|
-
* - Curried: `dateSubtractTime(time)`
|
|
7
|
+
* - Classic: `dateSubtractTime(date, time)` → `Date`
|
|
8
|
+
* - Curried: `dateSubtractTime(time)` → function waiting for the date
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `time` accepts wrapped `Time` or raw `TheTime`.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const date = C.Date.createOrThrow(D.create("2024-01-02"));
|
|
14
|
-
* const halfMinute = C.Time.createOrThrow(D.
|
|
14
|
+
* const halfMinute = C.Time.createOrThrow(D.createTime(30, "second"));
|
|
15
15
|
*
|
|
16
16
|
* const earlier = C.dateSubtractTime(date, halfMinute);
|
|
17
17
|
* // earlier: C.Date
|
|
18
18
|
*
|
|
19
19
|
* const curried = pipe(
|
|
20
20
|
* date,
|
|
21
|
-
* C.dateSubtractTime(D.
|
|
21
|
+
* C.dateSubtractTime(D.createTime(1, "second")),
|
|
22
22
|
* );
|
|
23
23
|
* // curried: C.Date
|
|
24
24
|
*
|
|
25
|
-
* const mixed = C.dateSubtractTime(
|
|
26
|
-
* C.Date.createOrThrow(D.create("2024-01-01")),
|
|
27
|
-
* D.createTheTime(500),
|
|
28
|
-
* );
|
|
25
|
+
* const mixed = C.dateSubtractTime(date, D.createTime(500, "millisecond"));
|
|
29
26
|
* // mixed: C.Date
|
|
30
|
-
*
|
|
31
27
|
* ```
|
|
32
28
|
*
|
|
33
29
|
* @see https://utils.duplojs.dev/en/v1/api/clean/primitives/operators/dateSubtractTime
|
|
@@ -8,7 +8,7 @@ function equal(...args) {
|
|
|
8
8
|
return (input) => equal(input, value);
|
|
9
9
|
}
|
|
10
10
|
const [input, value] = args;
|
|
11
|
-
return unwrap.unwrap(input) === unwrap.unwrap(value);
|
|
11
|
+
return unwrap.unwrap(input).toString() === unwrap.unwrap(value).toString();
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
exports.equal = equal;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ToLargeEnsemble, type Unwrap } from "../../../common";
|
|
2
|
-
import { type Primitive, type Primitives
|
|
2
|
+
import { type Primitive, type Primitives } from "../base";
|
|
3
3
|
/**
|
|
4
4
|
* Compares two wrapped primitives (or a primitive and a raw value) with a type guard.
|
|
5
5
|
*
|
|
@@ -34,5 +34,5 @@ import { type Primitive, type Primitives, type Date, type Time } from "../base";
|
|
|
34
34
|
* @namespace C
|
|
35
35
|
*
|
|
36
36
|
*/
|
|
37
|
-
export declare function equal<GenericInput extends Primitives, GenericValue extends (
|
|
38
|
-
export declare function equal<GenericInput extends Primitives, GenericValue extends (
|
|
37
|
+
export declare function equal<GenericInput extends Primitives, GenericValue extends (Primitive<ToLargeEnsemble<Unwrap<GenericInput>>> | ToLargeEnsemble<Unwrap<GenericInput>>)>(value: GenericValue): (input: GenericInput) => input is GenericInput & Primitive<Unwrap<GenericValue>>;
|
|
38
|
+
export declare function equal<GenericInput extends Primitives, GenericValue extends (Primitive<ToLargeEnsemble<Unwrap<GenericInput>>> | ToLargeEnsemble<Unwrap<GenericInput>>)>(input: GenericInput, value: GenericValue): input is GenericInput & Primitive<Unwrap<GenericValue>>;
|
|
@@ -2,13 +2,11 @@ import { type Date, type Number, type String, type Time } from "../base";
|
|
|
2
2
|
import { type ToWrappedValue, type SortType } from "../../../common";
|
|
3
3
|
import * as DDate from "../../../date";
|
|
4
4
|
/**
|
|
5
|
-
* Sorts
|
|
5
|
+
* Sorts arrays of wrapped primitives (`String`, `Number`, `Date`, `Time`).
|
|
6
6
|
*
|
|
7
7
|
* **Supported call styles:**
|
|
8
|
-
* - Classic: `sort(input, type)`
|
|
9
|
-
* - Curried: `sort(type)`
|
|
10
|
-
*
|
|
11
|
-
* The output array contains wrapped primitives.
|
|
8
|
+
* - Classic: `sort(input, type)` → wrapped array
|
|
9
|
+
* - Curried: `sort(type)` → function waiting for the input
|
|
12
10
|
*
|
|
13
11
|
* ```ts
|
|
14
12
|
* const numbers = [
|
|
@@ -27,13 +25,13 @@ import * as DDate from "../../../date";
|
|
|
27
25
|
* // desc: C.Number[]
|
|
28
26
|
*
|
|
29
27
|
* const dates = C.sort([
|
|
30
|
-
* D.
|
|
31
|
-
* D.
|
|
32
|
-
* ], "ASC");
|
|
33
|
-
* // dates: C.Date[]
|
|
34
|
-
*
|
|
28
|
+
* D.create("2024-01-02"),
|
|
29
|
+
* D.create("2024-01-01"),
|
|
35
30
|
* ```
|
|
36
31
|
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* - Supports mixed wrapped/raw values in the same primitive family.
|
|
34
|
+
*
|
|
37
35
|
* @see https://utils.duplojs.dev/en/v1/api/clean/primitives/operators/sort
|
|
38
36
|
*
|
|
39
37
|
* @namespace C
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { type Time } from "../../base";
|
|
2
2
|
import { type TheTime } from "../../../../date";
|
|
3
3
|
/**
|
|
4
|
-
* Checks whether a Time is greater than a threshold.
|
|
4
|
+
* Checks whether a wrapped `Time` is strictly greater than a threshold.
|
|
5
5
|
*
|
|
6
6
|
* **Supported call styles:**
|
|
7
|
-
* - Classic: `timeGreaterThan(time, threshold)`
|
|
8
|
-
* - Curried: `timeGreaterThan(threshold)`
|
|
7
|
+
* - Classic: `timeGreaterThan(time, threshold)` → `boolean`
|
|
8
|
+
* - Curried: `timeGreaterThan(threshold)` → function waiting for the time
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `threshold` accepts wrapped `Time` or raw `TheTime`.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
|
-
* const duration = C.Time.createOrThrow(D.
|
|
14
|
-
* const threshold = D.
|
|
13
|
+
* const duration = C.Time.createOrThrow(D.createTime(1, "hour"));
|
|
14
|
+
* const threshold = D.createTime(30, "minute");
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* }
|
|
16
|
+
* const result = C.timeGreaterThan(duration, threshold);
|
|
17
|
+
* // result: true
|
|
19
18
|
*
|
|
19
|
+
* pipe(
|
|
20
|
+
* duration,
|
|
21
|
+
* C.timeGreaterThan(threshold),
|
|
20
22
|
* ```
|
|
21
23
|
*
|
|
22
24
|
* @see https://utils.duplojs.dev/en/v1/api/clean/primitives/operators/timeGreaterThan
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { type Time } from "../../base";
|
|
2
2
|
import { type TheTime } from "../../../../date";
|
|
3
3
|
/**
|
|
4
|
-
* Checks whether a Time is less than a threshold.
|
|
4
|
+
* Checks whether a wrapped `Time` is strictly less than a threshold.
|
|
5
5
|
*
|
|
6
6
|
* **Supported call styles:**
|
|
7
|
-
* - Classic: `timeLessThan(time, threshold)`
|
|
8
|
-
* - Curried: `timeLessThan(threshold)`
|
|
7
|
+
* - Classic: `timeLessThan(time, threshold)` → `boolean`
|
|
8
|
+
* - Curried: `timeLessThan(threshold)` → function waiting for the time
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `threshold` accepts wrapped `Time` or raw `TheTime`.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
|
-
* const duration = C.Time.createOrThrow(D.
|
|
14
|
-
* const threshold = D.
|
|
13
|
+
* const duration = C.Time.createOrThrow(D.createTime(1, "hour"));
|
|
14
|
+
* const threshold = D.createTime(2, "hour");
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* }
|
|
16
|
+
* const result = C.timeLessThan(duration, threshold);
|
|
17
|
+
* // result: true
|
|
19
18
|
*
|
|
19
|
+
* pipe(
|
|
20
|
+
* duration,
|
|
21
|
+
* C.timeLessThan(threshold),
|
|
20
22
|
* ```
|
|
21
23
|
*
|
|
22
24
|
* @see https://utils.duplojs.dev/en/v1/api/clean/primitives/operators/timeLessThan
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var wrapValue = require('../../../../common/wrapValue.cjs');
|
|
4
|
-
var
|
|
4
|
+
var theTime = require('../../../../date/theTime.cjs');
|
|
5
5
|
var unwrap = require('../../../../common/unwrap.cjs');
|
|
6
6
|
var toTimeValue = require('../../../../date/toTimeValue.cjs');
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@ var toTimeValue = require('../../../../date/toTimeValue.cjs');
|
|
|
9
9
|
* {@include clean/timeMax/index.md}
|
|
10
10
|
*/
|
|
11
11
|
function timeMax(input) {
|
|
12
|
-
return wrapValue.wrapValue(
|
|
12
|
+
return wrapValue.wrapValue(theTime.TheTime.new(Math.max(...input.map(unwrap.unwrap).map(toTimeValue.toTimeValue))));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
exports.timeMax = timeMax;
|
|
@@ -1,32 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type Time } from "../../base";
|
|
1
|
+
import { TheTime } from "../../../../date";
|
|
3
2
|
import { type AnyTuple } from "../../../../common";
|
|
3
|
+
import { type Time } from "../../base";
|
|
4
4
|
/**
|
|
5
|
-
* Returns the largest
|
|
5
|
+
* Returns the largest wrapped `Time` from a tuple.
|
|
6
6
|
*
|
|
7
7
|
* **Supported call styles:**
|
|
8
|
-
* - Classic: `timeMax(input)`
|
|
8
|
+
* - Classic: `timeMax(input)` → `Time`
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `input` can mix wrapped `Time` and raw `TheTime` values.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const largest = C.timeMax([
|
|
14
|
-
* C.Time.createOrThrow(D.
|
|
15
|
-
* D.
|
|
16
|
-
* D.
|
|
14
|
+
* C.Time.createOrThrow(D.createTime(1_000, "millisecond")),
|
|
15
|
+
* D.createTime(500, "millisecond"),
|
|
16
|
+
* D.createTime(2_000, "millisecond"),
|
|
17
17
|
* ]);
|
|
18
18
|
* // largest: C.Time
|
|
19
19
|
*
|
|
20
|
-
* const fromRaw = C.timeMax([
|
|
21
|
-
* D.createTheTime(10),
|
|
22
|
-
* D.createTheTime(5),
|
|
23
|
-
* D.createTheTime(20),
|
|
24
|
-
* ]);
|
|
25
|
-
* // fromRaw: C.Time
|
|
26
|
-
*
|
|
27
20
|
* const mixed = C.timeMax([
|
|
28
|
-
* C.Time.createOrThrow(D.
|
|
29
|
-
* D.
|
|
21
|
+
* C.Time.createOrThrow(D.createTime(100, "millisecond")),
|
|
22
|
+
* D.createTime(50, "millisecond"),
|
|
30
23
|
* ]);
|
|
31
24
|
* // mixed: C.Time
|
|
32
25
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { wrapValue } from '../../../../common/wrapValue.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { TheTime } from '../../../../date/theTime.mjs';
|
|
3
3
|
import { unwrap } from '../../../../common/unwrap.mjs';
|
|
4
4
|
import { toTimeValue } from '../../../../date/toTimeValue.mjs';
|
|
5
5
|
|
|
@@ -7,7 +7,7 @@ import { toTimeValue } from '../../../../date/toTimeValue.mjs';
|
|
|
7
7
|
* {@include clean/timeMax/index.md}
|
|
8
8
|
*/
|
|
9
9
|
function timeMax(input) {
|
|
10
|
-
return wrapValue(
|
|
10
|
+
return wrapValue(TheTime.new(Math.max(...input.map(unwrap).map(toTimeValue))));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export { timeMax };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var toTimeValue = require('../../../../date/toTimeValue.cjs');
|
|
4
3
|
var wrapValue = require('../../../../common/wrapValue.cjs');
|
|
5
|
-
var
|
|
4
|
+
var theTime = require('../../../../date/theTime.cjs');
|
|
6
5
|
var unwrap = require('../../../../common/unwrap.cjs');
|
|
6
|
+
var toTimeValue = require('../../../../date/toTimeValue.cjs');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* {@include clean/timeMin/index.md}
|
|
10
10
|
*/
|
|
11
11
|
function timeMin(input) {
|
|
12
|
-
return wrapValue.wrapValue(
|
|
12
|
+
return wrapValue.wrapValue(theTime.TheTime.new(Math.min(...input.map(unwrap.unwrap).map(toTimeValue.toTimeValue))));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
exports.timeMin = timeMin;
|
|
@@ -1,32 +1,25 @@
|
|
|
1
|
-
import { type TheTime } from "../../../../date";
|
|
2
|
-
import { type Time } from "../../base";
|
|
3
1
|
import { type AnyTuple } from "../../../../common";
|
|
2
|
+
import { TheTime } from "../../../../date";
|
|
3
|
+
import { type Time } from "../../base";
|
|
4
4
|
/**
|
|
5
|
-
* Returns the smallest
|
|
5
|
+
* Returns the smallest wrapped `Time` from a tuple.
|
|
6
6
|
*
|
|
7
7
|
* **Supported call styles:**
|
|
8
|
-
* - Classic: `timeMin(input)`
|
|
8
|
+
* - Classic: `timeMin(input)` → `Time`
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `input` can mix wrapped `Time` and raw `TheTime` values.
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const smallest = C.timeMin([
|
|
14
|
-
* C.Time.createOrThrow(D.
|
|
15
|
-
* D.
|
|
16
|
-
* D.
|
|
14
|
+
* C.Time.createOrThrow(D.createTime(1_000, "millisecond")),
|
|
15
|
+
* D.createTime(500, "millisecond"),
|
|
16
|
+
* D.createTime(2_000, "millisecond"),
|
|
17
17
|
* ]);
|
|
18
18
|
* // smallest: C.Time
|
|
19
19
|
*
|
|
20
|
-
* const fromRaw = C.timeMin([
|
|
21
|
-
* D.createTheTime(10),
|
|
22
|
-
* D.createTheTime(5),
|
|
23
|
-
* D.createTheTime(20),
|
|
24
|
-
* ]);
|
|
25
|
-
* // fromRaw: C.Time
|
|
26
|
-
*
|
|
27
20
|
* const mixed = C.timeMin([
|
|
28
|
-
* C.Time.createOrThrow(D.
|
|
29
|
-
* D.
|
|
21
|
+
* C.Time.createOrThrow(D.createTime(100, "millisecond")),
|
|
22
|
+
* D.createTime(50, "millisecond"),
|
|
30
23
|
* ]);
|
|
31
24
|
* // mixed: C.Time
|
|
32
25
|
*
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { toTimeValue } from '../../../../date/toTimeValue.mjs';
|
|
2
1
|
import { wrapValue } from '../../../../common/wrapValue.mjs';
|
|
3
|
-
import {
|
|
2
|
+
import { TheTime } from '../../../../date/theTime.mjs';
|
|
4
3
|
import { unwrap } from '../../../../common/unwrap.mjs';
|
|
4
|
+
import { toTimeValue } from '../../../../date/toTimeValue.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* {@include clean/timeMin/index.md}
|
|
8
8
|
*/
|
|
9
9
|
function timeMin(input) {
|
|
10
|
-
return wrapValue(
|
|
10
|
+
return wrapValue(TheTime.new(Math.min(...input.map(unwrap).map(toTimeValue))));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export { timeMin };
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var entity = require('./entity.cjs');
|
|
4
4
|
var flag = require('./flag.cjs');
|
|
5
|
+
var forward = require('../common/forward.cjs');
|
|
5
6
|
var unwrap = require('../common/unwrap.cjs');
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* {@include clean/unwrapEntity/index.md}
|
|
10
|
+
*/
|
|
11
|
+
function unwrapEntity(entity$1, params) {
|
|
12
|
+
const transformer = params?.transformer ?? forward.forward;
|
|
8
13
|
const unwrapEntity = {};
|
|
9
14
|
for (const prop in entity$1) {
|
|
10
15
|
if (prop === entity.entityKind.runTimeKey) {
|
|
@@ -14,10 +19,15 @@ function unwrapEntity(entity$1) {
|
|
|
14
19
|
unwrapEntity._flags = entity$1[prop];
|
|
15
20
|
}
|
|
16
21
|
else if (entity$1[prop] instanceof Array) {
|
|
17
|
-
|
|
22
|
+
const length = entity$1[prop].length;
|
|
23
|
+
const result = [];
|
|
24
|
+
for (let index = 0; index < length; index++) {
|
|
25
|
+
result[index] = transformer(unwrap.unwrap(entity$1[prop][index]));
|
|
26
|
+
}
|
|
27
|
+
unwrapEntity[prop] = result;
|
|
18
28
|
}
|
|
19
29
|
else {
|
|
20
|
-
unwrapEntity[prop] = unwrap.unwrap(entity$1[prop]);
|
|
30
|
+
unwrapEntity[prop] = transformer(unwrap.unwrap(entity$1[prop]));
|
|
21
31
|
}
|
|
22
32
|
}
|
|
23
33
|
return unwrapEntity;
|
|
@@ -1,13 +1,65 @@
|
|
|
1
|
-
import { type GetKindValue, type SimplifyTopLevel, type Kind, type Unwrap, type DeepReadonly } from "../common";
|
|
1
|
+
import { type GetKindValue, type SimplifyTopLevel, type Kind, type Unwrap, type DeepReadonly, type TransformerFunction, type IsEqual, type Transformer } from "../common";
|
|
2
2
|
import { entityKind, type Entity } from "./entity";
|
|
3
3
|
import { flagKind } from "./flag";
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type ApplyTransformer<GenericValue extends unknown, GenericTransformer extends TransformerFunction> = IsEqual<GenericTransformer, never> extends true ? GenericValue : GenericTransformer extends TransformerFunction<infer InferredMethodName> ? Transformer<GenericValue, InferredMethodName> : never;
|
|
5
|
+
type UnwrapArrayProperties<GenericValue extends readonly any[], GenericTransformer extends TransformerFunction> = GenericValue extends readonly [infer InferredFirst, ...infer InferredRest] ? (InferredRest extends readonly [] ? readonly [] : UnwrapArrayProperties<InferredRest, GenericTransformer>) extends infer InferredResult extends readonly any[] ? readonly [
|
|
6
|
+
ApplyTransformer<Unwrap<InferredFirst>, GenericTransformer>,
|
|
7
|
+
...InferredResult
|
|
8
|
+
] : never : readonly ApplyTransformer<Unwrap<GenericValue[number]>, GenericTransformer>[];
|
|
9
|
+
export type UnwrapEntity<GenericEntity extends Entity, GenericTransformer extends TransformerFunction = never> = SimplifyTopLevel<DeepReadonly<{
|
|
10
|
+
[Prop in Extract<keyof GenericEntity, string>]: GenericEntity[Prop] extends readonly any[] ? UnwrapArrayProperties<GenericEntity[Prop], GenericTransformer> : ApplyTransformer<Unwrap<GenericEntity[Prop]>, GenericTransformer>;
|
|
7
11
|
} & {
|
|
8
12
|
[Prop in "_entityName"]: GetKindValue<typeof entityKind, GenericEntity>;
|
|
9
13
|
} & (GenericEntity extends Kind<typeof flagKind.definition, any> ? {
|
|
10
14
|
[Prop in "_flags"]: SimplifyTopLevel<GetKindValue<typeof flagKind, GenericEntity>>;
|
|
11
15
|
} : {})>>;
|
|
12
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Unwraps a `Clean` entity into a readonly plain object.
|
|
18
|
+
*
|
|
19
|
+
* Signature: `unwrapEntity(entity, params?)` → unwrapped object
|
|
20
|
+
*
|
|
21
|
+
* By default, wrapped values are unwrapped as-is. You can pass a transformer (for example `toNative` or `toJSON`) to project values during unwrapping.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const Id = C.createNewType("userId", DP.number());
|
|
25
|
+
* const Name = C.createNewType("userName", DP.string());
|
|
26
|
+
* const Birth = C.createNewType("userBirth", DP.date());
|
|
27
|
+
* const TimeSpent = C.createNewType("userTimeSpent", DP.time());
|
|
28
|
+
*
|
|
29
|
+
* const User = C.createEntity("User", () => ({
|
|
30
|
+
* id: Id,
|
|
31
|
+
* name: Name,
|
|
32
|
+
* birth: Birth,
|
|
33
|
+
* timeSpent: TimeSpent,
|
|
34
|
+
* }));
|
|
35
|
+
*
|
|
36
|
+
* const entity = User.new({
|
|
37
|
+
* id: Id.createOrThrow(1),
|
|
38
|
+
* name: Name.createOrThrow("Ada"),
|
|
39
|
+
* birth: Birth.createOrThrow(D.create("2024-01-01")),
|
|
40
|
+
* timeSpent: TimeSpent.createOrThrow(D.createTime(30, "minute")),
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* const unwrapped = C.unwrapEntity(entity);
|
|
44
|
+
* // unwrapped.birth: TheDate, unwrapped.timeSpent: TheTime
|
|
45
|
+
*
|
|
46
|
+
* const asJSON = C.unwrapEntity(entity, { transformer: toJSON });
|
|
47
|
+
* // asJSON.birth: SerializedTheDate, asJSON.timeSpent: SerializedTheTime
|
|
48
|
+
*
|
|
49
|
+
* const asNative = C.unwrapEntity(entity, { transformer: toNative });
|
|
50
|
+
* // asNative.birth: Date, asNative.timeSpent: number
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* - The result always contains `_entityName`.
|
|
55
|
+
* - If the entity has flags, `_flags` is also included.
|
|
56
|
+
*
|
|
57
|
+
* @see https://utils.duplojs.dev/en/v1/api/clean/unwrapEntity
|
|
58
|
+
*
|
|
59
|
+
* @namespace C
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
export declare function unwrapEntity<GenericEntity extends Entity, GenericTransformer extends TransformerFunction = never>(entity: GenericEntity, params?: {
|
|
63
|
+
transformer?: GenericTransformer;
|
|
64
|
+
}): UnwrapEntity<GenericEntity, GenericTransformer>;
|
|
13
65
|
export {};
|