cafe-utility 21.0.0 → 21.2.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.
Files changed (3) hide show
  1. package/index.d.ts +24 -1
  2. package/index.js +1228 -1176
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -8,6 +8,7 @@ declare function shuffle<T>(array: T[], generator?: () => number): T[];
8
8
  declare function onlyOrThrow<T>(array: T[]): T;
9
9
  declare function onlyOrNull<T>(array: T[]): T | null;
10
10
  declare function firstOrNull<T>(array: T[]): T | null;
11
+ declare function firstOrThrow<T>(array: T[]): T;
11
12
  declare function initializeArray<T>(count: number, initializer: (index: number) => T): T[];
12
13
  declare function rotate2DArray<T>(array: T[][]): T[][];
13
14
  declare function initialize2DArray<T>(width: number, height: number, initialValue: T): T[][];
@@ -34,6 +35,8 @@ declare function pickGuaranteed<T>(array: T[], include: T | null, exclude: T | n
34
35
  indexOfGuaranteed: number;
35
36
  };
36
37
  declare function last<T>(array: T[]): T;
38
+ declare function pipe<T>(value: any, functions: ((value: any) => any)[], assertionFn: (value: any) => T): T;
39
+ declare function makePipe<T>(functions: ((value: any) => any)[], assertionFn: (value: any) => T): (value: any) => T;
37
40
  declare function pickWeighted<T>(array: T[], weights: number[], randomNumber?: number): T;
38
41
  declare function sortWeighted<T>(array: T[], weights: number[], generator?: () => number): T[];
39
42
  declare function getDeep(some: any, path: string): unknown;
@@ -84,6 +87,7 @@ declare function asId(value: any): number;
84
87
  declare function asTime(value: any): string;
85
88
  declare function asArray(value: any): unknown[];
86
89
  declare function asObject(value: any): Record<string, unknown>;
90
+ declare function asNullableObject(value: any): Record<string, unknown> | null;
87
91
  declare function asNumericDictionary(value: any): Record<string, number>;
88
92
  declare function isUrl(value: any): boolean;
89
93
  declare function asUrl(value: any): string;
@@ -420,6 +424,14 @@ declare function createHierarchy<T>(items: T[], idKey: keyof T, parentKey: keyof
420
424
  declare function log2Reduce<T>(array: T[], reducer: (a: T, b: T) => T): T;
421
425
  declare function partition(bytes: Uint8Array, size: number): Uint8Array[];
422
426
  declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
427
+ declare function isPng(bytes: Uint8Array): boolean;
428
+ declare function isJpg(bytes: Uint8Array): boolean;
429
+ declare function isWebp(bytes: Uint8Array): boolean;
430
+ declare function isImage(bytes: Uint8Array): boolean;
431
+ declare function numberToUint64LE(number: number): Uint8Array;
432
+ declare function uint64LEToNumber(bytes: Uint8Array): number;
433
+ declare function numberToUint64BE(number: number): Uint8Array;
434
+ declare function uint64BEToNumber(bytes: Uint8Array): number;
423
435
  interface Uint8ArrayIO {
424
436
  max: () => number;
425
437
  }
@@ -442,7 +454,6 @@ declare class Chunk {
442
454
  writer: Uint8ArrayWriter;
443
455
  hashFn: (a: Uint8Array, b: Uint8Array) => Uint8Array;
444
456
  constructor(capacity: number, hashFn: (a: Uint8Array, b: Uint8Array) => Uint8Array, span?: number);
445
- buildSpan(): Uint8Array;
446
457
  build(): Uint8Array;
447
458
  hash(): Uint8Array;
448
459
  }
@@ -496,6 +507,10 @@ export declare const Binary: {
496
507
  merkleStart: typeof merkleStart;
497
508
  merkleAppend: typeof merkleAppend;
498
509
  merkleFinalize: typeof merkleFinalize;
510
+ numberToUint64LE: typeof numberToUint64LE;
511
+ uint64LEToNumber: typeof uint64LEToNumber;
512
+ numberToUint64BE: typeof numberToUint64BE;
513
+ uint64BEToNumber: typeof uint64BEToNumber;
499
514
  };
500
515
  export declare const Random: {
501
516
  intBetween: typeof intBetween;
@@ -514,6 +529,7 @@ export declare const Arrays: {
514
529
  indexCollection: typeof indexArrayToCollection;
515
530
  onlyOrThrow: typeof onlyOrThrow;
516
531
  onlyOrNull: typeof onlyOrNull;
532
+ firstOrThrow: typeof firstOrThrow;
517
533
  firstOrNull: typeof firstOrNull;
518
534
  shuffle: typeof shuffle;
519
535
  initialize: typeof initializeArray;
@@ -529,6 +545,8 @@ export declare const Arrays: {
529
545
  pickRandomIndices: typeof pickRandomIndices;
530
546
  pickGuaranteed: typeof pickGuaranteed;
531
547
  last: typeof last;
548
+ pipe: typeof pipe;
549
+ makePipe: typeof makePipe;
532
550
  sortWeighted: typeof sortWeighted;
533
551
  pushAll: typeof pushAll;
534
552
  unshiftAll: typeof unshiftAll;
@@ -699,11 +717,16 @@ export declare const Types: {
699
717
  asTime: typeof asTime;
700
718
  asArray: typeof asArray;
701
719
  asObject: typeof asObject;
720
+ asNullableObject: typeof asNullableObject;
702
721
  asNumericDictionary: typeof asNumericDictionary;
703
722
  asUrl: typeof asUrl;
704
723
  asNullable: typeof asNullable;
705
724
  enforceObjectShape: typeof enforceObjectShape;
706
725
  enforceArrayShape: typeof enforceArrayShape;
726
+ isPng: typeof isPng;
727
+ isJpg: typeof isJpg;
728
+ isWebp: typeof isWebp;
729
+ isImage: typeof isImage;
707
730
  };
708
731
  export declare const Strings: {
709
732
  tokenizeByCount: typeof tokenizeByCount;