@duplojs/utils 1.4.59 → 1.5.1

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.
@@ -1075,7 +1075,10 @@ const mimeType = (() => {
1075
1075
  results.set(extension, type);
1076
1076
  }
1077
1077
  }
1078
- return results;
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 a map that resolves file extensions to their MIME types.
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, the map returns `undefined`.
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: Map<string, string>;
31
+ export declare const mimeType: MimeTypeStore;
@@ -1073,7 +1073,10 @@ const mimeType = (() => {
1073
1073
  results.set(extension, type);
1074
1074
  }
1075
1075
  }
1076
- return results;
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), {}, nullable.overrideHandler);
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(DPE.number(), { coalescingValue: 0 });
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), {}, nullable.overrideHandler);
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), {}, optional.overrideHandler);
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(DPE.number(), { coalescingValue: 0 });
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), {}, optional.overrideHandler);
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");
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var unwrap = require('../common/unwrap.cjs');
4
- var override = require('../object/override.cjs');
4
+ var reduce = require('../array/reduce.cjs');
5
5
 
6
6
  function asyncReduce(...args) {
7
7
  if (args.length === 2) {
@@ -17,11 +17,7 @@ function asyncReduce(...args) {
17
17
  element,
18
18
  index,
19
19
  lastValue,
20
- nextWithObject: ((object1, object2) => ({
21
- "-next": override.override(object1, object2),
22
- })),
23
- exit: (output) => ({ "-exit": output }),
24
- next: (output) => ({ "-next": output }),
20
+ ...reduce.reduceTools,
25
21
  });
26
22
  if ("-exit" in result) {
27
23
  return result["-exit"];
@@ -1,5 +1,5 @@
1
1
  import { unwrap } from '../common/unwrap.mjs';
2
- import { override } from '../object/override.mjs';
2
+ import { reduceTools } from '../array/reduce.mjs';
3
3
 
4
4
  function asyncReduce(...args) {
5
5
  if (args.length === 2) {
@@ -15,11 +15,7 @@ function asyncReduce(...args) {
15
15
  element,
16
16
  index,
17
17
  lastValue,
18
- nextWithObject: ((object1, object2) => ({
19
- "-next": override(object1, object2),
20
- })),
21
- exit: (output) => ({ "-exit": output }),
22
- next: (output) => ({ "-next": output }),
18
+ ...reduceTools,
23
19
  });
24
20
  if ("-exit" in result) {
25
21
  return result["-exit"];
@@ -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) => GeneratorReduceExit<GenericOutput> : undefined;
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> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/utils",
3
- "version": "1.4.59",
3
+ "version": "1.5.1",
4
4
  "author": {
5
5
  "name": "mathcovax",
6
6
  "url": "https://github.com/mathcovax"