@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.
@@ -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 AnyValue } from "../common";
2
- import { type GeneratorLoopParams } from "./loop";
3
- interface LoopOutputExistResult<GenericOutput extends any> {
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>;
@@ -9,7 +9,7 @@ function asyncMap(...args) {
9
9
  let index = 0;
10
10
  return (async function* () {
11
11
  for await (const element of iterator) {
12
- yield theFunction(element, { index });
12
+ yield await theFunction(element, { index });
13
13
  index++;
14
14
  }
15
15
  })();
@@ -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) => Promise<GenericOutput>): (iterator: AsyncIterable<GenericInput> | Iterable<GenericInput>) => AsyncGenerator<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) => Promise<GenericOutput>): AsyncGenerator<GenericOutput, unknown, unknown>;
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 {};
@@ -7,7 +7,7 @@ function asyncMap(...args) {
7
7
  let index = 0;
8
8
  return (async function* () {
9
9
  for await (const element of iterator) {
10
- yield theFunction(element, { index });
10
+ yield await theFunction(element, { index });
11
11
  index++;
12
12
  }
13
13
  })();
@@ -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;
@@ -8,3 +8,4 @@ export * from "./asyncReduce";
8
8
  export * from "./loop";
9
9
  export * from "./asyncLoop";
10
10
  export * from "./chunk";
11
+ export * from "./asyncChunk";
@@ -8,3 +8,4 @@ export { asyncReduce } from './asyncReduce.mjs';
8
8
  export { loop } from './loop.mjs';
9
9
  export { asyncLoop } from './asyncLoop.mjs';
10
10
  export { chunk } from './chunk.mjs';
11
+ export { asyncChunk } from './asyncChunk.mjs';
@@ -1,9 +1,9 @@
1
1
  import { type AnyValue } from "../common";
2
- interface LoopOutputExistResult<GenericOutput extends any> {
3
- "-exitData": GenericOutput | undefined;
2
+ export interface LoopOutputExistResult<GenericOutput extends unknown = unknown> {
3
+ "-exitData": GenericOutput;
4
4
  }
5
- interface LoopOutputNextResult<GenericOutput extends any> {
6
- "-nextData": GenericOutput | undefined;
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 {};
@@ -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, GenericValue extends boolean, GenericOmitValue extends Partial<Record<keyof GenericInput, GenericValue>> | readonly (keyof GenericInput)[]>(omitValue: GenericOmitValue): (input: GenericInput) => GenericOmitValue extends Partial<Record<keyof GenericInput, boolean>> ? ComputeResultWithOmitIsObject<GenericInput, GenericOmitValue> : SimplifyTopLevel<Omit<GenericInput, Adaptor<GenericOmitValue, ObjectKey[]>[number]>>;
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 {};
@@ -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, GenericValue extends boolean, GenericPickValue extends Partial<Record<keyof GenericInput, GenericValue>> | readonly (keyof GenericInput)[]>(pickValue: GenericPickValue): (input: GenericInput) => GenericPickValue extends Partial<Record<keyof GenericInput, boolean>> ? ComputeResultWithPickIsObject<GenericInput, GenericPickValue> : SimplifyTopLevel<Pick<GenericInput, Adaptor<GenericPickValue, ObjectKey[]>[number]>>;
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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/utils",
3
- "version": "1.3.20",
3
+ "version": "1.3.21",
4
4
  "author": "mathcovax",
5
5
  "license": "MIT",
6
6
  "type": "module",