@duplojs/utils 1.3.20 → 1.3.21
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/generator/asyncChunk.cjs +24 -0
- package/dist/generator/asyncChunk.d.ts +2 -0
- package/dist/generator/asyncChunk.mjs +22 -0
- package/dist/generator/asyncLoop.d.ts +3 -10
- package/dist/generator/asyncMap.cjs +1 -1
- package/dist/generator/asyncMap.d.ts +2 -2
- package/dist/generator/asyncMap.mjs +1 -1
- package/dist/generator/index.cjs +2 -0
- package/dist/generator/index.d.ts +1 -0
- package/dist/generator/index.mjs +1 -0
- package/dist/generator/loop.d.ts +4 -5
- package/dist/object/omit.d.ts +2 -2
- package/dist/object/pick.d.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function asyncChunk(...args) {
|
|
4
|
+
if (args.length === 1) {
|
|
5
|
+
const [size] = args;
|
|
6
|
+
return (input) => asyncChunk(input, size);
|
|
7
|
+
}
|
|
8
|
+
const [input, size] = args;
|
|
9
|
+
return (async function* () {
|
|
10
|
+
let buffer = [];
|
|
11
|
+
for await (const element of input) {
|
|
12
|
+
buffer.push(element);
|
|
13
|
+
if (buffer.length === size) {
|
|
14
|
+
yield buffer;
|
|
15
|
+
buffer = [];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (buffer.length > 0) {
|
|
19
|
+
yield buffer;
|
|
20
|
+
}
|
|
21
|
+
})();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.asyncChunk = asyncChunk;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function asyncChunk<const GenericElement extends unknown>(size: number): (input: AsyncIterable<GenericElement>) => AsyncGenerator<GenericElement[], unknown, unknown>;
|
|
2
|
+
export declare function asyncChunk<const GenericElement extends unknown>(input: AsyncIterable<GenericElement>, size: number): AsyncGenerator<GenericElement[], unknown, unknown>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function asyncChunk(...args) {
|
|
2
|
+
if (args.length === 1) {
|
|
3
|
+
const [size] = args;
|
|
4
|
+
return (input) => asyncChunk(input, size);
|
|
5
|
+
}
|
|
6
|
+
const [input, size] = args;
|
|
7
|
+
return (async function* () {
|
|
8
|
+
let buffer = [];
|
|
9
|
+
for await (const element of input) {
|
|
10
|
+
buffer.push(element);
|
|
11
|
+
if (buffer.length === size) {
|
|
12
|
+
yield buffer;
|
|
13
|
+
buffer = [];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (buffer.length > 0) {
|
|
17
|
+
yield buffer;
|
|
18
|
+
}
|
|
19
|
+
})();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { asyncChunk };
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type GeneratorLoopParams } from "./loop";
|
|
3
|
-
|
|
4
|
-
"-exitData": GenericOutput | undefined;
|
|
5
|
-
}
|
|
6
|
-
interface LoopOutputNextResult<GenericOutput extends any> {
|
|
7
|
-
"-nextData": GenericOutput | undefined;
|
|
8
|
-
}
|
|
9
|
-
export declare function asyncLoop<GenericRawExitOutput extends AnyValue = undefined, GenericRawNextOutput extends AnyValue = undefined>(loop: (params: GeneratorLoopParams<GenericRawNextOutput>) => Promise<LoopOutputNextResult<GenericRawNextOutput> | LoopOutputNextResult<undefined> | LoopOutputExistResult<GenericRawExitOutput> | LoopOutputExistResult<undefined>>): AsyncGenerator<Exclude<GenericRawExitOutput | GenericRawNextOutput, undefined>, unknown, unknown>;
|
|
10
|
-
export {};
|
|
1
|
+
import { type MaybePromise } from "../common";
|
|
2
|
+
import { type LoopOutputExistResult, type LoopOutputNextResult, type GeneratorLoopParams } from "./loop";
|
|
3
|
+
export declare function asyncLoop<GenericRawNextOutput extends unknown, GenericOutput extends MaybePromise<LoopOutputNextResult<GenericRawNextOutput> | LoopOutputExistResult<unknown> | LoopOutputNextResult<undefined> | LoopOutputExistResult<undefined>>>(loop: (params: GeneratorLoopParams<GenericRawNextOutput>) => GenericOutput): AsyncGenerator<Exclude<Awaited<GenericOutput> extends infer InferredOutput ? InferredOutput extends LoopOutputNextResult ? InferredOutput["-nextData"] : InferredOutput extends LoopOutputExistResult ? InferredOutput["-exitData"] : never : never, undefined>, unknown, unknown>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
interface AsyncGeneratorMapParams {
|
|
2
2
|
index: number;
|
|
3
3
|
}
|
|
4
|
-
export declare function asyncMap<const GenericInput extends unknown, const GenericOutput extends unknown>(theFunction: (arg: GenericInput, params: AsyncGeneratorMapParams) =>
|
|
5
|
-
export declare function asyncMap<const GenericInput extends unknown, const GenericOutput extends unknown>(iterator: AsyncIterable<GenericInput> | Iterable<GenericInput>, theFunction: (arg: GenericInput, params: AsyncGeneratorMapParams) =>
|
|
4
|
+
export declare function asyncMap<const GenericInput extends unknown, const GenericOutput extends unknown>(theFunction: (arg: GenericInput, params: AsyncGeneratorMapParams) => GenericOutput): (iterator: AsyncIterable<GenericInput> | Iterable<GenericInput>) => AsyncGenerator<Awaited<GenericOutput>, unknown, unknown>;
|
|
5
|
+
export declare function asyncMap<const GenericInput extends unknown, const GenericOutput extends unknown>(iterator: AsyncIterable<GenericInput> | Iterable<GenericInput>, theFunction: (arg: GenericInput, params: AsyncGeneratorMapParams) => GenericOutput): AsyncGenerator<Awaited<GenericOutput>, unknown, unknown>;
|
|
6
6
|
export {};
|
package/dist/generator/index.cjs
CHANGED
|
@@ -10,6 +10,7 @@ var asyncReduce = require('./asyncReduce.cjs');
|
|
|
10
10
|
var loop = require('./loop.cjs');
|
|
11
11
|
var asyncLoop = require('./asyncLoop.cjs');
|
|
12
12
|
var chunk = require('./chunk.cjs');
|
|
13
|
+
var asyncChunk = require('./asyncChunk.cjs');
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
|
|
@@ -24,3 +25,4 @@ exports.asyncReduce = asyncReduce.asyncReduce;
|
|
|
24
25
|
exports.loop = loop.loop;
|
|
25
26
|
exports.asyncLoop = asyncLoop.asyncLoop;
|
|
26
27
|
exports.chunk = chunk.chunk;
|
|
28
|
+
exports.asyncChunk = asyncChunk.asyncChunk;
|
package/dist/generator/index.mjs
CHANGED
package/dist/generator/loop.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type AnyValue } from "../common";
|
|
2
|
-
interface LoopOutputExistResult<GenericOutput extends
|
|
3
|
-
"-exitData": GenericOutput
|
|
2
|
+
export interface LoopOutputExistResult<GenericOutput extends unknown = unknown> {
|
|
3
|
+
"-exitData": GenericOutput;
|
|
4
4
|
}
|
|
5
|
-
interface LoopOutputNextResult<GenericOutput extends
|
|
6
|
-
"-nextData": GenericOutput
|
|
5
|
+
export interface LoopOutputNextResult<GenericOutput extends unknown = unknown> {
|
|
6
|
+
"-nextData": GenericOutput;
|
|
7
7
|
}
|
|
8
8
|
export interface GeneratorLoopParams<GenericRawNextOutput extends any> {
|
|
9
9
|
count: number;
|
|
@@ -12,4 +12,3 @@ export interface GeneratorLoopParams<GenericRawNextOutput extends any> {
|
|
|
12
12
|
exit<GenericOutput extends AnyValue = undefined>(output?: GenericOutput): LoopOutputExistResult<GenericOutput>;
|
|
13
13
|
}
|
|
14
14
|
export declare function loop<GenericRawExitOutput extends AnyValue = undefined, GenericRawNextOutput extends AnyValue = undefined>(loop: (params: GeneratorLoopParams<GenericRawNextOutput>) => LoopOutputNextResult<GenericRawNextOutput> | LoopOutputNextResult<undefined> | LoopOutputExistResult<GenericRawExitOutput> | LoopOutputExistResult<undefined>): Generator<Exclude<GenericRawExitOutput | GenericRawNextOutput, undefined>, unknown, unknown>;
|
|
15
|
-
export {};
|
package/dist/object/omit.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import { type Adaptor } from "../common/types/adaptor";
|
|
|
3
3
|
import { type GetPropsWithValue } from "./types/getPropsWithValue";
|
|
4
4
|
import { type PartialKeys } from "./types";
|
|
5
5
|
type ComputeResultWithOmitIsObject<GenericInput extends object, GenericOmitValue extends Partial<Record<keyof GenericInput, boolean>>> = SimplifyTopLevel<Omit<GenericInput, GetPropsWithValue<GenericOmitValue, true>> extends infer InferredValue extends object ? PartialKeys<InferredValue, Adaptor<GetPropsWithValue<GenericOmitValue, boolean> | GetPropsWithValue<GenericOmitValue, boolean | undefined> | GetPropsWithValue<GenericOmitValue, true | undefined>, keyof InferredValue>> : never>;
|
|
6
|
-
export declare function omit<GenericInput extends object,
|
|
7
|
-
export declare function omit<GenericInput extends object, GenericOmitValue extends Partial<Record<keyof GenericInput, boolean>> | readonly (keyof GenericInput)[]>(input: GenericInput, omitValue: GenericOmitValue): GenericOmitValue extends Partial<Record<keyof GenericInput, boolean>> ? ComputeResultWithOmitIsObject<GenericInput, GenericOmitValue> : SimplifyTopLevel<Omit<GenericInput, Adaptor<GenericOmitValue, ObjectKey[]>[number]>>;
|
|
6
|
+
export declare function omit<GenericInput extends object, const GenericOmitValue extends Partial<Record<keyof GenericInput, boolean>> | readonly (keyof GenericInput)[]>(omitValue: GenericOmitValue): (input: GenericInput) => GenericOmitValue extends Partial<Record<keyof GenericInput, boolean>> ? ComputeResultWithOmitIsObject<GenericInput, GenericOmitValue> : SimplifyTopLevel<Omit<GenericInput, Adaptor<GenericOmitValue, readonly ObjectKey[]>[number]>>;
|
|
7
|
+
export declare function omit<GenericInput extends object, const GenericOmitValue extends Partial<Record<keyof GenericInput, boolean>> | readonly (keyof GenericInput)[]>(input: GenericInput, omitValue: GenericOmitValue): GenericOmitValue extends Partial<Record<keyof GenericInput, boolean>> ? ComputeResultWithOmitIsObject<GenericInput, GenericOmitValue> : SimplifyTopLevel<Omit<GenericInput, Adaptor<GenericOmitValue, readonly ObjectKey[]>[number]>>;
|
|
8
8
|
export {};
|
package/dist/object/pick.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { type ObjectKey, type SimplifyTopLevel } from "../common";
|
|
|
2
2
|
import { type Adaptor } from "../common/types/adaptor";
|
|
3
3
|
import { type GetPropsWithValue } from "./types/getPropsWithValue";
|
|
4
4
|
type ComputeResultWithPickIsObject<GenericInput extends object, GenericPickValue extends Partial<Record<keyof GenericInput, boolean>>> = SimplifyTopLevel<Pick<GenericInput, Adaptor<GetPropsWithValue<GenericPickValue, true>, keyof GenericInput>> & Partial<Pick<GenericInput, Adaptor<GetPropsWithValue<GenericPickValue, boolean> | GetPropsWithValue<GenericPickValue, boolean | undefined> | GetPropsWithValue<GenericPickValue, true | undefined>, keyof GenericInput>>>>;
|
|
5
|
-
export declare function pick<GenericInput extends object,
|
|
6
|
-
export declare function pick<GenericInput extends object, GenericPickValue extends Partial<Record<keyof GenericInput, boolean>> | readonly (keyof GenericInput)[]>(input: GenericInput, pickValue: GenericPickValue): GenericPickValue extends Partial<Record<keyof GenericInput, boolean>> ? ComputeResultWithPickIsObject<GenericInput, GenericPickValue> : SimplifyTopLevel<Pick<GenericInput, Adaptor<GenericPickValue, ObjectKey[]>[number]>>;
|
|
5
|
+
export declare function pick<GenericInput extends object, const GenericPickValue extends Partial<Record<keyof GenericInput, boolean>> | readonly (keyof GenericInput)[]>(pickValue: GenericPickValue): (input: GenericInput) => GenericPickValue extends Partial<Record<keyof GenericInput, boolean>> ? ComputeResultWithPickIsObject<GenericInput, GenericPickValue> : SimplifyTopLevel<Pick<GenericInput, Adaptor<GenericPickValue, readonly ObjectKey[]>[number]>>;
|
|
6
|
+
export declare function pick<GenericInput extends object, const GenericPickValue extends Partial<Record<keyof GenericInput, boolean>> | readonly (keyof GenericInput)[]>(input: GenericInput, pickValue: GenericPickValue): GenericPickValue extends Partial<Record<keyof GenericInput, boolean>> ? ComputeResultWithPickIsObject<GenericInput, GenericPickValue> : SimplifyTopLevel<Pick<GenericInput, Adaptor<GenericPickValue, readonly ObjectKey[]>[number]>>;
|
|
7
7
|
export {};
|