@duplojs/utils 1.4.59 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/mimeType.cjs +4 -1
- package/dist/common/mimeType.d.ts +12 -3
- package/dist/common/mimeType.mjs +4 -1
- package/dist/dataParser/extended/nullable.cjs +6 -1
- package/dist/dataParser/extended/nullable.d.ts +11 -2
- package/dist/dataParser/extended/nullable.mjs +6 -1
- package/dist/dataParser/extended/optional.cjs +6 -1
- package/dist/dataParser/extended/optional.d.ts +11 -2
- package/dist/dataParser/extended/optional.mjs +6 -1
- package/dist/generator/reduce.d.ts +1 -1
- package/package.json +1 -1
package/dist/common/mimeType.cjs
CHANGED
|
@@ -1075,7 +1075,10 @@ const mimeType = (() => {
|
|
|
1075
1075
|
results.set(extension, type);
|
|
1076
1076
|
}
|
|
1077
1077
|
}
|
|
1078
|
-
return
|
|
1078
|
+
return {
|
|
1079
|
+
get: (extensionName) => results.get(extensionName.toLowerCase()),
|
|
1080
|
+
set: (extensionName, mimeType) => void results.set(extensionName.toLowerCase(), mimeType.toLowerCase()),
|
|
1081
|
+
};
|
|
1079
1082
|
})();
|
|
1080
1083
|
|
|
1081
1084
|
exports.mimeType = mimeType;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
export interface MimeTypeStore {
|
|
2
|
+
get(extensionName: string): string | undefined;
|
|
3
|
+
set(extensionName: string, mimeType: string): void;
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
|
-
* Provides
|
|
6
|
+
* Provides an object that resolves file extensions to their MIME types and allows custom registrations.
|
|
3
7
|
*
|
|
4
8
|
* **Supported call styles:**
|
|
5
9
|
* - Access: `mimeType.get(extension)` -> returns the MIME type or undefined
|
|
10
|
+
* - Registration: `mimeType.set(extension, mimeType)` -> stores or overrides a MIME type for an extension
|
|
6
11
|
*
|
|
7
12
|
* Extensions are stored without the leading dot and should be passed in lower case.
|
|
8
|
-
* When an extension is not present,
|
|
13
|
+
* When an extension is not present, `mimeType.get(...)` returns `undefined`.
|
|
9
14
|
*
|
|
10
15
|
* ```ts
|
|
11
16
|
* const jsonType = mimeType.get("json");
|
|
@@ -14,9 +19,13 @@
|
|
|
14
19
|
* // svgType: "image/svg+xml"
|
|
15
20
|
* const unknownType = mimeType.get("unknown");
|
|
16
21
|
* // unknownType: undefined
|
|
22
|
+
*
|
|
23
|
+
* mimeType.set("txtnull", "text-null/plain");
|
|
24
|
+
* const customType = mimeType.get("txtnull");
|
|
25
|
+
* // customType: "text-null/plain"
|
|
17
26
|
* ```
|
|
18
27
|
*
|
|
19
28
|
* @see https://utils.duplojs.dev/en/v1/api/common/mimeType
|
|
20
29
|
*
|
|
21
30
|
*/
|
|
22
|
-
export declare const mimeType:
|
|
31
|
+
export declare const mimeType: MimeTypeStore;
|
package/dist/common/mimeType.mjs
CHANGED
|
@@ -1073,7 +1073,10 @@ const mimeType = (() => {
|
|
|
1073
1073
|
results.set(extension, type);
|
|
1074
1074
|
}
|
|
1075
1075
|
}
|
|
1076
|
-
return
|
|
1076
|
+
return {
|
|
1077
|
+
get: (extensionName) => results.get(extensionName.toLowerCase()),
|
|
1078
|
+
set: (extensionName, mimeType) => void results.set(extensionName.toLowerCase(), mimeType.toLowerCase()),
|
|
1079
|
+
};
|
|
1077
1080
|
})();
|
|
1078
1081
|
|
|
1079
1082
|
export { mimeType };
|
|
@@ -8,7 +8,12 @@ var override = require('../../common/override.cjs');
|
|
|
8
8
|
* {@include dataParser/extended/nullable/index.md}
|
|
9
9
|
*/
|
|
10
10
|
function nullable(inner, definition) {
|
|
11
|
-
const self = baseExtended.dataParserExtendedInit(nullable$1.nullable(inner, definition), {
|
|
11
|
+
const self = baseExtended.dataParserExtendedInit(nullable$1.nullable(inner, definition), {
|
|
12
|
+
default: (self, value) => nullable(self.definition.inner, {
|
|
13
|
+
...self.definition,
|
|
14
|
+
coalescingValue: value,
|
|
15
|
+
}),
|
|
16
|
+
}, nullable.overrideHandler);
|
|
12
17
|
return self;
|
|
13
18
|
}
|
|
14
19
|
nullable.overrideHandler = override.createOverride("@duplojs/utils/data-parser-extended/nullable");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FixDeepFunctionInfer, type IsEqual, type Kind, type NeverCoalescing } from "../../common";
|
|
1
|
+
import { type FixDeepFunctionInfer, type IsEqual, type Kind, type NeverCoalescing, type SimplifyTopLevel } from "../../common";
|
|
2
2
|
import { type DataParserExtended } from "../baseExtended";
|
|
3
3
|
import { type AddCheckersToDefinition, type MergeDefinition } from "../types";
|
|
4
4
|
import * as dataParsers from "../parsers";
|
|
@@ -13,6 +13,13 @@ export interface DataParserNullableExtended<GenericDefinition extends dataParser
|
|
|
13
13
|
...dataParsers.DataParserNullableCheckers<Output<this>>[]
|
|
14
14
|
], GenericChecker>): DataParserNullableExtended<AddCheckersToDefinition<GenericDefinition, GenericChecker>>;
|
|
15
15
|
refine(theFunction: (input: Output<this>) => boolean, definition?: Partial<Omit<dataParsers.DataParserCheckerDefinitionRefine, "theFunction">>): DataParserNullableExtended<AddCheckersToDefinition<GenericDefinition, readonly [dataParsers.CheckerRefineImplementation<Output<this>>]>>;
|
|
16
|
+
/**
|
|
17
|
+
* Alias to define the default value
|
|
18
|
+
* Using `default()` is equivalent to defining the `coalescingValue` in the dataParser definition.
|
|
19
|
+
*/
|
|
20
|
+
default<GenericInput extends Output<GenericDefinition["inner"]>>(input: GenericInput): DataParserNullableExtended<SimplifyTopLevel<Omit<GenericDefinition, "coalescingValue"> & {
|
|
21
|
+
readonly coalescingValue: GenericInput;
|
|
22
|
+
}>>;
|
|
16
23
|
}
|
|
17
24
|
/**
|
|
18
25
|
* Creates an extended nullable parser from another parser.
|
|
@@ -30,11 +37,13 @@ export interface DataParserNullableExtended<GenericDefinition extends dataParser
|
|
|
30
37
|
* // value: string | null
|
|
31
38
|
* }
|
|
32
39
|
*
|
|
33
|
-
* const withCoalescing = DPE.nullable(
|
|
40
|
+
* const withCoalescing = DPE.number().nullable().default(0);
|
|
34
41
|
* const coalesced = withCoalescing.parse(null);
|
|
42
|
+
* // E.Error<DPE.DataParserError> | E.Success<number>
|
|
35
43
|
*
|
|
36
44
|
* const nullableBool = DPE.nullable(DPE.boolean());
|
|
37
45
|
* const boolResult = nullableBool.parse(true);
|
|
46
|
+
* // E.Error<DPE.DataParserError> | E.Success<boolean | null>
|
|
38
47
|
* ```
|
|
39
48
|
*
|
|
40
49
|
* @see https://utils.duplojs.dev/en/v1/api/dataParser/nullable
|
|
@@ -6,7 +6,12 @@ import { createOverride } from '../../common/override.mjs';
|
|
|
6
6
|
* {@include dataParser/extended/nullable/index.md}
|
|
7
7
|
*/
|
|
8
8
|
function nullable(inner, definition) {
|
|
9
|
-
const self = dataParserExtendedInit(nullable$1(inner, definition), {
|
|
9
|
+
const self = dataParserExtendedInit(nullable$1(inner, definition), {
|
|
10
|
+
default: (self, value) => nullable(self.definition.inner, {
|
|
11
|
+
...self.definition,
|
|
12
|
+
coalescingValue: value,
|
|
13
|
+
}),
|
|
14
|
+
}, nullable.overrideHandler);
|
|
10
15
|
return self;
|
|
11
16
|
}
|
|
12
17
|
nullable.overrideHandler = createOverride("@duplojs/utils/data-parser-extended/nullable");
|
|
@@ -8,7 +8,12 @@ var override = require('../../common/override.cjs');
|
|
|
8
8
|
* {@include dataParser/extended/optional/index.md}
|
|
9
9
|
*/
|
|
10
10
|
function optional(inner, definition) {
|
|
11
|
-
const self = baseExtended.dataParserExtendedInit(optional$1.optional(inner, definition), {
|
|
11
|
+
const self = baseExtended.dataParserExtendedInit(optional$1.optional(inner, definition), {
|
|
12
|
+
default: (self, value) => optional(self.definition.inner, {
|
|
13
|
+
...self.definition,
|
|
14
|
+
coalescingValue: value,
|
|
15
|
+
}),
|
|
16
|
+
}, optional.overrideHandler);
|
|
12
17
|
return self;
|
|
13
18
|
}
|
|
14
19
|
optional.overrideHandler = override.createOverride("@duplojs/utils/data-parser-extended/optional");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FixDeepFunctionInfer, type IsEqual, type Kind, type NeverCoalescing } from "../../common";
|
|
1
|
+
import { type FixDeepFunctionInfer, type IsEqual, type Kind, type NeverCoalescing, type SimplifyTopLevel } from "../../common";
|
|
2
2
|
import { type DataParserExtended } from "../baseExtended";
|
|
3
3
|
import { type AddCheckersToDefinition, type MergeDefinition } from "../types";
|
|
4
4
|
import * as dataParsers from "../parsers";
|
|
@@ -13,6 +13,13 @@ export interface DataParserOptionalExtended<GenericDefinition extends dataParser
|
|
|
13
13
|
...dataParsers.DataParserOptionalCheckers<Output<this>>[]
|
|
14
14
|
], GenericChecker>): DataParserOptionalExtended<AddCheckersToDefinition<GenericDefinition, GenericChecker>>;
|
|
15
15
|
refine(theFunction: (input: Output<this>) => boolean, definition?: Partial<Omit<dataParsers.DataParserCheckerDefinitionRefine, "theFunction">>): DataParserOptionalExtended<AddCheckersToDefinition<GenericDefinition, readonly [dataParsers.CheckerRefineImplementation<Output<this>>]>>;
|
|
16
|
+
/**
|
|
17
|
+
* Alias to define the default value
|
|
18
|
+
* Using `default()` is equivalent to defining the `coalescingValue` in the dataParser definition.
|
|
19
|
+
*/
|
|
20
|
+
default<GenericInput extends Output<GenericDefinition["inner"]>>(input: GenericInput): DataParserOptionalExtended<SimplifyTopLevel<Omit<GenericDefinition, "coalescingValue"> & {
|
|
21
|
+
readonly coalescingValue: GenericInput;
|
|
22
|
+
}>>;
|
|
16
23
|
}
|
|
17
24
|
/**
|
|
18
25
|
* Creates an extended optional parser from another parser.
|
|
@@ -30,11 +37,13 @@ export interface DataParserOptionalExtended<GenericDefinition extends dataParser
|
|
|
30
37
|
* // value: string | undefined
|
|
31
38
|
* }
|
|
32
39
|
*
|
|
33
|
-
* const withCoalescing = DPE.optional(
|
|
40
|
+
* const withCoalescing = DPE.number().optional().default(0);
|
|
34
41
|
* const coalesced = withCoalescing.parse(undefined);
|
|
42
|
+
* // E.Error<DPE.DataParserError> | E.Success<number>
|
|
35
43
|
*
|
|
36
44
|
* const optionalBool = DPE.optional(DPE.boolean());
|
|
37
45
|
* const boolResult = optionalBool.parse(true);
|
|
46
|
+
* // E.Error<DPE.DataParserError> | E.Success<boolean | undefined>
|
|
38
47
|
* ```
|
|
39
48
|
*
|
|
40
49
|
* @see https://utils.duplojs.dev/en/v1/api/dataParser/optional
|
|
@@ -6,7 +6,12 @@ import { createOverride } from '../../common/override.mjs';
|
|
|
6
6
|
* {@include dataParser/extended/optional/index.md}
|
|
7
7
|
*/
|
|
8
8
|
function optional(inner, definition) {
|
|
9
|
-
const self = dataParserExtendedInit(optional$1(inner, definition), {
|
|
9
|
+
const self = dataParserExtendedInit(optional$1(inner, definition), {
|
|
10
|
+
default: (self, value) => optional(self.definition.inner, {
|
|
11
|
+
...self.definition,
|
|
12
|
+
coalescingValue: value,
|
|
13
|
+
}),
|
|
14
|
+
}, optional.overrideHandler);
|
|
10
15
|
return self;
|
|
11
16
|
}
|
|
12
17
|
optional.overrideHandler = createOverride("@duplojs/utils/data-parser-extended/optional");
|
|
@@ -15,7 +15,7 @@ export interface GeneratorReduceFunctionParams<GenericElement extends unknown =
|
|
|
15
15
|
nextWithObject: GenericOutput extends object ? (object1: GenericOutput, object2: Partial<GenericOutput>) => GeneratorReduceNext<GenericOutput> : undefined;
|
|
16
16
|
next(output: GenericOutput): GeneratorReduceNext<GenericOutput>;
|
|
17
17
|
exit<GenericExitValue extends unknown>(output: GenericExitValue): GeneratorReduceExit<GenericExitValue>;
|
|
18
|
-
nextPush: GenericOutput extends readonly any[] ? (array: GenericOutput, ...values: GenericOutput) =>
|
|
18
|
+
nextPush: GenericOutput extends readonly any[] ? (array: GenericOutput, ...values: GenericOutput) => GeneratorReduceNext<GenericOutput> : undefined;
|
|
19
19
|
}
|
|
20
20
|
declare const generatorReduceFromKind: import("../common").KindHandler<import("../common").KindDefinition<"generator-reduce-from", unknown>>;
|
|
21
21
|
export interface GeneratorReduceFromResult<GenericValue extends unknown = unknown> extends Kind<typeof generatorReduceFromKind.definition>, WrappedValue<GenericValue> {
|