Update docs
This commit is contained in:
+1
-1
@@ -32,6 +32,6 @@ emitter.on('*', (eventType, ...args) => {
|
||||
// Emit an event - triggers both listeners
|
||||
emitter.emit('message', 'Hello world');
|
||||
// Output:
|
||||
// Event: message ['Hello world']
|
||||
// Message: Hello world
|
||||
// Event: message ['Hello world']
|
||||
```
|
||||
+3
-3
@@ -40,9 +40,9 @@ cache.set('c', 3);
|
||||
|
||||
console.log(cache.get('a')); // 1
|
||||
|
||||
// Adding 'd' will evict 'b' (least recently used)
|
||||
// Adding 'd' will evict 'a' (its stale key entry is at the front of the tracking queue)
|
||||
cache.set('d', 4);
|
||||
|
||||
console.log(cache.has('b')); // false
|
||||
console.log(cache.has('a')); // true (recently accessed)
|
||||
console.log(cache.has('b')); // true
|
||||
console.log(cache.has('a')); // false
|
||||
```
|
||||
|
||||
@@ -8,6 +8,7 @@ The `TaskQueue` class provides a simple queue processing system with batched ope
|
||||
// Task queue options
|
||||
export type TaskQueueOptions<Item> = {
|
||||
batchSize: number;
|
||||
batchDelay: number;
|
||||
processItem: (item: Item) => unknown;
|
||||
};
|
||||
|
||||
@@ -17,7 +18,7 @@ export declare class TaskQueue<Item> {
|
||||
push(item: Item): void;
|
||||
remove(item: Item): void;
|
||||
subscribe(subscriber: (item: Item) => void): () => void;
|
||||
process(): Promise<void>;
|
||||
process(): void;
|
||||
stop(): void;
|
||||
start(): void;
|
||||
clear(): void;
|
||||
@@ -32,6 +33,7 @@ import { TaskQueue } from '@welshman/lib';
|
||||
// Create a task queue that processes 3 items at a time
|
||||
const queue = new TaskQueue({
|
||||
batchSize: 3,
|
||||
batchDelay: 0,
|
||||
processItem: async (message: string) => {
|
||||
console.log('Processing:', message);
|
||||
// Simulate async work
|
||||
|
||||
+15
-14
@@ -35,17 +35,17 @@ type PartialUser = MakeOptional<User, 'email' | 'age'>;
|
||||
## Basic functional programming utilities
|
||||
|
||||
```typescript
|
||||
// Null or undefined
|
||||
export type Nil = null | undefined;
|
||||
// Undefined or T
|
||||
export type Maybe<T> = T | undefined;
|
||||
|
||||
// Check whether something is null or undefined
|
||||
export declare const isNil: <T>(x: T, ...args: unknown[]) => boolean;
|
||||
// Check whether something is not undefined
|
||||
export declare const isDefined: <T>(x: T, ...args: unknown[]) => boolean;
|
||||
|
||||
// Check whether something is not null or undefined
|
||||
export declare const isNotNil: <T>(x: T, ...args: unknown[]) => x is (T & null) | (T & {}) | (T & undefined);
|
||||
// Check whether something is undefined
|
||||
export declare const isUndefined: <T>(x: T, ...args: unknown[]) => boolean;
|
||||
|
||||
// Assert that a nullable type is not null or undefined
|
||||
export declare const assertNotNil: <T>(x: T, ...args: unknown[]) => NonNullable<T>;
|
||||
// Assert that a value is not undefined
|
||||
export declare const assertDefined: <T>(x: T, ...args: unknown[]) => NonNullable<T>;
|
||||
|
||||
// Function that does nothing and returns undefined
|
||||
export declare const noop: (...args: unknown[]) => undefined;
|
||||
@@ -215,7 +215,7 @@ export declare const drop: <T>(n: number, xs: Iterable<T>) => T[];
|
||||
// Returns first n elements of array
|
||||
export declare const take: <T>(n: number, xs: Iterable<T>) => T[];
|
||||
|
||||
// Concatenates multiple arrays, filtering out null/undefined
|
||||
// Concatenates multiple arrays, skipping undefined array arguments
|
||||
export declare const concat: <T>(...xs: T[][]) => T[];
|
||||
|
||||
// Prepends element to array
|
||||
@@ -417,7 +417,7 @@ export declare const yieldThread: () => any;
|
||||
// Poll options for condition checking
|
||||
type PollOptions = {
|
||||
signal: AbortSignal;
|
||||
condition: () => boolean;
|
||||
condition: () => unknown;
|
||||
interval?: number;
|
||||
};
|
||||
|
||||
@@ -468,6 +468,7 @@ export declare const setJson: (k: string, v: any) => void;
|
||||
// Options for fetch requests
|
||||
type FetchOpts = {
|
||||
method?: string;
|
||||
signal?: AbortSignal;
|
||||
headers?: Record<string, string | boolean>;
|
||||
body?: string | FormData;
|
||||
};
|
||||
@@ -497,8 +498,8 @@ export declare const ellipsize: (s: string, l: number, suffix?: string) => strin
|
||||
// Displays a list of items with oxford commas and a chosen conjunction
|
||||
export declare const displayList: <T>(xs: T[], conj?: string, n?: number) => string;
|
||||
|
||||
// Generates a hash string from input string
|
||||
export declare const hash: (s: string) => string;
|
||||
// Generates a hash number from input string
|
||||
export declare const hash: (s: string) => number;
|
||||
```
|
||||
|
||||
## Curried utilities for working with collections
|
||||
@@ -564,8 +565,8 @@ export declare const hexToBech32: (prefix: string, hex: string) => `${Lowercase<
|
||||
// Converts bech32 string to hex format
|
||||
export declare const bech32ToHex: (b32: string) => string;
|
||||
|
||||
// Converts an array buffer to hex format
|
||||
export declare const bytesToHex: (buffer: ArrayBuffer) => string;
|
||||
// Converts an array buffer or Uint8Array to hex format
|
||||
export declare const bytesToHex: (buffer: ArrayBuffer | Uint8Array) => string;
|
||||
|
||||
// Converts a hex string to a Uint8Array buffer
|
||||
export declare const hexToBytes: (hex: string) => Uint8Array;
|
||||
|
||||
Reference in New Issue
Block a user