@duplojs/utils 1.5.4 → 1.5.5
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/index.d.ts +1 -0
- package/dist/common/justExec.cjs +10 -0
- package/dist/common/justExec.d.ts +28 -0
- package/dist/common/justExec.mjs +8 -0
- package/dist/common/stringToBytes.cjs +1 -1
- package/dist/common/stringToBytes.mjs +1 -1
- package/dist/dataParser/baseExtended.cjs +3 -0
- package/dist/dataParser/baseExtended.d.ts +5 -1
- package/dist/dataParser/baseExtended.mjs +3 -0
- package/dist/index.cjs +2 -0
- package/dist/index.mjs +1 -0
- package/dist/metadata.json +9 -0
- package/package.json +1 -1
package/dist/common/index.d.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The justExec() function executes a callback immediately and returns the callback result.
|
|
3
|
+
*
|
|
4
|
+
* **Supported call styles:**
|
|
5
|
+
* - Classic: `justExec(theFunction)` -> executes `theFunction` and returns its output
|
|
6
|
+
* - Curried: not available for this function
|
|
7
|
+
*
|
|
8
|
+
* The callback is called once per invocation. The function itself does not transform the callback output.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const numberResult = justExec(
|
|
12
|
+
* () => 42 as const,
|
|
13
|
+
* );
|
|
14
|
+
* // type: 42
|
|
15
|
+
*
|
|
16
|
+
* const objectResult = justExec(
|
|
17
|
+
* () => ({
|
|
18
|
+
* id: 1,
|
|
19
|
+
* name: "ZeRiix",
|
|
20
|
+
* }),
|
|
21
|
+
* );
|
|
22
|
+
* // type: { id: number; name: string; }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @see https://utils.duplojs.dev/en/v1/api/common/justExec
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
export declare function justExec<GenericOutput extends unknown>(theFunction: () => GenericOutput): GenericOutput;
|
|
@@ -12,7 +12,7 @@ class InvalidBytesInStringError extends kind.kindHeritage("invalid-bytes-in-stri
|
|
|
12
12
|
this.input = input;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
const parseRegExp = /(?<rawValue>[0-9.]+)(?<unit>b|kb|mb|gb|tb|
|
|
15
|
+
const parseRegExp = /(?<rawValue>[0-9.]+)(?<unit>b|kb|mb|gb|tb|pb)/;
|
|
16
16
|
const unitMapper = {
|
|
17
17
|
b: 1,
|
|
18
18
|
kb: 1 << 10,
|
|
@@ -10,7 +10,7 @@ class InvalidBytesInStringError extends kindHeritage("invalid-bytes-in-string-er
|
|
|
10
10
|
this.input = input;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
const parseRegExp = /(?<rawValue>[0-9.]+)(?<unit>b|kb|mb|gb|tb|
|
|
13
|
+
const parseRegExp = /(?<rawValue>[0-9.]+)(?<unit>b|kb|mb|gb|tb|pb)/;
|
|
14
14
|
const unitMapper = {
|
|
15
15
|
b: 1,
|
|
16
16
|
kb: 1 << 10,
|
|
@@ -62,6 +62,9 @@ function dataParserExtendedInit(dataParser, rest, specificOverrideHandler) {
|
|
|
62
62
|
contract() {
|
|
63
63
|
return self;
|
|
64
64
|
},
|
|
65
|
+
contractExtended() {
|
|
66
|
+
return self;
|
|
67
|
+
},
|
|
65
68
|
}, extendedKind.setTo, dataParserExtendedInit.overrideHandler.apply, specificOverrideHandler.apply);
|
|
66
69
|
return self;
|
|
67
70
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Kind, type NeverCoalescing, type AnyFunction, type SimplifyTopLevel, type AnyValue, type OverrideHandler, type GetKind, type RemoveKind } from "../common";
|
|
1
|
+
import { type Kind, type NeverCoalescing, type AnyFunction, type SimplifyTopLevel, type AnyValue, type OverrideHandler, type GetKind, type RemoveKind, type IsEqual } from "../common";
|
|
2
2
|
import { type MergeDefinition } from "./types";
|
|
3
3
|
import { type Output, type DataParser, type DataParserDefinition } from "./base";
|
|
4
4
|
import type * as DEither from "../either";
|
|
@@ -7,6 +7,7 @@ import * as dataParsersExtended from "./extended";
|
|
|
7
7
|
import { type DataParserError } from "./error";
|
|
8
8
|
export declare const extendedKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsDataParser/extended", unknown>>;
|
|
9
9
|
type _DataParserExtended<GenericDefinition extends DataParserDefinition, GenericOutput extends unknown, GenericInput extends unknown> = (DataParser<GenericDefinition, GenericOutput, GenericInput> & Kind<typeof extendedKind.definition>);
|
|
10
|
+
declare const SymbolContractExtendedError: unique symbol;
|
|
10
11
|
export interface DataParserExtended<GenericDefinition extends DataParserDefinition = DataParserDefinition, GenericOutput extends unknown = unknown, GenericInput extends unknown = GenericOutput> extends _DataParserExtended<GenericDefinition, GenericOutput, GenericInput> {
|
|
11
12
|
/**
|
|
12
13
|
* The parse() method runs an extended data parser synchronously and returns an Either with the parsed value or a DataParserError.
|
|
@@ -149,6 +150,9 @@ export interface DataParserExtended<GenericDefinition extends DataParserDefiniti
|
|
|
149
150
|
*
|
|
150
151
|
*/
|
|
151
152
|
clone(): this;
|
|
153
|
+
contractExtended<GenericValue extends unknown>(...args: IsEqual<Output<this>, GenericValue> extends true ? [] : [] & {
|
|
154
|
+
[SymbolContractExtendedError]: "ContractExtended error.";
|
|
155
|
+
}): ContractExtended<GenericValue>;
|
|
152
156
|
/**
|
|
153
157
|
* Creates an array parser from the current parser.
|
|
154
158
|
*
|
|
@@ -60,6 +60,9 @@ function dataParserExtendedInit(dataParser, rest, specificOverrideHandler) {
|
|
|
60
60
|
contract() {
|
|
61
61
|
return self;
|
|
62
62
|
},
|
|
63
|
+
contractExtended() {
|
|
64
|
+
return self;
|
|
65
|
+
},
|
|
63
66
|
}, extendedKind.setTo, dataParserExtendedInit.overrideHandler.apply, specificOverrideHandler.apply);
|
|
64
67
|
return self;
|
|
65
68
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -65,6 +65,7 @@ var asserts = require('./common/asserts.cjs');
|
|
|
65
65
|
var path = require('./common/path.cjs');
|
|
66
66
|
var transformer = require('./common/transformer.cjs');
|
|
67
67
|
var toRegExp = require('./common/toRegExp.cjs');
|
|
68
|
+
var justExec = require('./common/justExec.cjs');
|
|
68
69
|
|
|
69
70
|
|
|
70
71
|
|
|
@@ -165,3 +166,4 @@ exports.toJSON = transformer.toJSON;
|
|
|
165
166
|
exports.toNative = transformer.toNative;
|
|
166
167
|
exports.transformer = transformer.transformer;
|
|
167
168
|
exports.toRegExp = toRegExp.toRegExp;
|
|
169
|
+
exports.justExec = justExec.justExec;
|
package/dist/index.mjs
CHANGED
|
@@ -87,3 +87,4 @@ export { AssertsError, asserts } from './common/asserts.mjs';
|
|
|
87
87
|
export { Path } from './common/path.mjs';
|
|
88
88
|
export { createTransformer, toJSON, toNative, transformer } from './common/transformer.mjs';
|
|
89
89
|
export { toRegExp } from './common/toRegExp.mjs';
|
|
90
|
+
export { justExec } from './common/justExec.mjs';
|
package/dist/metadata.json
CHANGED