@polyipseity/obsidian-plugin-library
Version:
Library for Obsidian plugins.
102 lines • 8.15 kB
TypeScript
import { type AsyncFunctionConstructor, type Base64String, type CodePoint, type ReadonlyTuple } from "./types.js";
import type { AsyncOrSync, DeepReadonly, DeepWritable, Newable } from "ts-essentials";
import { type PrimitiveTypeE, type TypeofMapE } from "./typeof.js";
import { type Options } from "browser-util-inspect";
import AsyncLock from "async-lock";
export type KeyModifier = "Alt" | "Ctrl" | "Meta" | "Shift";
export declare class EventEmitterLite<A extends readonly unknown[]> {
#private;
protected static readonly emitLock = "emit";
protected readonly lock: AsyncLock;
emit(...args: A): Promise<void>;
listen(listener: (...args: A) => unknown): () => void;
}
export type PromisePromise<T> = Promise<{
readonly promise: Promise<T>;
readonly resolve: (value: AsyncOrSync<T>) => void;
readonly reject: (reason?: unknown) => void;
}>;
export declare class Functions<Async extends boolean = false, Args extends readonly unknown[] = []> extends Array<Async extends true ? (...args: Args) => unknown : Async extends false ? (...args: Args) => void : never> {
protected readonly options: {
readonly async: Async;
readonly settled?: boolean;
};
constructor(options: {
readonly async: Async;
readonly settled?: boolean;
}, ...args: readonly (Async extends true ? (...args: Args) => unknown : Async extends false ? (...args: Args) => void : never)[]);
transform(func: (self0: this[number][]) => readonly this[number][]): Functions<Async, Args>;
call(...args: Args): Async extends true ? Promise<void> : Async extends false ? void : never;
call0(thisArg: unknown, ...args: Args): Async extends true ? Promise<void> : Async extends false ? void : never;
}
export declare function acquireConditionally<T>(lock: AsyncLock, key: string[] | string, condition: boolean, fn: () => PromiseLike<T> | T): Promise<T>;
export declare function alternativeRegExp(strs: readonly string[]): RegExp;
export declare function anyToError(obj: unknown): Error;
export declare function aroundIdentityFactory<T extends (this: unknown, ...args: readonly unknown[]) => unknown>(): (proto: T) => (this: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T>;
export declare function assignExact<K extends keyof any, T extends Partial<Record<K, unknown>>>(self0: T, key: K & keyof T, value?: T[K]): typeof value;
export declare function asyncDebounce<A extends readonly unknown[], R>(func: (resolve: (value: AsyncOrSync<R>) => void, reject: (reason?: unknown) => void, ...args: A) => unknown): (...args: A) => Promise<R>;
export declare function asyncFunction(self0: typeof globalThis): AsyncFunctionConstructor;
export declare function base64ToBytes(base64: Base64String): Uint8Array;
export declare function base64ToString(base64: Base64String): string;
export declare function basename(path: string, ext?: string): string;
export declare function bigIntReplacer(): (key: string, value: unknown) => unknown;
export declare function bracket<T extends object, K extends keyof any>(self0: T, key: K): {
readonly valid: false;
readonly value?: never;
} | {
readonly valid: true;
readonly value: T[K & keyof T];
};
export declare function bytesToBase64(bytes: Uint8Array): Base64String;
export declare function capitalize(str: string, locales?: string[] | string): string;
export declare function cartesianProduct<T extends readonly (readonly unknown[])[]>(...arrays: T): readonly ({ readonly [I in keyof T]: T[I][number]; } & {
readonly length: T["length"];
})[];
export declare function clear(self0: unknown[]): void;
export declare function clearProperties(self0: object): void;
export declare function cloneAsFrozen<T>(obj: T, cloner?: <V>(value: V) => V): DeepReadonly<T>;
export declare function cloneAsWritable<T>(obj: T, cloner?: <V>(value: V) => V): DeepWritable<T>;
export declare function consumeEvent(event: Event): void;
export declare function copyOnWrite<T extends object>(obj: DeepReadonly<T>, mutator: (obj: DeepWritable<T>) => void): DeepReadonly<T>;
export declare function copyOnWriteAsync<T extends object>(obj: DeepReadonly<T>, mutator: (obj: DeepWritable<T>) => unknown): Promise<DeepReadonly<T>>;
export declare function createChildElement<K extends keyof HTMLElementTagNameMap>(element: ParentNode & {
readonly ownerDocument: Document;
}, type: K, callback?: (_element: HTMLElementTagNameMap[K]) => void, options?: ElementCreationOptions): HTMLElementTagNameMap[K];
export declare function createDocumentFragment(self0: Document, callback: (fragment: DocumentFragment) => void): DocumentFragment;
export declare function deepFreeze<const T>(value: T): DeepReadonly<T>;
export declare function escapeJavaScriptString(value: string): string;
export declare function escapeQuerySelectorAttribute(value: string): string;
export declare function extname(path: string): string;
export declare function getKeyModifiers(event: KeyboardEvent): readonly KeyModifier[];
export declare function typedIn<T extends object, K extends keyof any>(self0: T, key: K): (() => T[K & keyof T]) | null;
export declare function typedOwnKeys<T extends object>(self0: T): (keyof T & (string | symbol))[];
export declare function typedKeys<T extends readonly (keyof any)[]>(): <O extends (keyof O extends T[number] ? Readonly<Record<T[number], unknown>> : never)>(obj: O) => Readonly<T>;
export declare function inSet<const T extends ReadonlyTuple>(set: T, obj: unknown): obj is T[number];
export declare function insertAt<T>(self0: T[], index: number, ...items: readonly T[]): void;
export declare function instanceOf<T extends Node | UIEvent>(self0: unknown, type: Newable<T>): self0 is T;
export declare function isHomogenousArray<T extends PrimitiveTypeE>(types: readonly T[], value: unknown): value is TypeofMapE[T][];
export declare function isNonNil<T>(value: (T & (null | undefined)) extends never ? never : T): value is (T & (null | undefined)) extends never ? never : NonNullable<T>;
export declare function lazyInit<T>(initializer: () => T): () => T;
export declare function lazyProxy<T extends object>(initializer: () => T): T;
export declare function logFormat(options: Options, ...args: readonly unknown[]): string;
export declare function mapFirstCodePoint(str: string, map: (value: string) => string, mapRest?: (value: string) => string): string;
export declare function multireplace(self0: string, replacements: Map<string, string>): string;
export declare function onResize(element: Element, callback: (entry: ResizeObserverEntry) => void): ResizeObserver;
export declare function onVisible(element: Element, callback: (entry: IntersectionObserverEntry) => void, transient?: boolean): IntersectionObserver;
export declare function openExternal(self0: Window, url?: URL | string): Window | null;
export declare function promisePromise<T = void>(): PromisePromise<T>;
export declare function randomNotIn(self0: readonly string[], generator?: () => string): string;
export declare function rangeCodePoint(start: CodePoint, end?: CodePoint, step?: number): readonly string[];
export declare function remove<T>(self0: T[], item: T): T | undefined;
export declare function removeAt<T>(self0: T[], index: number): T | undefined;
export declare function replaceAllRegex(string: string): RegExp;
export declare function splitLines(str: string, delimiter?: RegExp): readonly string[];
export declare function startCase(str: string, locales?: string[] | string): string;
export declare function stringToBase64(string: string): Base64String;
export declare function toJSONOrString(value: unknown, replacer?: (this: unknown, key: string, value: unknown) => unknown, space?: string | number): string;
export declare function activeSelf(reference?: Element | UIEvent | null): Window & typeof globalThis;
export declare function sleep2(self0: WindowOrWorkerGlobalScope, timeInSeconds: number): Promise<void>;
export declare function swap(self0: unknown[], left: number, right: number): void;
export declare function uncapitalize(str: string, locales?: string[] | string): string;
export declare function unexpected(): never;
//# sourceMappingURL=util.d.ts.map