UNPKG

@pafa/shared

Version:

shared utils of paf

74 lines (65 loc) 4.88 kB
declare const uniq: (arr: Array<any>) => any[]; declare const normalizeToArray: <T>(value: T | T[]) => T[]; declare const removeItem: <T>(arr: Array<T>, item: T) => T[] | undefined; declare const toggleItem: <T>(arr: Array<T>, item: T) => T[]; declare const removeArrayBlank: <T>(arr: Array<T | null | undefined>) => T[]; declare const find: <T>(arr: Array<T>, callback: (item: T, index: number, array: Array<T>) => any, from?: "start" | "end") => [T, number] | [null, -1]; type ClassName = string | undefined | null; type Classes = (ClassName | [any, ClassName, ClassName?])[]; declare const classes: (...classes: Classes) => any[]; declare const getGlobalThis: () => typeof globalThis; declare const requestAnimationFrame: (fn: FrameRequestCallback) => number; declare const cancelAnimationFrame: (handle: number) => void; declare const raf: () => Promise<unknown>; declare const doubleRaf: () => Promise<unknown>; declare const getStyle: (element: Element) => CSSStyleDeclaration; declare const getRect: (element: Element | Window) => DOMRect; declare const inViewport: (element: HTMLElement) => boolean; declare const toDataURL: (file: File) => Promise<string>; declare const preventDefault: (event: Event) => void; declare const getScrollTop: (element: Element | Window) => number; declare const getScrollLeft: (element: Element | Window) => number; declare const debounce: (fn: any, delay?: number) => (this: unknown, ...args: any[]) => void; declare const throttle: (fn: any, delay?: number) => (() => void); declare function call<P extends any[], R>(fn?: ((...arg: P) => R) | ((...arg: P) => R)[] | null, ...args: P): R | R[] | undefined; declare function noop(): void; declare const isString: (val: unknown) => val is string; declare const isBoolean: (val: unknown) => val is boolean; declare const isNumber: (val: unknown) => val is number; declare const isNumeric: (val: unknown) => val is number | string; declare const isPlainObject: (val: unknown) => val is Record<string, any>; declare const isObject: (val: unknown) => val is Record<string, any>; declare const isFunction: (val: unknown) => val is Function; declare const isPromise: <T = any>(val: unknown) => val is Promise<T>; declare const isArray: (val: unknown) => val is Array<any>; declare const isURL: (val: string | undefined | null) => boolean; declare const isEmpty: (val: unknown) => boolean; declare const isWindow: (val: unknown) => val is Window; declare const supportTouch: () => boolean; declare const inBrowser: () => boolean; declare const inMobile: () => boolean; declare const hasOwn: <T extends object>(val: T, key: PropertyKey) => key is keyof T; declare const isNullish: (value: any) => boolean; declare const isDef: (val: unknown) => val is {}; declare const toNumber: (val: number | string | boolean | undefined | null) => number; declare const clamp: (num: number, min: number, max: number) => number; declare const clampArrayRange: (index: number, arr: Array<unknown>) => number; declare const bigCamelize: (s: string) => string; declare const camelize: (s: string) => string; declare const kebabCase: (s: string) => string; declare const slash: (path: string) => string; type BEM<S extends string | undefined, N extends string, NC extends string> = S extends undefined ? NC : S extends `$--${infer CM}` ? `${N}--${CM}` : S extends `--${infer M}` ? `${NC}--${M}` : `${NC}__${S}`; declare function createNamespaceFn<N extends string>(namespace: N): <C extends string>(name: C) => { name: string; n: <S extends string | undefined = undefined>(suffix?: S) => BEM<S, typeof namespace, `${N}-${C}`>; classes: (...classes: Classes) => any[]; }; declare function mergeWith<TObject extends Record<string, any>, TSource extends Record<string, any>>(object: TObject, source: TSource, customizer: (objValue: any, srcValue: any, key: string | number | symbol, object?: TObject, source?: TSource) => any | void): TObject & TSource; type Interceptor = (...args: any[]) => Promise<boolean> | boolean | undefined | void; declare function callInterceptor(interceptor: Interceptor | undefined, { args, done, canceled, error, }: { args?: unknown[]; done: () => void; canceled?: () => void; error?: () => void; }): void; export { type BEM, type ClassName, type Classes, type Interceptor, bigCamelize, call, callInterceptor, camelize, cancelAnimationFrame, clamp, clampArrayRange, classes, createNamespaceFn, debounce, doubleRaf, find, getGlobalThis, getRect, getScrollLeft, getScrollTop, getStyle, hasOwn, inBrowser, inMobile, inViewport, isArray, isBoolean, isDef, isEmpty, isFunction, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPromise, isString, isURL, isWindow, kebabCase, mergeWith, noop, normalizeToArray, preventDefault, raf, removeArrayBlank, removeItem, requestAnimationFrame, slash, supportTouch, throttle, toDataURL, toNumber, toggleItem, uniq };