cafe-utility 11.0.2 → 12.0.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.
- package/index.d.ts +14 -12
- package/index.js +6 -3124
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type Indexable = number | string;
|
|
2
|
+
type CafeObject<T = unknown> = Record<string, T>;
|
|
3
3
|
declare function invertPromise<T>(promise: Promise<T>): Promise<unknown>;
|
|
4
4
|
declare function raceFulfilled<T>(promises: Promise<T>[]): Promise<unknown>;
|
|
5
5
|
declare function runInParallelBatches<T>(promises: (() => Promise<T>)[], concurrency?: number): Promise<T[]>;
|
|
@@ -62,6 +62,7 @@ declare function searchHex(string: string, length: number): string | null;
|
|
|
62
62
|
declare function randomHexString(length: number, generator?: () => number): string;
|
|
63
63
|
declare function asString(string: any): string;
|
|
64
64
|
declare function asNumber(number: any): number;
|
|
65
|
+
declare function asInteger(number: any): number;
|
|
65
66
|
declare function asBoolean(bool: any): boolean;
|
|
66
67
|
declare function asDate(date: any): Date;
|
|
67
68
|
declare function asNullableString(string: any): string | null;
|
|
@@ -165,7 +166,7 @@ interface BlockExtractionOptions {
|
|
|
165
166
|
declare function extractBlock(string: string, options: BlockExtractionOptions): string | null;
|
|
166
167
|
declare function extractAllBlocks(string: string, options: BlockExtractionOptions): string[];
|
|
167
168
|
declare function replaceBlocks(string: string, replaceFn: (match: string) => string, options: BlockExtractionOptions): string;
|
|
168
|
-
|
|
169
|
+
type StringSegment = {
|
|
169
170
|
symbol: string | null;
|
|
170
171
|
string: string;
|
|
171
172
|
};
|
|
@@ -175,7 +176,7 @@ declare function uint8ArrayToBase64(array: Uint8Array): string;
|
|
|
175
176
|
declare function hexToUint8Array(hex: string): Uint8Array;
|
|
176
177
|
declare function uint8ArrayToHex(array: Uint8Array): string;
|
|
177
178
|
declare function route(pattern: string, actual: string): Record<string, unknown> | null;
|
|
178
|
-
|
|
179
|
+
type VariantGroup = {
|
|
179
180
|
variants: string[];
|
|
180
181
|
avoid: string | null;
|
|
181
182
|
};
|
|
@@ -183,6 +184,7 @@ declare function explodeReplace(string: string, substring: string, variants: str
|
|
|
183
184
|
declare function generateVariants(string: string, groups: VariantGroup[], count: number, generator?: () => number): string[];
|
|
184
185
|
declare function hashCode(string: string): number;
|
|
185
186
|
declare function replaceWord(string: string, search: string, replace: string, whitespaceOnly?: boolean): string;
|
|
187
|
+
declare function replacePascalCaseWords(string: string, replacer: (word: string) => string): string;
|
|
186
188
|
declare function containsWord(string: string, word: string): boolean;
|
|
187
189
|
declare function containsWords(string: string, words: string[], mode: 'any' | 'all'): boolean;
|
|
188
190
|
declare function parseHtmlAttributes(string: string): Record<string, string>;
|
|
@@ -211,7 +213,7 @@ declare function getAgoStructured(dateOrTimestamp: Date | number, now?: number):
|
|
|
211
213
|
value: number;
|
|
212
214
|
unit: string;
|
|
213
215
|
};
|
|
214
|
-
|
|
216
|
+
type CountCyclesOptions = {
|
|
215
217
|
precision?: number;
|
|
216
218
|
now?: number;
|
|
217
219
|
};
|
|
@@ -253,7 +255,7 @@ declare function getPreLine(string: string): string;
|
|
|
253
255
|
declare function getCached<T>(key: string, ttlMillis: number, handler: () => Promise<T>): Promise<T>;
|
|
254
256
|
declare function joinUrl(...parts: unknown[]): string;
|
|
255
257
|
declare function replaceBetweenStrings(string: string, start: string, end: string, replacement: string, keepBoundaries?: boolean): string;
|
|
256
|
-
|
|
258
|
+
type MarkdownDescription = {
|
|
257
259
|
type: 'p' | 'h1' | 'li';
|
|
258
260
|
isCapitalized: boolean;
|
|
259
261
|
hasPunctuation: boolean;
|
|
@@ -290,7 +292,6 @@ interface NumberFormatOptions {
|
|
|
290
292
|
}
|
|
291
293
|
declare function formatNumber(number: number, options?: NumberFormatOptions): string;
|
|
292
294
|
declare function makeNumber(numberWithUnit: string): number;
|
|
293
|
-
declare function parseIntOrThrow(numberOrString: any): number;
|
|
294
295
|
declare function clamp(value: number, lower: number, upper: number): number;
|
|
295
296
|
declare function increment(value: number, change: number, maximum: number): number;
|
|
296
297
|
declare function decrement(value: number, change: number, minimum: number): number;
|
|
@@ -343,7 +344,7 @@ export declare class Maybe<T> {
|
|
|
343
344
|
bind<K>(fn: (value: T) => K): Maybe<Awaited<K>>;
|
|
344
345
|
valueOf(): Promise<T | null>;
|
|
345
346
|
}
|
|
346
|
-
|
|
347
|
+
type Playbook<T> = {
|
|
347
348
|
ttl: number;
|
|
348
349
|
ttlMax?: number;
|
|
349
350
|
data: T;
|
|
@@ -359,15 +360,15 @@ declare function requireStringArgument(args: string[], key: string, env?: Record
|
|
|
359
360
|
declare function requireNumberArgument(args: string[], key: string, env?: Record<string, string | undefined>, envKey?: string): number;
|
|
360
361
|
declare function bringToFrontInPlace<T>(array: T[], index: number): void;
|
|
361
362
|
declare function bringToFront<T>(array: T[], index: number): T[];
|
|
362
|
-
|
|
363
|
+
type Point = {
|
|
363
364
|
x: number;
|
|
364
365
|
y: number;
|
|
365
366
|
};
|
|
366
|
-
|
|
367
|
+
type Line = {
|
|
367
368
|
start: Point;
|
|
368
369
|
end: Point;
|
|
369
370
|
};
|
|
370
|
-
|
|
371
|
+
type Truthy = boolean | number;
|
|
371
372
|
declare function addPoint(a: Point, b: Point): Point;
|
|
372
373
|
declare function subtractPoint(a: Point, b: Point): Point;
|
|
373
374
|
declare function multiplyPoint(point: Point, scalar: number): Point;
|
|
@@ -450,7 +451,6 @@ export declare const Numbers: {
|
|
|
450
451
|
increment: typeof increment;
|
|
451
452
|
decrement: typeof decrement;
|
|
452
453
|
format: typeof formatNumber;
|
|
453
|
-
parseIntOrThrow: typeof parseIntOrThrow;
|
|
454
454
|
asMegabytes: typeof asMegabytes;
|
|
455
455
|
convertBytes: typeof convertBytes;
|
|
456
456
|
hexToRgb: typeof hexToRgb;
|
|
@@ -558,6 +558,7 @@ export declare const Types: {
|
|
|
558
558
|
isId: typeof isId;
|
|
559
559
|
asString: typeof asString;
|
|
560
560
|
asNumber: typeof asNumber;
|
|
561
|
+
asInteger: typeof asInteger;
|
|
561
562
|
asBoolean: typeof asBoolean;
|
|
562
563
|
asDate: typeof asDate;
|
|
563
564
|
asNullableString: typeof asNullableString;
|
|
@@ -647,6 +648,7 @@ export declare const Strings: {
|
|
|
647
648
|
generateVariants: typeof generateVariants;
|
|
648
649
|
hashCode: typeof hashCode;
|
|
649
650
|
replaceWord: typeof replaceWord;
|
|
651
|
+
replacePascalCaseWords: typeof replacePascalCaseWords;
|
|
650
652
|
};
|
|
651
653
|
export declare const Assertions: {
|
|
652
654
|
asEqual: typeof asEqual;
|