@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,8 +1,13 @@
|
|
|
1
1
|
import { entityKind } from './entity.mjs';
|
|
2
2
|
import { flagKind } from './flag.mjs';
|
|
3
|
+
import { forward } from '../common/forward.mjs';
|
|
3
4
|
import { unwrap } from '../common/unwrap.mjs';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* {@include clean/unwrapEntity/index.md}
|
|
8
|
+
*/
|
|
9
|
+
function unwrapEntity(entity, params) {
|
|
10
|
+
const transformer = params?.transformer ?? forward;
|
|
6
11
|
const unwrapEntity = {};
|
|
7
12
|
for (const prop in entity) {
|
|
8
13
|
if (prop === entityKind.runTimeKey) {
|
|
@@ -12,10 +17,15 @@ function unwrapEntity(entity) {
|
|
|
12
17
|
unwrapEntity._flags = entity[prop];
|
|
13
18
|
}
|
|
14
19
|
else if (entity[prop] instanceof Array) {
|
|
15
|
-
|
|
20
|
+
const length = entity[prop].length;
|
|
21
|
+
const result = [];
|
|
22
|
+
for (let index = 0; index < length; index++) {
|
|
23
|
+
result[index] = transformer(unwrap(entity[prop][index]));
|
|
24
|
+
}
|
|
25
|
+
unwrapEntity[prop] = result;
|
|
16
26
|
}
|
|
17
27
|
else {
|
|
18
|
-
unwrapEntity[prop] = unwrap(entity[prop]);
|
|
28
|
+
unwrapEntity[prop] = transformer(unwrap(entity[prop]));
|
|
19
29
|
}
|
|
20
30
|
}
|
|
21
31
|
return unwrapEntity;
|
package/dist/common/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* - predicates and guards (`when`, `whenNot`, `whenElse`, `and`, `or`, `isType`, `asserts`, `instanceOf`)
|
|
17
17
|
* - control flow (`loop`, `asyncLoop`, `asyncRetry`, `sleep`, `memo`)
|
|
18
18
|
* - promise utilities (`externalPromise`, `promiseObject`)
|
|
19
|
-
* - string and value conversions (`
|
|
19
|
+
* - string and value conversions (`stringToMillisecond`, `stringToBytes`, `escapeRegExp`, `toRegExp`)
|
|
20
20
|
* - wrappers and kinds (`wrapValue`, `unwrap`, `toWrappedValue`, `hasKinds`, `hasSomeKinds`)
|
|
21
21
|
*
|
|
22
22
|
* @see https://utils.duplojs.dev/en/v1/api/common
|
|
@@ -38,15 +38,12 @@ export * from "./sleep";
|
|
|
38
38
|
export * from "./stringToBytes";
|
|
39
39
|
export * from "./mimeType";
|
|
40
40
|
export * from "./stringToMillisecond";
|
|
41
|
-
export * from "./toJSON";
|
|
42
|
-
export * from "./toTransform";
|
|
43
41
|
export * from "./toWrappedValue";
|
|
44
42
|
export * from "./unwrap";
|
|
45
43
|
export * from "./unwrapGroup";
|
|
46
44
|
export * from "./asyncLoop";
|
|
47
45
|
export * from "./asyncRetry";
|
|
48
46
|
export * from "./wrapValue";
|
|
49
|
-
export * from "./toString";
|
|
50
47
|
export * from "./innerPipe";
|
|
51
48
|
export * from "./asyncInnerPipe";
|
|
52
49
|
export * from "./loop";
|
|
@@ -76,3 +73,5 @@ export * from "./toCurriedPredicate";
|
|
|
76
73
|
export * from "./pipeCall";
|
|
77
74
|
export * from "./asserts";
|
|
78
75
|
export * from "./path";
|
|
76
|
+
export * from "./transformer";
|
|
77
|
+
export * from "./toRegExp";
|
package/dist/common/kind.d.ts
CHANGED
|
@@ -90,6 +90,7 @@ export interface ReservedKindNamespace {
|
|
|
90
90
|
DuplojsUtilsBuilder: true;
|
|
91
91
|
DuplojsUtilsError: true;
|
|
92
92
|
DuplojsUtilsClean: true;
|
|
93
|
+
DuplojsUtilsDate: true;
|
|
93
94
|
}
|
|
94
95
|
type ForbiddenKindNamespace<GenericValue extends string> = (ForbiddenKindCharacters<GenericValue> & ForbiddenString<GenericValue, GetPropsWithValue<ReservedKindNamespace, true>>);
|
|
95
96
|
/**
|
package/dist/common/path.cjs
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var success = require('../either/right/success.cjs');
|
|
4
|
-
var fail = require('../either/left/fail.cjs');
|
|
5
|
-
|
|
6
3
|
exports.Path = void 0;
|
|
7
4
|
(function (Path) {
|
|
8
5
|
Path.baseNameRegex = /\/?([^/]+)$/;
|
|
9
6
|
Path.folderNameRegex = /([^]+)\/[^/]+\/?$/;
|
|
10
7
|
Path.extensionNameRegex = /\.([^./]+)$/;
|
|
11
|
-
Path.
|
|
8
|
+
Path.isContainBackPathRegex = /(^|\/)\.\.(?=\/|$)/;
|
|
12
9
|
Path.segmentTrailingRegex = /\/$/;
|
|
13
10
|
Path.segmentRelativeRegex = /^(.\/)/;
|
|
14
11
|
/**
|
|
@@ -52,17 +49,21 @@ exports.Path = void 0;
|
|
|
52
49
|
*/
|
|
53
50
|
function isAbsolute(path) {
|
|
54
51
|
return path.startsWith("/")
|
|
55
|
-
&& !Path.
|
|
52
|
+
&& !Path.isContainBackPathRegex.test(path);
|
|
56
53
|
}
|
|
57
54
|
Path.isAbsolute = isAbsolute;
|
|
58
55
|
/**
|
|
59
56
|
* {@include common/path/resolveFrom/index.md}
|
|
60
57
|
*/
|
|
61
|
-
function resolveFrom(origin, segments) {
|
|
62
|
-
const
|
|
58
|
+
function resolveFrom(origin, segments, params) {
|
|
59
|
+
const resultRelative = resolveRelative(segments);
|
|
60
|
+
if (params?.stayInOrigin && resultRelative.startsWith("../")) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const result = resolveRelative([origin, resultRelative]);
|
|
63
64
|
return isAbsolute(result)
|
|
64
|
-
?
|
|
65
|
-
:
|
|
65
|
+
? result
|
|
66
|
+
: null;
|
|
66
67
|
}
|
|
67
68
|
Path.resolveFrom = resolveFrom;
|
|
68
69
|
/**
|
|
@@ -74,16 +75,15 @@ exports.Path = void 0;
|
|
|
74
75
|
if (segment.length === 0) {
|
|
75
76
|
continue;
|
|
76
77
|
}
|
|
77
|
-
if (segment === "/") {
|
|
78
|
+
else if (segment === "/") {
|
|
78
79
|
clearedPath = segment;
|
|
79
80
|
continue;
|
|
80
81
|
}
|
|
81
82
|
const formattedSegment = fix(segment);
|
|
82
|
-
if (formattedSegment.startsWith("/")) {
|
|
83
|
+
if (formattedSegment.startsWith("/") || clearedPath === "") {
|
|
83
84
|
clearedPath = formattedSegment;
|
|
84
|
-
continue;
|
|
85
85
|
}
|
|
86
|
-
if (clearedPath === "/") {
|
|
86
|
+
else if (clearedPath === "/") {
|
|
87
87
|
clearedPath += formattedSegment;
|
|
88
88
|
}
|
|
89
89
|
else {
|
package/dist/common/path.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import * as DEither from "../either";
|
|
2
1
|
import type { AnyTuple } from "./types";
|
|
3
2
|
export declare namespace Path {
|
|
4
3
|
const baseNameRegex: RegExp;
|
|
5
4
|
const folderNameRegex: RegExp;
|
|
6
5
|
const extensionNameRegex: RegExp;
|
|
7
|
-
const
|
|
6
|
+
const isContainBackPathRegex: RegExp;
|
|
8
7
|
const segmentTrailingRegex: RegExp;
|
|
9
8
|
const segmentRelativeRegex: RegExp;
|
|
10
9
|
interface GetBaseNameParams {
|
|
@@ -95,31 +94,38 @@ export declare namespace Path {
|
|
|
95
94
|
*
|
|
96
95
|
*/
|
|
97
96
|
function isAbsolute<GenericPath extends string>(path: GenericPath): boolean;
|
|
97
|
+
interface ResolveFromParams {
|
|
98
|
+
stayInOrigin?: boolean;
|
|
99
|
+
}
|
|
98
100
|
/**
|
|
99
|
-
* Resolves a list of path segments from an origin
|
|
101
|
+
* Resolves a list of path segments from an origin.
|
|
100
102
|
*
|
|
101
103
|
* **Supported call styles:**
|
|
102
|
-
* - Classic: `resolveFrom(origin, segments)` -> returns
|
|
104
|
+
* - Classic: `resolveFrom(origin, segments, params?)` -> returns the resolved absolute path or null
|
|
103
105
|
*
|
|
104
106
|
* Segments are resolved in order using `resolveRelative`.
|
|
105
|
-
* The
|
|
107
|
+
* The function returns `null` when the final path is not absolute.
|
|
108
|
+
* When `params.stayInOrigin` is `true`, the resolution returns `null` if segments escape the origin with leading `../`.
|
|
106
109
|
*
|
|
107
110
|
* ```ts
|
|
108
111
|
* const absoluteResult = Path.resolveFrom("/root", ["alpha", "beta"]);
|
|
109
|
-
* // absoluteResult:
|
|
110
|
-
* const result = unwrap(absoluteResult);
|
|
111
|
-
* // result: "/root/alpha/beta"
|
|
112
|
+
* // absoluteResult: "/root/alpha/beta"
|
|
112
113
|
*
|
|
113
114
|
* const overrideResult = Path.resolveFrom("gamma", ["alpha", "/root", "beta"]);
|
|
114
|
-
* // overrideResult:
|
|
115
|
+
* // overrideResult: "/root/beta"
|
|
116
|
+
*
|
|
115
117
|
* const relativeResult = Path.resolveFrom("alpha", ["..", ".."]);
|
|
116
|
-
* // relativeResult:
|
|
118
|
+
* // relativeResult: null
|
|
119
|
+
*
|
|
120
|
+
* const blockedResult = Path.resolveFrom("/root", ["..", "etc"], {
|
|
121
|
+
* stayInOrigin: true,
|
|
122
|
+
* });
|
|
117
123
|
* ```
|
|
118
124
|
*
|
|
119
125
|
* @see https://utils.duplojs.dev/en/v1/api/common/path/resolveFrom
|
|
120
126
|
*
|
|
121
127
|
*/
|
|
122
|
-
function resolveFrom<GenericSegment extends string>(origin: string, segments: AnyTuple<GenericSegment
|
|
128
|
+
function resolveFrom<GenericSegment extends string>(origin: string, segments: AnyTuple<GenericSegment>, params?: ResolveFromParams): string | null;
|
|
123
129
|
/**
|
|
124
130
|
* Resolves path segments into a single POSIX-like path.
|
|
125
131
|
*
|
package/dist/common/path.mjs
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { success } from '../either/right/success.mjs';
|
|
2
|
-
import { fail } from '../either/left/fail.mjs';
|
|
3
|
-
|
|
4
1
|
var Path;
|
|
5
2
|
(function (Path) {
|
|
6
3
|
Path.baseNameRegex = /\/?([^/]+)$/;
|
|
7
4
|
Path.folderNameRegex = /([^]+)\/[^/]+\/?$/;
|
|
8
5
|
Path.extensionNameRegex = /\.([^./]+)$/;
|
|
9
|
-
Path.
|
|
6
|
+
Path.isContainBackPathRegex = /(^|\/)\.\.(?=\/|$)/;
|
|
10
7
|
Path.segmentTrailingRegex = /\/$/;
|
|
11
8
|
Path.segmentRelativeRegex = /^(.\/)/;
|
|
12
9
|
/**
|
|
@@ -50,17 +47,21 @@ var Path;
|
|
|
50
47
|
*/
|
|
51
48
|
function isAbsolute(path) {
|
|
52
49
|
return path.startsWith("/")
|
|
53
|
-
&& !Path.
|
|
50
|
+
&& !Path.isContainBackPathRegex.test(path);
|
|
54
51
|
}
|
|
55
52
|
Path.isAbsolute = isAbsolute;
|
|
56
53
|
/**
|
|
57
54
|
* {@include common/path/resolveFrom/index.md}
|
|
58
55
|
*/
|
|
59
|
-
function resolveFrom(origin, segments) {
|
|
60
|
-
const
|
|
56
|
+
function resolveFrom(origin, segments, params) {
|
|
57
|
+
const resultRelative = resolveRelative(segments);
|
|
58
|
+
if (params?.stayInOrigin && resultRelative.startsWith("../")) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const result = resolveRelative([origin, resultRelative]);
|
|
61
62
|
return isAbsolute(result)
|
|
62
|
-
?
|
|
63
|
-
:
|
|
63
|
+
? result
|
|
64
|
+
: null;
|
|
64
65
|
}
|
|
65
66
|
Path.resolveFrom = resolveFrom;
|
|
66
67
|
/**
|
|
@@ -72,16 +73,15 @@ var Path;
|
|
|
72
73
|
if (segment.length === 0) {
|
|
73
74
|
continue;
|
|
74
75
|
}
|
|
75
|
-
if (segment === "/") {
|
|
76
|
+
else if (segment === "/") {
|
|
76
77
|
clearedPath = segment;
|
|
77
78
|
continue;
|
|
78
79
|
}
|
|
79
80
|
const formattedSegment = fix(segment);
|
|
80
|
-
if (formattedSegment.startsWith("/")) {
|
|
81
|
+
if (formattedSegment.startsWith("/") || clearedPath === "") {
|
|
81
82
|
clearedPath = formattedSegment;
|
|
82
|
-
continue;
|
|
83
83
|
}
|
|
84
|
-
if (clearedPath === "/") {
|
|
84
|
+
else if (clearedPath === "/") {
|
|
85
85
|
clearedPath += formattedSegment;
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var escapeRegExp = require('./escapeRegExp.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* {@include common/toRegExp/index.md}
|
|
7
|
+
*/
|
|
8
|
+
function toRegExp(input) {
|
|
9
|
+
if (typeof input === "string") {
|
|
10
|
+
return new RegExp(`^${escapeRegExp.escapeRegExp(input)}$`);
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(input)) {
|
|
13
|
+
const result = input.map(escapeRegExp.escapeRegExp).join("|");
|
|
14
|
+
return new RegExp(`^(?:${result})$`);
|
|
15
|
+
}
|
|
16
|
+
return input;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.toRegExp = toRegExp;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The toRegExp() function normalizes a value into a regular expression. Strings and string arrays are escaped and converted to exact-match regex patterns.
|
|
3
|
+
*
|
|
4
|
+
* Supported call style:
|
|
5
|
+
* - Classic: `toRegExp(input)` → returns a value
|
|
6
|
+
*
|
|
7
|
+
* Behavior:
|
|
8
|
+
* - `string` input becomes an exact regex (`^.../**
|
|
9
|
+
)
|
|
10
|
+
* - `string[]` input becomes an exact alternation regex (`^(?:...|...)/**
|
|
11
|
+
)
|
|
12
|
+
* - `RegExp` input is returned as-is
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const fromString = toRegExp("a.c");
|
|
16
|
+
* // matches only the literal "a.c"
|
|
17
|
+
*
|
|
18
|
+
* const fromList = toRegExp([
|
|
19
|
+
* "jpg",
|
|
20
|
+
* "png",
|
|
21
|
+
* ]);
|
|
22
|
+
* // matches "jpg" or "png"
|
|
23
|
+
*
|
|
24
|
+
* const existing = /hello/i;
|
|
25
|
+
* const sameInstance = toRegExp(existing);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @see https://utils.duplojs.dev/en/v1/api/common/toRegExp
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
export declare function toRegExp(input: string | string[] | RegExp): RegExp;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { escapeRegExp } from './escapeRegExp.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* {@include common/toRegExp/index.md}
|
|
5
|
+
*/
|
|
6
|
+
function toRegExp(input) {
|
|
7
|
+
if (typeof input === "string") {
|
|
8
|
+
return new RegExp(`^${escapeRegExp(input)}$`);
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(input)) {
|
|
11
|
+
const result = input.map(escapeRegExp).join("|");
|
|
12
|
+
return new RegExp(`^(?:${result})$`);
|
|
13
|
+
}
|
|
14
|
+
return input;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { toRegExp };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function transformer(input, methodName) {
|
|
4
|
+
if (input
|
|
5
|
+
&& typeof input === "object"
|
|
6
|
+
&& methodName in input
|
|
7
|
+
&& typeof input[methodName] === "function") {
|
|
8
|
+
return input[methodName]();
|
|
9
|
+
}
|
|
10
|
+
else if (typeof input === "object"
|
|
11
|
+
&& input !== null
|
|
12
|
+
&& (!input.constructor
|
|
13
|
+
|| input.constructor.name === "Object")) {
|
|
14
|
+
const result = {};
|
|
15
|
+
for (const key in input) {
|
|
16
|
+
result[key] = transformer(input[key], methodName);
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
else if (input instanceof Array
|
|
21
|
+
&& input.constructor.name === "Array") {
|
|
22
|
+
const length = input.length;
|
|
23
|
+
const result = [];
|
|
24
|
+
for (let index = 0; index < length; index++) {
|
|
25
|
+
result[index] = transformer(input[index], methodName);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return input;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* {@include common/createTransformer/index.md}
|
|
35
|
+
*/
|
|
36
|
+
function createTransformer(methodName) {
|
|
37
|
+
return (input) => transformer(input, methodName);
|
|
38
|
+
}
|
|
39
|
+
const toNative = createTransformer("toNative");
|
|
40
|
+
const toJSON = createTransformer("toJSON");
|
|
41
|
+
|
|
42
|
+
exports.createTransformer = createTransformer;
|
|
43
|
+
exports.toJSON = toJSON;
|
|
44
|
+
exports.toNative = toNative;
|
|
45
|
+
exports.transformer = transformer;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { GetPropsWithValueExtends } from "../object/types";
|
|
2
|
+
import type { Adaptor, AnyFunction, IsEqual, NeverCoalescing, Or, UnionToIntersection } from "./types";
|
|
3
|
+
export type Transformer<GenericValue extends unknown, GenericMethodName extends string> = GenericValue extends Record<GenericMethodName, () => unknown> ? ReturnType<GenericValue[GenericMethodName]> : GenericValue extends readonly [infer InferredFirst, ...infer InferredRest] ? [
|
|
4
|
+
Transformer<InferredFirst, GenericMethodName>,
|
|
5
|
+
...Adaptor<Transformer<InferredRest, GenericMethodName>, readonly any[]>
|
|
6
|
+
] : GenericValue extends readonly [] ? [] : GenericValue extends readonly any[] ? Transformer<GenericValue[number], GenericMethodName>[] : GenericValue extends string ? GenericValue : GenericValue extends Record<number, unknown> ? {
|
|
7
|
+
[Prop in keyof GenericValue]: Transformer<GenericValue[Prop], GenericMethodName>;
|
|
8
|
+
} : GenericValue;
|
|
9
|
+
declare const SymbolTransformError: unique symbol;
|
|
10
|
+
export type CheckTransformArgument<GenericValue extends unknown, GenericMethodName extends string = string> = NeverCoalescing<GenericValue extends any ? (Or<[
|
|
11
|
+
IsEqual<GenericValue, unknown>,
|
|
12
|
+
IsEqual<GenericValue, never>,
|
|
13
|
+
IsEqual<GenericValue, object>,
|
|
14
|
+
IsEqual<GenericValue, any>,
|
|
15
|
+
IsEqual<GenericMethodName, string>
|
|
16
|
+
]> extends true ? {
|
|
17
|
+
[SymbolTransformError]: "Input contain an indeterminate value.";
|
|
18
|
+
} : GenericValue extends Record<GenericMethodName, () => unknown> ? unknown : GenericValue extends Record<GenericMethodName, AnyFunction> ? {
|
|
19
|
+
[SymbolTransformError]: `A method ${GenericMethodName} in input have an argument.`;
|
|
20
|
+
} : GenericValue extends readonly [infer InferredFirst, ...infer InferredRest] ? (CheckTransformArgument<InferredFirst, GenericMethodName> & CheckTransformArgument<InferredRest, GenericMethodName>) : GenericValue extends readonly [] ? unknown : GenericValue extends string ? unknown : GenericValue extends readonly (infer InferredValue)[] ? CheckTransformArgument<InferredValue, GenericMethodName> : GenericValue extends Record<number, unknown> ? {
|
|
21
|
+
[Prop in keyof GenericValue]: CheckTransformArgument<GenericValue[Prop], GenericMethodName>;
|
|
22
|
+
} extends infer InferredResult extends object ? UnionToIntersection<NeverCoalescing<InferredResult[GetPropsWithValueExtends<InferredResult, object>], unknown>> : never : unknown) extends infer InferredResult ? IsEqual<InferredResult, unknown> extends true ? never : InferredResult : never : never, unknown>;
|
|
23
|
+
export declare function transformer<GenericInput extends unknown, GenericMethodName extends string>(input: GenericInput & CheckTransformArgument<GenericInput, GenericMethodName>, methodName: GenericMethodName): Transformer<GenericInput, GenericMethodName>;
|
|
24
|
+
export type TransformerFunction<GenericMethodName extends string = string> = <GenericInput extends unknown>(input: GenericInput) => Transformer<GenericInput, GenericMethodName>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a recursive transformer function based on a method name.
|
|
27
|
+
*
|
|
28
|
+
* Signature: `createTransformer(methodName)` → `TransformerFunction`
|
|
29
|
+
*
|
|
30
|
+
* The returned function walks through nested objects and arrays, and calls `methodName()` on values that implement it.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const input = {
|
|
34
|
+
* date: D.create("2024-01-01"),
|
|
35
|
+
* duration: D.createTime(90, "minute"),
|
|
36
|
+
* list: [D.create("2024-01-02")],
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* const nativeValues = toNative(input);
|
|
40
|
+
* // nativeValues: { date: Date; duration: number; list: Date[] }
|
|
41
|
+
*
|
|
42
|
+
* const jsonValues = toJSON(input);
|
|
43
|
+
* // jsonValues: { date: SerializedTheDate; duration: SerializedTheTime; list: SerializedTheDate[] }
|
|
44
|
+
*
|
|
45
|
+
* const toStringTree = createTransformer("toString");
|
|
46
|
+
* const stringValues = toStringTree(input);
|
|
47
|
+
* // stringValues: string-based recursive projection
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* - Two default transformers are provided out of the box: `toNative` and `toJSON`.
|
|
52
|
+
*
|
|
53
|
+
* @see https://utils.duplojs.dev/en/v1/api/common/createTransformer
|
|
54
|
+
*
|
|
55
|
+
* @namespace C
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
export declare function createTransformer<GenericMethodName extends string>(methodName: GenericMethodName): TransformerFunction<GenericMethodName>;
|
|
59
|
+
export declare const toNative: TransformerFunction<"toNative">;
|
|
60
|
+
export declare const toJSON: TransformerFunction<"toJSON">;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
function transformer(input, methodName) {
|
|
2
|
+
if (input
|
|
3
|
+
&& typeof input === "object"
|
|
4
|
+
&& methodName in input
|
|
5
|
+
&& typeof input[methodName] === "function") {
|
|
6
|
+
return input[methodName]();
|
|
7
|
+
}
|
|
8
|
+
else if (typeof input === "object"
|
|
9
|
+
&& input !== null
|
|
10
|
+
&& (!input.constructor
|
|
11
|
+
|| input.constructor.name === "Object")) {
|
|
12
|
+
const result = {};
|
|
13
|
+
for (const key in input) {
|
|
14
|
+
result[key] = transformer(input[key], methodName);
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
else if (input instanceof Array
|
|
19
|
+
&& input.constructor.name === "Array") {
|
|
20
|
+
const length = input.length;
|
|
21
|
+
const result = [];
|
|
22
|
+
for (let index = 0; index < length; index++) {
|
|
23
|
+
result[index] = transformer(input[index], methodName);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return input;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* {@include common/createTransformer/index.md}
|
|
33
|
+
*/
|
|
34
|
+
function createTransformer(methodName) {
|
|
35
|
+
return (input) => transformer(input, methodName);
|
|
36
|
+
}
|
|
37
|
+
const toNative = createTransformer("toNative");
|
|
38
|
+
const toJSON = createTransformer("toJSON");
|
|
39
|
+
|
|
40
|
+
export { createTransformer, toJSON, toNative, transformer };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type DeepReadonly<GenericValue extends unknown> = GenericValue extends
|
|
1
|
+
export type DeepReadonly<GenericValue extends unknown> = GenericValue extends Record<number, unknown> ? {
|
|
2
2
|
readonly [Prop in keyof GenericValue]: DeepReadonly<GenericValue[Prop]>;
|
|
3
3
|
} : GenericValue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type ToLargeEnsemble<GenericValue extends unknown> = GenericValue extends string ? string : GenericValue extends number ? number : GenericValue extends bigint ? bigint : GenericValue extends boolean ? boolean : GenericValue extends null ? null : GenericValue extends undefined ? undefined : GenericValue extends symbol ? symbol : GenericValue extends [infer InferredValue, ...infer InferredRest] ? [
|
|
2
2
|
ToLargeEnsemble<InferredValue>,
|
|
3
3
|
...ToLargeEnsemble<InferredRest>
|
|
4
|
-
] : GenericValue extends never[] ? [] : GenericValue extends (infer InferredValue)[] ? ToLargeEnsemble<InferredValue>[] : GenericValue extends
|
|
4
|
+
] : GenericValue extends never[] ? [] : GenericValue extends (infer InferredValue)[] ? ToLargeEnsemble<InferredValue>[] : GenericValue extends Record<number, unknown> ? {
|
|
5
5
|
[Prop in keyof GenericValue]: ToLargeEnsemble<GenericValue[Prop]>;
|
|
6
|
-
} : GenericValue extends (...args: infer InferredArgs) => infer InferredReturn ? (...args: ToLargeEnsemble<InferredArgs>) => ToLargeEnsemble<InferredReturn> : GenericValue extends Promise<infer InferredValue> ? InferredValue :
|
|
6
|
+
} : GenericValue extends (...args: infer InferredArgs) => infer InferredReturn ? (...args: ToLargeEnsemble<InferredArgs>) => ToLargeEnsemble<InferredReturn> : GenericValue extends Promise<infer InferredValue> ? InferredValue : GenericValue;
|
|
@@ -15,19 +15,21 @@ function createError() {
|
|
|
15
15
|
currentPath: [],
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
function addIssue(error, source, data) {
|
|
18
|
+
function addIssue(error, source, data, moreInformation) {
|
|
19
19
|
error.issues.push(errorIssueKind.setTo({
|
|
20
20
|
source,
|
|
21
21
|
path: error.currentPath.join("."),
|
|
22
22
|
data,
|
|
23
|
+
moreInformation,
|
|
23
24
|
}));
|
|
24
25
|
return error;
|
|
25
26
|
}
|
|
26
|
-
function addPromiseIssue(error, source, data) {
|
|
27
|
+
function addPromiseIssue(error, source, data, moreInformation) {
|
|
27
28
|
error.issues.push(errorPromiseIssueKind.setTo({
|
|
28
29
|
source,
|
|
29
30
|
path: error.currentPath.join("."),
|
|
30
31
|
data,
|
|
32
|
+
moreInformation,
|
|
31
33
|
}));
|
|
32
34
|
return error;
|
|
33
35
|
}
|
|
@@ -10,6 +10,7 @@ export interface DataParserErrorIssue extends Kind<typeof errorIssueKind.definit
|
|
|
10
10
|
readonly source: DataParser | DataParserCheckers;
|
|
11
11
|
readonly path: string;
|
|
12
12
|
readonly data: unknown;
|
|
13
|
+
readonly moreInformation?: string;
|
|
13
14
|
}
|
|
14
15
|
export declare const SymbolDataParserErrorPromiseIssueLabel = "SymbolDataParserErrorPromiseIssue";
|
|
15
16
|
export declare const SymbolDataParserErrorPromiseIssue: unique symbol;
|
|
@@ -19,6 +20,7 @@ export interface DataParserErrorPromiseIssue extends Kind<typeof errorPromiseIss
|
|
|
19
20
|
readonly source: DataParserTransform;
|
|
20
21
|
readonly path: string;
|
|
21
22
|
readonly data: unknown;
|
|
23
|
+
readonly moreInformation?: string;
|
|
22
24
|
}
|
|
23
25
|
export declare const errorKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsDataParser/error", unknown>>;
|
|
24
26
|
export interface DataParserError extends Kind<typeof errorKind.definition> {
|
|
@@ -26,7 +28,7 @@ export interface DataParserError extends Kind<typeof errorKind.definition> {
|
|
|
26
28
|
readonly currentPath: string[];
|
|
27
29
|
}
|
|
28
30
|
export declare function createError(): DataParserError;
|
|
29
|
-
export declare function addIssue(error: DataParserError, source: DataParser | DataParserCheckers, data: unknown): DataParserError;
|
|
30
|
-
export declare function addPromiseIssue(error: DataParserError, source: DataParserTransform, data: unknown): DataParserError;
|
|
31
|
+
export declare function addIssue(error: DataParserError, source: DataParser | DataParserCheckers, data: unknown, moreInformation?: string): DataParserError;
|
|
32
|
+
export declare function addPromiseIssue(error: DataParserError, source: DataParserTransform, data: unknown, moreInformation?: string): DataParserError;
|
|
31
33
|
export declare function setErrorPath(error: DataParserError, value: string, index: number): DataParserError;
|
|
32
34
|
export declare function popErrorPath(error: DataParserError): DataParserError;
|
|
@@ -13,19 +13,21 @@ function createError() {
|
|
|
13
13
|
currentPath: [],
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
function addIssue(error, source, data) {
|
|
16
|
+
function addIssue(error, source, data, moreInformation) {
|
|
17
17
|
error.issues.push(errorIssueKind.setTo({
|
|
18
18
|
source,
|
|
19
19
|
path: error.currentPath.join("."),
|
|
20
20
|
data,
|
|
21
|
+
moreInformation,
|
|
21
22
|
}));
|
|
22
23
|
return error;
|
|
23
24
|
}
|
|
24
|
-
function addPromiseIssue(error, source, data) {
|
|
25
|
+
function addPromiseIssue(error, source, data, moreInformation) {
|
|
25
26
|
error.issues.push(errorPromiseIssueKind.setTo({
|
|
26
27
|
source,
|
|
27
28
|
path: error.currentPath.join("."),
|
|
28
29
|
data,
|
|
30
|
+
moreInformation,
|
|
29
31
|
}));
|
|
30
32
|
return error;
|
|
31
33
|
}
|
|
@@ -16,12 +16,11 @@ export interface DataParserDateExtended<GenericDefinition extends dataParsers.Da
|
|
|
16
16
|
refine(theFunction: (input: Output<this>) => boolean, definition?: Partial<Omit<dataParsers.DataParserCheckerDefinitionRefine, "theFunction">>): DataParserDateExtended<AddCheckersToDefinition<GenericDefinition, readonly [dataParsers.CheckerRefineImplementation<Output<this>>]>>;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Creates an extended
|
|
19
|
+
* Creates an extended parser for `TheDate`.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
* - Method: `DPE.date(definition?)` -> returns a date parser
|
|
21
|
+
* Signature: `DPE.date(definition?)` → `DataParserDateExtended`
|
|
23
22
|
*
|
|
24
|
-
*
|
|
23
|
+
* This parser extends classic `DP.date(...)` behavior and keeps the extended chainable base API (`nullable`, `optional`, `pipe`, `transform`, etc.).
|
|
25
24
|
*
|
|
26
25
|
* ```ts
|
|
27
26
|
* const parser = DPE.date();
|
|
@@ -33,11 +32,17 @@ export interface DataParserDateExtended<GenericDefinition extends dataParsers.Da
|
|
|
33
32
|
*
|
|
34
33
|
* const coerceParser = DPE.coerce.date();
|
|
35
34
|
* const coerceResult = coerceParser.parse("2024-01-01T00:00:00.000Z");
|
|
35
|
+
* // coerceResult: E.Error<DP.DataParserError> | E.Success<TheDate>
|
|
36
36
|
*
|
|
37
37
|
* const nullableDate = DPE.date().nullable();
|
|
38
38
|
* const nullableResult = nullableDate.parse(null);
|
|
39
|
+
* // nullableResult: E.Error<DPE.DataParserError> | E.Success<TheDate | null>
|
|
39
40
|
* ```
|
|
40
41
|
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* - Parsed output is always `TheDate`.
|
|
44
|
+
* - `DPE.coerce.date()` enables coercion by default.
|
|
45
|
+
*
|
|
41
46
|
* @see https://utils.duplojs.dev/en/v1/api/dataParser/date
|
|
42
47
|
*
|
|
43
48
|
* @namespace DPE
|