Options
All
  • Public
  • Public/Protected
  • All
Menu

@planjs/utils

Index

Namespaces

Object Classes

Other Classes

Interfaces

Type aliases

Other Variables

RegExp Variables

Array Functions

Bom Functions

Date Functions

Dom Functions

Dom TODO support hex8 Functions

Function Functions

Is Functions

Number Functions

Object Functions

Other Functions

Promise Functions

Type aliases

AnyFn

AnyFn: (...args: any[]) => any

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

Many

Many<T>: T | ReadonlyArray<T>

Type parameters

  • T

MemoizeReturnType

MemoizeReturnType<T>: { clear: any; reset: any } & T

Type parameters

  • T: AnyPromiseFN

PropertyName

PropertyName: string | number | symbol

PropertyPath

PropertyPath: Many<PropertyName>

ThenReturn

ThenReturn<T>: T extends Promise<infer U> ? U : T extends (...args: any[]) => Promise<infer V> ? V : T

Type parameters

  • T

UploadRequestMethod

UploadRequestMethod: "POST" | "PUT" | "PATCH" | "post" | "put" | "patch"

Values

Values<T>: T[keyof T]

Type parameters

  • T: object

Other Variables

Const KeyCode

KeyCode: { A: number; ALT: number; APOSTROPHE: number; B: number; BACKSLASH: number; BACKSPACE: number; C: number; CAPS_LOCK: number; CLOSE_SQUARE_BRACKET: number; COMMA: number; CONTEXT_MENU: number; CTRL: number; D: number; DASH: number; DELETE: number; DOWN: number; E: number; EIGHT: number; END: number; ENTER: number; EQUALS: number; ESC: number; F: number; F1: number; F10: number; F11: number; F12: number; F2: number; F3: number; F4: number; F5: number; F6: number; F7: number; F8: number; F9: number; FIVE: number; FOUR: number; G: number; H: number; HOME: number; I: number; INSERT: number; J: number; K: number; L: number; LEFT: number; M: number; MAC_ENTER: number; MAC_FF_META: number; META: number; N: number; NINE: number; NUMLOCK: number; NUM_CENTER: number; NUM_DIVISION: number; NUM_EIGHT: number; NUM_FIVE: number; NUM_FOUR: number; NUM_MINUS: number; NUM_MULTIPLY: number; NUM_NINE: number; NUM_ONE: number; NUM_PERIOD: number; NUM_PLUS: number; NUM_SEVEN: number; NUM_SIX: number; NUM_THREE: number; NUM_TWO: number; NUM_ZERO: number; O: number; ONE: number; OPEN_SQUARE_BRACKET: number; P: number; PAGE_DOWN: number; PAGE_UP: number; PAUSE: number; PERIOD: number; PRINT_SCREEN: number; Q: number; QUESTION_MARK: number; R: number; RIGHT: number; S: number; SEMICOLON: number; SEVEN: number; SHIFT: number; SINGLE_QUOTE: number; SIX: number; SLASH: number; SPACE: number; T: number; TAB: number; THREE: number; TWO: number; U: number; UP: number; V: number; W: number; WIN_IME: number; WIN_KEY: number; WIN_KEY_RIGHT: number; X: number; Y: number; Z: number; ZERO: number; isCharacterKey: (keyCode: number) => boolean; isTextModifyingKeyEvent: (e: KeyboardEvent) => boolean } = ...

Type declaration

  • A: number
  • ALT: number
  • APOSTROPHE: number
  • B: number
  • BACKSLASH: number
  • BACKSPACE: number
  • C: number
  • CAPS_LOCK: number
  • CLOSE_SQUARE_BRACKET: number
  • COMMA: number
  • CONTEXT_MENU: number
  • CTRL: number
  • D: number
  • DASH: number
  • DELETE: number
  • DOWN: number
  • E: number
  • EIGHT: number
  • END: number
  • ENTER: number
  • EQUALS: number
  • ESC: number
  • F: number
  • F1: number
  • F10: number
  • F11: number
  • F12: number
  • F2: number
  • F3: number
  • F4: number
  • F5: number
  • F6: number
  • F7: number
  • F8: number
  • F9: number
  • FIVE: number
  • FOUR: number
  • G: number
  • H: number
  • HOME: number
  • I: number
  • INSERT: number
  • J: number
  • K: number
  • L: number
  • LEFT: number
  • M: number
  • MAC_ENTER: number
  • MAC_FF_META: number
  • META: number
  • N: number
  • NINE: number
  • NUMLOCK: number
  • NUM_CENTER: number
  • NUM_DIVISION: number
  • NUM_EIGHT: number
  • NUM_FIVE: number
  • NUM_FOUR: number
  • NUM_MINUS: number
  • NUM_MULTIPLY: number
  • NUM_NINE: number
  • NUM_ONE: number
  • NUM_PERIOD: number
  • NUM_PLUS: number
  • NUM_SEVEN: number
  • NUM_SIX: number
  • NUM_THREE: number
  • NUM_TWO: number
  • NUM_ZERO: number
  • O: number
  • ONE: number
  • OPEN_SQUARE_BRACKET: number
  • P: number
  • PAGE_DOWN: number
  • PAGE_UP: number
  • PAUSE: number
  • PERIOD: number
  • PRINT_SCREEN: number
  • Q: number
  • QUESTION_MARK: number
  • R: number
  • RIGHT: number
  • S: number
  • SEMICOLON: number
  • SEVEN: number
  • SHIFT: number
  • SINGLE_QUOTE: number
  • SIX: number
  • SLASH: number
  • SPACE: number
  • T: number
  • TAB: number
  • THREE: number
  • TWO: number
  • U: number
  • UP: number
  • V: number
  • W: number
  • WIN_IME: number
  • WIN_KEY: number
  • WIN_KEY_RIGHT: number
  • X: number
  • Y: number
  • Z: number
  • ZERO: number
  • isCharacterKey: (keyCode: number) => boolean
      • (keyCode: number): boolean
      • whether character is entered.

        Parameters

        • keyCode: number

        Returns boolean

  • isTextModifyingKeyEvent: (e: KeyboardEvent) => boolean
      • (e: KeyboardEvent): boolean
      • whether text and modified key is entered at the same time.

        Parameters

        • e: KeyboardEvent

        Returns boolean

Const MAX_ARRAY_INDEX

MAX_ARRAY_INDEX: number = ...

数组最长长度

Const MAX_SAFE_INTEGER

MAX_SAFE_INTEGER: number = ...

Const SINGLETON_KEY

SINGLETON_KEY: typeof SINGLETON_KEY = ...

Const eventCenter

eventCenter: Event = ...

Const global

global: any = ...

全局对象

Const pref

pref: Pref = ...

RegExp Variables

Const REG_BANK_CARD_NUM

REG_BANK_CARD_NUM: RegExp = ...

银行卡号 10到30位, 覆盖对公/私账户, 参考 https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=22_1

Const REG_BASE64

REG_BASE64: RegExp = ...

判断是否是base64

Const REG_CN

REG_CN: RegExp = ...

匹配中文

Const REG_CN_NAME

REG_CN_NAME: RegExp = ...

中文名

Const REG_COLOR

REG_COLOR: RegExp = ...

颜色16进制颜色,rgb或rgba

Const REG_DATA_URL

REG_DATA_URL: RegExp = ...

判断是否data url

Const REG_DECIMAL

REG_DECIMAL: RegExp = ...

小数

Const REG_EMAIL

REG_EMAIL: RegExp = ...

email

Const REG_EN

REG_EN: RegExp = ...

匹配英文

Const REG_ENGLISH

REG_ENGLISH: RegExp = ...

英文字母

Const REG_EN_NAME

REG_EN_NAME: RegExp = ...

英文名

Const REG_HEX_COLOR

REG_HEX_COLOR: RegExp = ...

16进制颜色

Const REG_ID_CARD

REG_ID_CARD: RegExp = ...

身份证号, 支持1/2代(15位/18位数字)

Const REG_IMEI

REG_IMEI: RegExp = ...

手机机身码(IMEI)

Const REG_IPV4

REG_IPV4: RegExp = ...

ip-v4

Const REG_IPV6

REG_IPV6: RegExp = ...

ip-v6

Const REG_LINUX_FILE_PATH

REG_LINUX_FILE_PATH: RegExp = ...

linux文件路径

Const REG_LINUX_FOLDER_PATH

REG_LINUX_FOLDER_PATH: RegExp = ...

linux文件夹路径

Const REG_MD532

REG_MD532: RegExp = ...

md5 32

Const REG_NO_CN

REG_NO_CN: RegExp = ...

不包含中文

Const REG_NUMBER

REG_NUMBER: RegExp = ...

数字

Const REG_PHONE_LOOSE

REG_PHONE_LOOSE: RegExp = ...

手机号(mobile phone)中国(宽松), 只要是13,14,15,16,17,18,19开头即可

Const REG_POSTAL_CODEi

REG_POSTAL_CODEi: RegExp = ...

邮政编码(中国)

Const REG_SUBNET_MASK

REG_SUBNET_MASK: RegExp = ...

子网掩码

Const REG_TEL_PHONE

REG_TEL_PHONE: RegExp = ...

座机(tel phone)

Const REG_UNIFIED_SOCIAL_CREDIT_CODE

REG_UNIFIED_SOCIAL_CREDIT_CODE: RegExp = ...

统一社会信用代码

Const REG_URI

REG_URI: RegExp = ...

网址校验,必须带有协议,或者相对协议

Const REG_URI_LOSE

REG_URI_LOSE: RegExp = ...

网址(url,支持端口和"?+参数"和"#+参数)

note

没有协议也会校验通过

Const REG_URI_WITH_PORT

REG_URI_WITH_PORT: RegExp = ...

必须带端口号的网址(或ip)

Const REG_VERSION

REG_VERSION: RegExp = ...

version x.y.z

Const REG_WINDOWS_FILE_PATH

REG_WINDOWS_FILE_PATH: RegExp = ...

window下"文件"路径

Const REG_WINDOWS_FOLDER_PATH

REG_WINDOWS_FOLDER_PATH: RegExp = ...

window"文件夹"路径

Array Functions

arrayAverage

  • arrayAverage(array: number[]): number

arrayEachRight

  • arrayEachRight<T>(array: T[], iteratee: (item: T, index: number, array: T[]) => false | void): T[]
  • 从右边foreach数组

    Type parameters

    • T

    Parameters

    • array: T[]
    • iteratee: (item: T, index: number, array: T[]) => false | void
        • (item: T, index: number, array: T[]): false | void
        • Parameters

          • item: T
          • index: number
          • array: T[]

          Returns false | void

    Returns T[]

arrayMove

  • arrayMove<T>(array: T[], from: number, to: number): T[]
  • 移动数组中元素位置

    Type parameters

    • T

    Parameters

    • array: T[]
    • from: number

      原始位置,如果超过数组长度,则不出处理

    • to: number

      目标位置

    Returns T[]

    array 返回原数组

arrayRandom

  • arrayRandom<T>(array: T[]): T

arraySplice

  • arraySplice<T>(array: T[], indexes: number[]): T[]
  • 一次删除数组中多个元素

    Type parameters

    • T

    Parameters

    • array: T[]
    • indexes: number[]

      下标数组

    Returns T[]

    array 被删除的元素

arraySum

  • arraySum(array: number[]): number

arrayToMap

arrayToTree

  • arrayToTree<T, K, Opts, Node>(array: T[], option?: Opts): Record<string, Node>
  • 数组通过关联主键,返回树

    example
    const arr = [
      { id: 1, parentId: 0 },
      { id: 2, parentId: 1 },
      { id: 3, parentId: 2 },
      { id: 4, parentId: 3 }
    ]
    const tree = arrayToTree(arr)[0];
    // out
    {
      children: [
        {
          id: 1,
          parentId: 0,
          children: [
            {
              id: 2,
              parentId: 1,
              children: [
                {
                  id: 3,
                  parentId: 2,
                  children: [
                    {
                      id: 4,
                      parentId: 3
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
    }
    

    Type parameters

    Parameters

    • array: T[]
    • Optional option: Opts

    Returns Record<string, Node>

    tree { { [id]: TreeNode } } 可以根据root节点id获取树

arrayify

  • arrayify(val: any): unknown[]

chunk

  • chunk<T>(array: T[], size?: number): T[][]
  • 将数组分成指定大小的较小数组

    Type parameters

    • T

    Parameters

    • array: T[]
    • size: number = 1

      default 1

    Returns T[][]

mapPick

  • mapPick<T, K, Value, Item>(array: readonly T[], keyPaths?: Record<K, (PropertyPath | keyof T)[]>, keyPredicates?: Record<K, (key: K, value: T, index: number, array: readonly T[]) => Value>): Item[]
  • 从数组对象中获取指定的值,返回新的数组

    example
    const list = [{ id: 1, name: 'bob' }, { id: 2, name: 'sam' }]
    mapPick(list, { label: ['name'], value: ['id'] })
    // [{ label: 'bob', value: 1 }, { label: 'sam', value: 2 }]
    

    Type parameters

    • T: Dictionary<any, T>

    • K: string

    • Value = T[keyof T]

    • Item = Record<K, Value>

    Parameters

    • array: readonly T[]
    • Optional keyPaths: Record<K, (PropertyPath | keyof T)[]>

      key 返回对象key, path 对象中值的key

    • Optional keyPredicates: Record<K, (key: K, value: T, index: number, array: readonly T[]) => Value>

      key 返回对象key, predicate 返回需要的值

    Returns Item[]

range

  • range(from: number, to: number, step?: number): number[]
  • 获取范围内的数组

    Parameters

    • from: number
    • to: number
    • step: number = 1

    Returns number[]

shuffle

  • shuffle<T>(array: T[]): T[]
  • 随机排列数组

    Type parameters

    • T = any

    Parameters

    • array: T[]

    Returns T[]

    array 返回原数组

Bom Functions

XHRUploadFile

Const cancelAnimationFrame

  • cancelAnimationFrame(handle: number): void

Const delCookie

  • delCookie(name: string): void
  • 删除cookie

    Parameters

    • name: string

      删除的cookie名称

    Returns void

downloadCanvasImage

  • downloadCanvasImage(path: string, fileName: string, opt?: Parameters<typeof canvasImageToBlob>[1]): Promise<void>
  • 下载图片,如果是跨域图片需要用这个方法,同域等也可以直接用 downloadFile

    note

    浏览器不要开拦截弹窗工具。。。

    Parameters

    • path: string

      远程文件地址

    • fileName: string

      下载文件名

    • Optional opt: Parameters<typeof canvasImageToBlob>[1]

    Returns Promise<void>

downloadFile

  • downloadFile(path: string | Blob, fileName: string): void

executeCopy

  • executeCopy(textValue: string): void

fetch

  • fetch(url: string, options?: Options): Promise<Response>
  • 具有兼容性的fetch

    Parameters

    • url: string
    • options: Options = {}

    Returns Promise<Response>

Const getCookie

  • getCookie(name: string, type?: number | boolean): null | string
  • 读取cookies

    Parameters

    • name: string

      要获取的cookie名称

    • type: number | boolean = 0

      是否直接获取对应的值,若存入真值,则直接返回,否则进行解码

    Returns null | string

openWindow

  • openWindow(url: string): void
  • 异步请求,或者promise内window open被拦截

    Parameters

    • url: string

    Returns void

Const requestAnimationFrame

  • requestAnimationFrame(callback: FrameRequestCallback): number

Const setCookie

  • setCookie(name: string, value: string | number, expires: DateInput): void
  • 写cookies

    throws

    Invalid Date

    Parameters

    • name: string

      写cookie的key

    • value: string | number

      写cookie的值

    • expires: DateInput

    Returns void

windowSmoothScrolling

  • windowSmoothScrolling(to: number, duration: number): void

Date Functions

parsePassTime

  • parsePassTime(startTime: number): string

parseTimeRange

  • parseTimeRange(runningTime: number): string

parseTimeWX

  • parseTimeWX(time: DateInput): any
  • 微信语义化形式展示 1、< 60s, 显示为“刚刚” 2、>= 1min && < 60 min, 显示与当前时间差“XX分钟前” 3、>= 60min && < 1day, 显示与当前时间差“今天 XX:XX” 4、>= 1day && < 1year, 显示日期“XX月XX日 XX:XX” 5、>= 1year, 显示具体日期 XXXX年XX月XX日 XX:XX

    Parameters

    • time: DateInput

    Returns any

timeLeft

  • timeLeft(startTime: DateInput, endTime: DateInput): undefined | { d: number; h: number; m: number; s: number }
  • 计算剩余时间

    note

    startTime - endTime 的剩余时间,startTime大于endTime时,均返回0

    Parameters

    • startTime: DateInput
    • endTime: DateInput

    Returns undefined | { d: number; h: number; m: number; s: number }

toDate

  • toDate(input: DateInput): Date
  • 时间戳,字符串,转换成 Date

    throws

    Invalid Date

    Parameters

    • input: DateInput

    Returns Date

Dom Functions

loadImageElement

  • loadImageElement(src: string, crossOrigin?: string | null): Promise<HTMLImageElement>
  • 创建一个img元素,获取img元素

    Parameters

    • src: string
    • crossOrigin: string | null = 'anonymous'

    Returns Promise<HTMLImageElement>

Dom TODO support hex8 Functions

hexColorToRgba

  • hexColorToRgba(hex: string, opacity?: number | string): string

Function Functions

after

  • after<FN>(n: number, func: FN): FN

before

  • before<FN>(n: number, func: FN): FN
  • 只执行最开始的几次,超过次数之后返回最后一次执行的结果

    Type parameters

    Parameters

    • n: number
    • func: FN

    Returns FN

clearPrefSetInterval

  • clearPrefSetInterval(handle: number): void

clearPrefTimeout

  • clearPrefTimeout(handle: number): void

curry

  • curry<T1, R>(func: (t1: T1) => R, depth?: number): Curry1<T1, R>
  • curry<T1, T2, R>(func: (t1: T1, t2: T2) => R, depth?: number): Curry2<T1, T2, R>
  • curry<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, depth?: number): Curry3<T1, T2, T3, R>
  • curry<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, depth?: number): Curry4<T1, T2, T3, T4, R>
  • curry<T1, T2, T3, T4, T5, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R, depth?: number): Curry5<T1, T2, T3, T4, T5, R>
  • curry<T1, T2, T3, T4, T5, T6, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6) => R, depth?: number): Curry6<T1, T2, T3, T4, T5, T6, R>
  • 柯里化

    Type parameters

    • T1

    • R

    Parameters

    • func: (t1: T1) => R
        • (t1: T1): R
        • Parameters

          • t1: T1

          Returns R

    • Optional depth: number

    Returns Curry1<T1, R>

  • Type parameters

    • T1

    • T2

    • R

    Parameters

    • func: (t1: T1, t2: T2) => R
        • (t1: T1, t2: T2): R
        • Parameters

          • t1: T1
          • t2: T2

          Returns R

    • Optional depth: number

    Returns Curry2<T1, T2, R>

  • Type parameters

    • T1

    • T2

    • T3

    • R

    Parameters

    • func: (t1: T1, t2: T2, t3: T3) => R
        • (t1: T1, t2: T2, t3: T3): R
        • Parameters

          • t1: T1
          • t2: T2
          • t3: T3

          Returns R

    • Optional depth: number

    Returns Curry3<T1, T2, T3, R>

  • Type parameters

    • T1

    • T2

    • T3

    • T4

    • R

    Parameters

    • func: (t1: T1, t2: T2, t3: T3, t4: T4) => R
        • (t1: T1, t2: T2, t3: T3, t4: T4): R
        • Parameters

          • t1: T1
          • t2: T2
          • t3: T3
          • t4: T4

          Returns R

    • Optional depth: number

    Returns Curry4<T1, T2, T3, T4, R>

  • Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • R

    Parameters

    • func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R
        • (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): R
        • Parameters

          • t1: T1
          • t2: T2
          • t3: T3
          • t4: T4
          • t5: T5

          Returns R

    • Optional depth: number

    Returns Curry5<T1, T2, T3, T4, T5, R>

  • Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • T6

    • R

    Parameters

    • func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6) => R
        • (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6): R
        • Parameters

          • t1: T1
          • t2: T2
          • t3: T3
          • t4: T4
          • t5: T5
          • t6: T6

          Returns R

    • Optional depth: number

    Returns Curry6<T1, T2, T3, T4, T5, T6, R>

Const incrementId

  • incrementId(): () => number

memoizeWith

  • memoizeWith<FN>(func: FN, harsher?: (...args: Parameters<FN>) => any): MemoizeWithReturnType<FN>
  • 缓存函数返回结果

    desc

    替换cache函数memoizeWith.Cache默认是Map

    example
    let count = 0;
    const counter = memoizeWith(n => {
       count++;
       return n * 2;
    })
    counter(50) // 100
    counter(50) // 100
    counter(50) // 100
    count // 1
    counter(100) // 200
    count // 2
    

    Type parameters

    Parameters

    • func: FN
    • Optional harsher: (...args: Parameters<FN>) => any

      默认会 args[0]

        • (...args: Parameters<FN>): any
        • Parameters

          • Rest ...args: Parameters<FN>

          Returns any

    Returns MemoizeWithReturnType<FN>

nextTick

  • nextTick(callback: Function, ...args: any[]): void | Immediate | Timeout
  • 延迟执行 event loop

    Parameters

    • callback: Function
    • Rest ...args: any[]

    Returns void | Immediate | Timeout

once

  • once<FN>(func: FN): FN
  • 只执行一次,之后调用返回第一次的结果

    Type parameters

    Parameters

    • func: FN

    Returns FN

prefSetInterval

  • prefSetInterval(handler: Function, ms?: number, ...args: any[]): number
  • 优先使用 requestAnimationFrame 实现 setInterval 如果没有 requestAnimationFrame 则用 setTimeout 实现 setInterval

    note

    当窗口未激活的时候会暂停

    Parameters

    • handler: Function
    • Optional ms: number
    • Rest ...args: any[]

    Returns number

prefSetTimeout

  • prefSetTimeout(handler: Function, timeout?: number, ...args: any[]): number
  • 优先使用 requestAnimationFrame 实现 setTimeout 如果没有 requestAnimationFrame 则使用 native setTimeout

    note

    当窗口未激活的时候会暂停

    Parameters

    • handler: Function
    • Optional timeout: number
    • Rest ...args: any[]

    Returns number

shallowEqual

  • shallowEqual<Context>(objA: any, objB: any, compare?: (this: Context, objA: any, objB: any, indexOrKey?: number | string) => boolean | void, compareContext?: Context): boolean
  • 浅比较两个值

    Type parameters

    • Context = any

    Parameters

    • objA: any
    • objB: any
    • Optional compare: (this: Context, objA: any, objB: any, indexOrKey?: number | string) => boolean | void
        • (this: Context, objA: any, objB: any, indexOrKey?: number | string): boolean | void
        • Parameters

          • this: Context
          • objA: any
          • objB: any
          • Optional indexOrKey: number | string

          Returns boolean | void

    • Optional compareContext: Context

    Returns boolean

Const singleton

  • singleton<T>(classTarget: T): T
  • singleton class

    example

    class A {} const SingletonA = singleton(A); console.log(new SingletonA() === new SingletonA()) // true;

    use decorators

    singleton

    class B {}

    Type parameters

    Parameters

    • classTarget: T

    Returns T

    class {classTarget}

toggle

  • toggle<D, R>(defaultValue: D, reverseValue: R): { setLeft: () => void; setRight: () => void; toggle: (value?: D | R) => void; value: D | R }
  • 两个值做切换

    Type parameters

    • D

    • R

    Parameters

    • defaultValue: D
    • reverseValue: R

    Returns { setLeft: () => void; setRight: () => void; toggle: (value?: D | R) => void; value: D | R }

    • setLeft: () => void
        • (): void
        • Returns void

    • setRight: () => void
        • (): void
        • Returns void

    • toggle: (value?: D | R) => void
        • (value?: D | R): void
        • Parameters

          • Optional value: D | R

          Returns void

    • value: D | R

tryCatch

  • tryCatch<FN>(tryer: FN, catcher: (...args: [any, ...Parameters<FN>]) => ReturnType<FN>): FN
  • 通过try catch包裹函数,如果失败会调用catcher返回相同结果,可以省略try catch

    example
    const result = tryCatch(() => throw new Error('error'), () => 1)
    result() // 1
    

    Type parameters

    Parameters

    • tryer: FN
    • catcher: (...args: [any, ...Parameters<FN>]) => ReturnType<FN>

      返回跟tryer相同结果

        • (...args: [any, ...Parameters<FN>]): ReturnType<FN>
        • Parameters

          • Rest ...args: [any, ...Parameters<FN>]

          Returns ReturnType<FN>

    Returns FN

uncurry

  • uncurry<T>(fn: AnyFn): T

Is Functions

getType

  • getType(value: any): string

isAndroid

  • isAndroid(ua?: string): boolean

isArguments

  • isArguments(value: any): value is IArguments

isArray

  • isArray<T, S>(value: T[] | S): value is T[]
  • 是否为Array类型

    Type parameters

    • T

    • S

    Parameters

    • value: T[] | S

    Returns value is T[]

isBrowser

  • isBrowser(): boolean

isChrome

  • isChrome(ua?: string): boolean

isDate

  • isDate(value: any): value is Date
  • 判断是否为Date对象

    Parameters

    • value: any

    Returns value is Date

isDef

  • isDef<T>(v: any): v is T
  • 是否是定义过的数据 值不是 undefined null

    Type parameters

    • T: string | number | bigint | boolean | symbol | object | any[]

    Parameters

    • v: any

    Returns v is T

isDigit

  • isDigit(value: any): value is number | bigint
  • 是否为数字

    note

    字符串数字也是数字

    Parameters

    • value: any

    Returns value is number | bigint

isEDGE

  • isEDGE(ua?: string): boolean

isEmpty

  • isEmpty(value: any): boolean

isError

  • isError(value: any): value is Error

isFile

  • isFile(value: any): value is File
  • 是否为File类型

    Parameters

    • value: any

    Returns value is File

isFirefox

  • isFirefox(ua?: string): boolean

isFunction

  • isFunction(func: any): func is Function

isHTMLElement

  • isHTMLElement(ele: any): ele is HTMLElement
  • 是否为HTML element

    note

    必须是 object(不是null) 且拥有 nodeType 和 nodeName 两个属性

    Parameters

    • ele: any

    Returns ele is HTMLElement

isIE

  • isIE(ua?: string): boolean

isIE8

  • isIE8(ua?: string): boolean

isIE9

  • isIE9(ua?: string): boolean

isIOS

  • isIOS(ua?: string): boolean

isInfinite

  • isInfinite(value: any): value is number

isMap

  • isMap(value: any): value is Map<any, any>
  • 是否为Map类型

    Parameters

    • value: any

    Returns value is Map<any, any>

isNaN

  • isNaN(value: any): value is number
  • 判断是否NaN

    Parameters

    • value: any

    Returns value is number

isNative

  • isNative(value: any): any

isNil

  • isNil(value: any): value is undefined | null
  • 判断是 undefined 或者是 null

    Parameters

    • value: any

    Returns value is undefined | null

isNode

  • isNode(): boolean

isNull

  • isNull(value: any): value is null

isNumber

  • isNumber(value: any): value is number

isObject

  • isObject<T>(value: unknown): value is {[ P in string | number | symbol]: unknown }
  • 定义一个参数是否是object类型的,不等同于javascript中的 typeof null 不是对象

    Type parameters

    • T: object

    Parameters

    • value: unknown

    Returns value is {[ P in string | number | symbol]: unknown }

isObjectLike

  • isObjectLike<T>(value: unknown): value is T
  • isObjectLike({}) => true isObjectLike([1, 2, 3]) => true isObjectLike(Function) => false isObjectLike(null) => false

    Type parameters

    • T

    Parameters

    • value: unknown

    Returns value is T

isOpera

  • isOpera(ua?: string): boolean

isPlanObject

  • isPlanObject<T>(value: unknown): value is {[ P in string | number | symbol]: unknown }
  • 判断是否 plan object 通过 "{}" 或者 "new Object" 创建的

    Type parameters

    • T: object

    Parameters

    • value: unknown

    Returns value is {[ P in string | number | symbol]: unknown }

isPrefersDarkMode

  • isPrefersDarkMode(): MediaQueryList

isPrimitive

  • isPrimitive(value: any): value is string | number | boolean | symbol
  • 判断是否原始数据类型

    Parameters

    • value: any

    Returns value is string | number | boolean | symbol

isPromise

  • isPromise<T, S>(obj: PromiseLike<T> | S): obj is PromiseLike<T>
  • 是否为promise

    Type parameters

    • T

    • S

    Parameters

    • obj: PromiseLike<T> | S

    Returns obj is PromiseLike<T>

isPrototype

  • isPrototype(value: any): boolean

isRegExp

  • isRegExp(value: any): value is RegExp

isSafari

  • isSafari(ua?: string): boolean

isSet

  • isSet(value: any): value is Set<any>
  • 是否为Set类型

    Parameters

    • value: any

    Returns value is Set<any>

isString

  • isString(value: any): value is string

isSymbol

  • isSymbol(value: any): value is symbol

isTypedArray

  • isTypedArray(value: any): value is Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray
  • check typed array

    Parameters

    • value: any

    Returns value is Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray

isUndefined

  • isUndefined(value: any): value is undefined

isUndefinedStr

  • isUndefinedStr(value: any): value is undefined

isWWBrowser

  • isWWBrowser(ua?: string): boolean

isWXBrowser

  • isWXBrowser(ua?: string): boolean

isWXMiniProgramWebView

  • isWXMiniProgramWebView(ua?: string): boolean

isWeakMap

  • isWeakMap(value: any): value is WeakMap<any, any>

isWeakSet

  • isWeakSet(value: any): value is WeakSet<any>

isWindow

  • isWindow(value: any): value is Window
  • 判断是否为window对象

    Parameters

    • value: any

    Returns value is Window

Number Functions

between

  • between(number: number, start: number, end: number): boolean
  • number is in a range

    example

    between(1, 2) // true between(2, 1, 3) // true between(3, 3) // false

    Parameters

    • number: number
    • start: number
    • end: number

    Returns boolean

modulo

  • modulo(n: number, d: number): number

numberToChinese

  • numberToChinese(n: number): string

numberToStringWithComma

  • numberToStringWithComma(number: number): string

Object Functions

convertObjectKeysCase

  • convertObjectKeysCase<T>(obj: T, action?: "toLowerCase"): LowercaseDictionary<T>
  • convertObjectKeysCase<T>(obj: T, action?: "toUpperCase"): UppercaseDictionary<T>

createDict

flipObject

  • flipObject<T>(obj: T): WeakMap<T[keyof T], keyof T>

mapObject

  • mapObject<U, T>(obj: T, predicate: (key: keyof T, value: T[keyof T], obj: T) => U[keyof U]): U
  • 遍历obj返回新的对象

    Type parameters

    Parameters

    • obj: T
    • predicate: (key: keyof T, value: T[keyof T], obj: T) => U[keyof U]
        • (key: keyof T, value: T[keyof T], obj: T): U[keyof U]
        • Parameters

          • key: keyof T
          • value: T[keyof T]
          • obj: T

          Returns U[keyof U]

    Returns U

toObjectArray

  • toObjectArray<T>(dict: Dictionary<any>, opts?: ToObjectArrayOptions<T>): T[]
  • object to array

    example
    const a = { a: 1, b: 2 }
    toObjectArray(a) // [{ value: 'a', label: 1 }, { value: 'b', label: 2 }]
    const b = new Map([['a', 1], ['b', 2]])
    toObjectArray(a) // [{ value: 'a', label: 1 }, { value: 'b', label: 2 }]
    

    Type parameters

    • T: Record<string, any> = { label: any; value: string }

    Parameters

    • dict: Dictionary<any>
    • Optional opts: ToObjectArrayOptions<T>
         @default { keyPropName: 'label', valuePropName: 'value' }
      

    Returns T[]

toPlanObject

  • toPlanObject(value?: any): Object

Other Functions

appendScript

  • appendScript(__namedParameters: Partial<HTMLScriptElement>): undefined | { script: HTMLScriptElement; remove: any }
  • Parameters

    • __namedParameters: Partial<HTMLScriptElement>

    Returns undefined | { script: HTMLScriptElement; remove: any }

asyncWorker

  • asyncWorker(ctx: Worker): { postMessage: <T, P>(payload: P, opts?: AsyncWorkerTaskOptions) => Promise<T>; register: (fn: CB) => void; setCtx: (c: Parameters<typeof asyncWorker>[0]) => void }
  • Parameters

    • ctx: Worker

    Returns { postMessage: <T, P>(payload: P, opts?: AsyncWorkerTaskOptions) => Promise<T>; register: (fn: CB) => void; setCtx: (c: Parameters<typeof asyncWorker>[0]) => void }

    • postMessage: <T, P>(payload: P, opts?: AsyncWorkerTaskOptions) => Promise<T>
        • <T, P>(payload: P, opts?: AsyncWorkerTaskOptions): Promise<T>
        • Type parameters

          • T

          • P = any

          Parameters

          • payload: P
          • Optional opts: AsyncWorkerTaskOptions

          Returns Promise<T>

    • register: (fn: CB) => void
        • (fn: CB): void
        • 只处理使用asyncWorker postMessage 发送的事件

          Parameters

          • fn: CB

            返回值作为 postMessage 的返回结果

          Returns void

    • setCtx: (c: Parameters<typeof asyncWorker>[0]) => void

b64ByteLength

  • b64ByteLength(b64: string): number
  • base64 string len

    description

    base64 is 4/3 + up to two characters of the original data

    Parameters

    • b64: string

    Returns number

    len

b64ToByteArray

  • b64ToByteArray(b64: string): Uint8Array | string[]
  • base64 转换成 Uint8Array

    Parameters

    • b64: string

    Returns Uint8Array | string[]

blobToDataURL

  • blobToDataURL(blob: Blob | File): Promise<string | ArrayBuffer>
  • 将blob对象转为DataUrl类型的数据

    Parameters

    • blob: Blob | File

    Returns Promise<string | ArrayBuffer>

byteArrayToB64

  • byteArrayToB64(uint8: number[]): string
  • Uint8Array to base64

    Parameters

    • uint8: number[]

    Returns string

    base64 string

byteLength

  • byteLength(str: string): number
  • 计算utf8字节长度

    Parameters

    • str: string

    Returns number

    returns the byte length of an utf8 string

byteToReadableSize

  • byteToReadableSize(value: number, fractionDigits?: number): string

camelcase

  • camelcase(str: string): string
  • 转换为驼峰

    example

    hello-word -> helloWord hello_word -> helloWord hello.word -> helloWord

    Parameters

    • str: string

    Returns string

canvasImageToBlob

  • canvasImageToBlob(url: string, opt?: { quality?: any; type?: string }): Promise<Blob>
  • 图片通过canvas转换成blob

    Parameters

    • url: string
    • Optional opt: { quality?: any; type?: string }
      • Optional quality?: any
      • Optional type?: string

    Returns Promise<Blob>

capitalize

  • capitalize(str: string): string

checkOverflow

  • checkOverflow(el: HTMLElement): boolean
  • Determines if the passed element is overflowing its bounds

    Parameters

    • el: HTMLElement

    Returns boolean

cloneDeep

  • cloneDeep<T>(value: T): T
  • This method is like _.clone except that it recursively clones value.

    Type parameters

    • T

    Parameters

    • value: T

      The value to recursively clone.

    Returns T

    Returns the deep cloned value.

compose

  • compose<T, V0>(fn1: Q<T, V0>): Q<T, V0>
  • compose<T, V0, V1>(fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V1>
  • compose<T, V0, V1, V2>(fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V2>
  • compose<T, V0, V1, V2, V3>(fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V3>
  • compose<T, V0, V1, V2, V3, V4>(fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V4>
  • compose<T, V0, V1, V2, V3, V4, V5>(fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V5>
  • compose<T, V0, V1, V2, V3, V4, V5, V6>(fn6: Fn<V5, V6>, fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V6>
  • compose<T, V0, V1, V2, V3, V4, V5, V6, V7>(fn7: Fn<V6, V7>, fn6: Fn<V5, V6>, fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V7>
  • compose<T, V0, V1, V2, V3, V4, V5, V6, V7, V8>(fn8: Fn<V7, V8>, fn7: Fn<V6, V7>, fn6: Fn<V5, V6>, fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V8>
  • compose<T, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9>(fn9: Fn<V8, V9>, fn8: Fn<V7, V8>, fn7: Fn<V6, V7>, fn6: Fn<V5, V6>, fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V9>
  • compose<T, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10>(fn10: Fn<V9, V10>, fn9: Fn<V8, V9>, fn8: Fn<V7, V8>, fn7: Fn<V6, V7>, fn6: Fn<V5, V6>, fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V10>
  • Type parameters

    • T

    • V0

    Parameters

    • fn1: Q<T, V0>

    Returns Q<T, V0>

  • Type parameters

    • T

    • V0

    • V1

    Parameters

    • fn1: Fn<V0, V1>
    • fn0: Q<T, V0>

    Returns Q<T, V1>

  • Type parameters

    • T

    • V0

    • V1

    • V2

    Parameters

    • fn2: Fn<V1, V2>
    • fn1: Fn<V0, V1>
    • fn0: Q<T, V0>

    Returns Q<T, V2>

  • Type parameters

    • T

    • V0

    • V1

    • V2

    • V3

    Parameters

    • fn3: Fn<V2, V3>
    • fn2: Fn<V1, V2>
    • fn1: Fn<V0, V1>
    • fn0: Q<T, V0>

    Returns Q<T, V3>

  • Type parameters

    • T

    • V0

    • V1

    • V2

    • V3

    • V4

    Parameters

    • fn4: Fn<V3, V4>
    • fn3: Fn<V2, V3>
    • fn2: Fn<V1, V2>
    • fn1: Fn<V0, V1>
    • fn0: Q<T, V0>

    Returns Q<T, V4>

  • Type parameters

    • T

    • V0

    • V1

    • V2

    • V3

    • V4

    • V5

    Parameters

    • fn5: Fn<V4, V5>
    • fn4: Fn<V3, V4>
    • fn3: Fn<V2, V3>
    • fn2: Fn<V1, V2>
    • fn1: Fn<V0, V1>
    • fn0: Q<T, V0>

    Returns Q<T, V5>

  • Type parameters

    • T

    • V0

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    Parameters

    • fn6: Fn<V5, V6>
    • fn5: Fn<V4, V5>
    • fn4: Fn<V3, V4>
    • fn3: Fn<V2, V3>
    • fn2: Fn<V1, V2>
    • fn1: Fn<V0, V1>
    • fn0: Q<T, V0>

    Returns Q<T, V6>

  • Type parameters

    • T

    • V0

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    Parameters

    • fn7: Fn<V6, V7>
    • fn6: Fn<V5, V6>
    • fn5: Fn<V4, V5>
    • fn4: Fn<V3, V4>
    • fn3: Fn<V2, V3>
    • fn2: Fn<V1, V2>
    • fn1: Fn<V0, V1>
    • fn0: Q<T, V0>

    Returns Q<T, V7>

  • Type parameters

    • T

    • V0

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    • V8

    Parameters

    • fn8: Fn<V7, V8>
    • fn7: Fn<V6, V7>
    • fn6: Fn<V5, V6>
    • fn5: Fn<V4, V5>
    • fn4: Fn<V3, V4>
    • fn3: Fn<V2, V3>
    • fn2: Fn<V1, V2>
    • fn1: Fn<V0, V1>
    • fn0: Q<T, V0>

    Returns Q<T, V8>

  • Type parameters

    • T

    • V0

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    • V8

    • V9

    Parameters

    • fn9: Fn<V8, V9>
    • fn8: Fn<V7, V8>
    • fn7: Fn<V6, V7>
    • fn6: Fn<V5, V6>
    • fn5: Fn<V4, V5>
    • fn4: Fn<V3, V4>
    • fn3: Fn<V2, V3>
    • fn2: Fn<V1, V2>
    • fn1: Fn<V0, V1>
    • fn0: Q<T, V0>

    Returns Q<T, V9>

  • Type parameters

    • T

    • V0

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    • V8

    • V9

    • V10

    Parameters

    • fn10: Fn<V9, V10>
    • fn9: Fn<V8, V9>
    • fn8: Fn<V7, V8>
    • fn7: Fn<V6, V7>
    • fn6: Fn<V5, V6>
    • fn5: Fn<V4, V5>
    • fn4: Fn<V3, V4>
    • fn3: Fn<V2, V3>
    • fn2: Fn<V1, V2>
    • fn1: Fn<V0, V1>
    • fn0: Q<T, V0>

    Returns Q<T, V10>

computeMaxCallStackSize

  • computeMaxCallStackSize(): any

copyDict

  • copyDict<T>(dict: T): T

createUniqueString

  • createUniqueString(): string

dataURLToBlob

  • dataURLToBlob(dataUrl: string): Blob

dataURLtoFile

  • dataURLtoFile(dataUrl: string, filename: string): File

debounce

  • debounce<T>(func: T, wait: undefined | number, options: DebounceSettingsLeading): DebouncedFuncLeading<T>
  • debounce<T>(func: T, wait?: number, options?: DebounceSettings): DebouncedFunc<T>
  • Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked. The debounced function comes with a cancel method to cancel delayed invocations and a flush method to immediately invoke them. Provide an options object to indicate that func should be invoked on the leading and/or trailing edge of the wait timeout. Subsequent calls to the debounced function return the result of the last func invocation.

    Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only if the the debounced function is invoked more than once during the wait timeout.

    See David Corbacho’s article for details over the differences between _.debounce and _.throttle.

    Type parameters

    • T: (...args: any) => any

    Parameters

    • func: T

      The function to debounce.

    • wait: undefined | number

      The number of milliseconds to delay.

    • options: DebounceSettingsLeading

      The options object.

    Returns DebouncedFuncLeading<T>

    Returns the new debounced function.

  • Type parameters

    • T: (...args: any) => any

    Parameters

    • func: T
    • Optional wait: number
    • Optional options: DebounceSettings

    Returns DebouncedFunc<T>

decamelize

  • decamelize(string: string, options?: DecamelizeOpts): string
  • 驼峰转换成其他格式

    example

    decamelize('sayName'); // say_name

    Parameters

    • string: string
    • options: DecamelizeOpts = {}

    Returns string

decimal

  • decimal(n: Decimal.Value): Decimal

documentShim

  • documentShim(): any

ensure

  • ensure(condition: boolean, msg: string): asserts condition
  • 如果值有问题则报错

    Parameters

    • condition: boolean
    • msg: string

    Returns asserts condition

ensureCallable

  • ensureCallable<T>(fn: any): T
  • 如果fn不是一个函数就报typeError

    Type parameters

    • T: Function = any

    Parameters

    • fn: any

    Returns T

    fn 如果fn是函数,则返回函数,否则报错

equal

  • equal(a: any, b: any): boolean

fetchBlob

  • fetchBlob(url: string, options?: { credentials?: "include" | "omit"; headers: Record<string, string> }): Promise<Blob>
  • 通过myFetch获取远程资源blob

    Parameters

    • url: string
    • Optional options: { credentials?: "include" | "omit"; headers: Record<string, string> }
      • Optional credentials?: "include" | "omit"
      • headers: Record<string, string>

    Returns Promise<Blob>

fetchShim

  • fetchShim(): void

format

  • format(text: string, args: Record<string, string | number>): string
  • format(text: string, ...args: (string | number)[]): string
  • 字符串format

    example

    format('hello {0}', 'bob') // hello bob

    Parameters

    • text: string
    • args: Record<string, string | number>

    Returns string

  • Parameters

    • text: string
    • Rest ...args: (string | number)[]

    Returns string

get

getRandomBool

  • getRandomBool(): boolean
  • 获取随机bool值

    Returns boolean

    a random true/false

getRandomFloat

  • getRandomFloat(min: number, max: number): number
  • 获取一个介于 minmax 之间的随机浮点数。

    Parameters

    • min: number

      min number

    • max: number

      max number

    Returns number

    a random floating point number

getRandomHexColor

  • getRandomHexColor(): string

getRandomInt

  • getRandomInt(min: number, max: number): number
  • 获取一个介于 minmax 之间的随机整数。

    Parameters

    • min: number

      min number

    • max: number

      max number

    Returns number

    a random integer

getRandomLower

  • getRandomLower(): string

getRandomNumber

  • getRandomNumber(): string

getRandomString

  • getRandomString(len: number, types?: keyof typeof randomFunc[]): string
  • 生成一定长度随机数

    Parameters

    • len: number

      长度

    • types: keyof typeof randomFunc[] = ...

      随机字符串需要包含的字符

    Returns string

getRandomSymbol

  • getRandomSymbol(): string

getRandomUpper

  • getRandomUpper(): string

invertCase

  • invertCase(str: string): string
  • Inverts the case of a string

    example

    Str.invertCase('Hello'); // => 'hELLO'

    Parameters

    • str: string

    Returns string

isArrayLike

  • isArrayLike<T, S>(value: ArrayLike<T> | S): value is ArrayLike<T>
  • 是否为一个类数组

    Type parameters

    • T

    • S

    Parameters

    • value: ArrayLike<T> | S

    Returns value is ArrayLike<T>

noop

  • noop(): void

pipe

  • pipe<A, B, C>(ab: (a: A) => B, bc: (b: B) => C): (a: A) => C
  • pipe<A, B, C, D>(ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (a: A) => D
  • pipe<A, B, C, D, E>(ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): (a: A) => E
  • pipe<A, B, C, D, E, F>(ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): (a: A) => F
  • pipe<A, B, C, D, E, F, G>(ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): (a: A) => G
  • pipe<A, B, C, D, E, F, G, H>(ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H): (a: A) => H
  • pipe<A, B, C, D, E, F, G, H, I>(ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I): (a: A) => I
  • pipe<A, B, C, D, E, F, G, H, I, J>(ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J): (a: A) => J
  • Type parameters

    • A

    • B

    • C

    Parameters

    • ab: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • bc: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    Returns (a: A) => C

      • (a: A): C
      • Parameters

        • a: A

        Returns C

  • Type parameters

    • A

    • B

    • C

    • D

    Parameters

    • ab: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • bc: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    • cd: (c: C) => D
        • (c: C): D
        • Parameters

          • c: C

          Returns D

    Returns (a: A) => D

      • (a: A): D
      • Parameters

        • a: A

        Returns D

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    Parameters

    • ab: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • bc: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    • cd: (c: C) => D
        • (c: C): D
        • Parameters

          • c: C

          Returns D

    • de: (d: D) => E
        • (d: D): E
        • Parameters

          • d: D

          Returns E

    Returns (a: A) => E

      • (a: A): E
      • Parameters

        • a: A

        Returns E

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    Parameters

    • ab: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • bc: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    • cd: (c: C) => D
        • (c: C): D
        • Parameters

          • c: C

          Returns D

    • de: (d: D) => E
        • (d: D): E
        • Parameters

          • d: D

          Returns E

    • ef: (e: E) => F
        • (e: E): F
        • Parameters

          • e: E

          Returns F

    Returns (a: A) => F

      • (a: A): F
      • Parameters

        • a: A

        Returns F

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    Parameters

    • ab: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • bc: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    • cd: (c: C) => D
        • (c: C): D
        • Parameters

          • c: C

          Returns D

    • de: (d: D) => E
        • (d: D): E
        • Parameters

          • d: D

          Returns E

    • ef: (e: E) => F
        • (e: E): F
        • Parameters

          • e: E

          Returns F

    • fg: (f: F) => G
        • (f: F): G
        • Parameters

          • f: F

          Returns G

    Returns (a: A) => G

      • (a: A): G
      • Parameters

        • a: A

        Returns G

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    Parameters

    • ab: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • bc: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    • cd: (c: C) => D
        • (c: C): D
        • Parameters

          • c: C

          Returns D

    • de: (d: D) => E
        • (d: D): E
        • Parameters

          • d: D

          Returns E

    • ef: (e: E) => F
        • (e: E): F
        • Parameters

          • e: E

          Returns F

    • fg: (f: F) => G
        • (f: F): G
        • Parameters

          • f: F

          Returns G

    • gh: (g: G) => H
        • (g: G): H
        • Parameters

          • g: G

          Returns H

    Returns (a: A) => H

      • (a: A): H
      • Parameters

        • a: A

        Returns H

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    Parameters

    • ab: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • bc: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    • cd: (c: C) => D
        • (c: C): D
        • Parameters

          • c: C

          Returns D

    • de: (d: D) => E
        • (d: D): E
        • Parameters

          • d: D

          Returns E

    • ef: (e: E) => F
        • (e: E): F
        • Parameters

          • e: E

          Returns F

    • fg: (f: F) => G
        • (f: F): G
        • Parameters

          • f: F

          Returns G

    • gh: (g: G) => H
        • (g: G): H
        • Parameters

          • g: G

          Returns H

    • hi: (h: H) => I
        • (h: H): I
        • Parameters

          • h: H

          Returns I

    Returns (a: A) => I

      • (a: A): I
      • Parameters

        • a: A

        Returns I

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • J

    Parameters

    • ab: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • bc: (b: B) => C
        • (b: B): C
        • Parameters

          • b: B

          Returns C

    • cd: (c: C) => D
        • (c: C): D
        • Parameters

          • c: C

          Returns D

    • de: (d: D) => E
        • (d: D): E
        • Parameters

          • d: D

          Returns E

    • ef: (e: E) => F
        • (e: E): F
        • Parameters

          • e: E

          Returns F

    • fg: (f: F) => G
        • (f: F): G
        • Parameters

          • f: F

          Returns G

    • gh: (g: G) => H
        • (g: G): H
        • Parameters

          • g: G

          Returns H

    • hi: (h: H) => I
        • (h: H): I
        • Parameters

          • h: H

          Returns I

    • ij: (i: I) => J
        • (i: I): J
        • Parameters

          • i: I

          Returns J

    Returns (a: A) => J

      • (a: A): J
      • Parameters

        • a: A

        Returns J

promisify

  • promisify<T>(f: (cb: (err: any, res: T) => void) => void, thisContext?: any): () => Promise<T>
  • promisify<A, T>(f: (arg: A, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A) => Promise<T>
  • promisify<A, A2, T>(f: (arg: A, arg2: A2, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2) => Promise<T>
  • promisify<A, A2, A3, T>(f: (arg: A, arg2: A2, arg3: A3, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2, arg3: A3) => Promise<T>
  • promisify<A, A2, A3, A4, T>(f: (arg: A, arg2: A2, arg3: A3, arg4: A4, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2, arg3: A3, arg4: A4) => Promise<T>
  • promisify<A, A2, A3, A4, A5, T>(f: (arg: A, arg2: A2, arg3: A3, arg4: A4, arg5: A5, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Promise<T>
  • Type parameters

    • T

    Parameters

    • f: (cb: (err: any, res: T) => void) => void
        • (cb: (err: any, res: T) => void): void
        • Parameters

          • cb: (err: any, res: T) => void
              • (err: any, res: T): void
              • Parameters

                • err: any
                • res: T

                Returns void

          Returns void

    • Optional thisContext: any

    Returns () => Promise<T>

      • (): Promise<T>
      • Returns Promise<T>

  • Type parameters

    • A

    • T

    Parameters

    • f: (arg: A, cb: (err: any, res: T) => void) => void
        • (arg: A, cb: (err: any, res: T) => void): void
        • Parameters

          • arg: A
          • cb: (err: any, res: T) => void
              • (err: any, res: T): void
              • Parameters

                • err: any
                • res: T

                Returns void

          Returns void

    • Optional thisContext: any

    Returns (arg: A) => Promise<T>

      • (arg: A): Promise<T>
      • Parameters

        • arg: A

        Returns Promise<T>

  • Type parameters

    • A

    • A2

    • T

    Parameters

    • f: (arg: A, arg2: A2, cb: (err: any, res: T) => void) => void
        • (arg: A, arg2: A2, cb: (err: any, res: T) => void): void
        • Parameters

          • arg: A
          • arg2: A2
          • cb: (err: any, res: T) => void
              • (err: any, res: T): void
              • Parameters

                • err: any
                • res: T

                Returns void

          Returns void

    • Optional thisContext: any

    Returns (arg: A, arg2: A2) => Promise<T>

      • (arg: A, arg2: A2): Promise<T>
      • Parameters

        • arg: A
        • arg2: A2

        Returns Promise<T>

  • Type parameters

    • A

    • A2

    • A3

    • T

    Parameters

    • f: (arg: A, arg2: A2, arg3: A3, cb: (err: any, res: T) => void) => void
        • (arg: A, arg2: A2, arg3: A3, cb: (err: any, res: T) => void): void
        • Parameters

          • arg: A
          • arg2: A2
          • arg3: A3
          • cb: (err: any, res: T) => void
              • (err: any, res: T): void
              • Parameters

                • err: any
                • res: T

                Returns void

          Returns void

    • Optional thisContext: any

    Returns (arg: A, arg2: A2, arg3: A3) => Promise<T>

      • (arg: A, arg2: A2, arg3: A3): Promise<T>
      • Parameters

        • arg: A
        • arg2: A2
        • arg3: A3

        Returns Promise<T>

  • Type parameters

    • A

    • A2

    • A3

    • A4

    • T

    Parameters

    • f: (arg: A, arg2: A2, arg3: A3, arg4: A4, cb: (err: any, res: T) => void) => void
        • (arg: A, arg2: A2, arg3: A3, arg4: A4, cb: (err: any, res: T) => void): void
        • Parameters

          • arg: A
          • arg2: A2
          • arg3: A3
          • arg4: A4
          • cb: (err: any, res: T) => void
              • (err: any, res: T): void
              • Parameters

                • err: any
                • res: T

                Returns void

          Returns void

    • Optional thisContext: any

    Returns (arg: A, arg2: A2, arg3: A3, arg4: A4) => Promise<T>

      • (arg: A, arg2: A2, arg3: A3, arg4: A4): Promise<T>
      • Parameters

        • arg: A
        • arg2: A2
        • arg3: A3
        • arg4: A4

        Returns Promise<T>

  • Type parameters

    • A

    • A2

    • A3

    • A4

    • A5

    • T

    Parameters

    • f: (arg: A, arg2: A2, arg3: A3, arg4: A4, arg5: A5, cb: (err: any, res: T) => void) => void
        • (arg: A, arg2: A2, arg3: A3, arg4: A4, arg5: A5, cb: (err: any, res: T) => void): void
        • Parameters

          • arg: A
          • arg2: A2
          • arg3: A3
          • arg4: A4
          • arg5: A5
          • cb: (err: any, res: T) => void
              • (err: any, res: T): void
              • Parameters

                • err: any
                • res: T

                Returns void

          Returns void

    • Optional thisContext: any

    Returns (arg: A, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Promise<T>

      • (arg: A, arg2: A2, arg3: A3, arg4: A4, arg5: A5): Promise<T>
      • Parameters

        • arg: A
        • arg2: A2
        • arg3: A3
        • arg4: A4
        • arg5: A5

        Returns Promise<T>

rgbaColorToHex

  • rgbaColorToHex(rgba: string): string
  • rgba color 转化为 hex

    Parameters

    • rgba: string

    Returns string

set

  • set<Entity, Output, Value>(entity: Entity, paths: PropertyPath[], value: Value): Output
  • Type parameters

    • Entity = any

    • Output = Entity

    • Value = any

    Parameters

    Returns Output

slash

  • slash(path: string): string
  • 接受Windows反斜杠路径,并返回带有正斜杠的路径

    Parameters

    • path: string

    Returns string

stripHtmlTags

  • stripHtmlTags(str: string, options?: stripHtmlTagsOption): string
  • Strip html tags from a string

    example

    stripHtmlTags('

    hello word

    '); // => 'hello word' stripHtmlTags('

    hello word

    ', { blocked: ['p'] }); // => 'hello word' stripHtmlTags('

    hello

    ', { blocked: ['p'], replaceWith: '**' }); // => 'hello'

    Parameters

    • str: string
    • options: stripHtmlTagsOption = {}

    Returns string

structuralClone

  • structuralClone<T>(obj: T): Promise<T>

throttle

  • throttle<T>(func: T, wait?: number, options?: ThrottleSettings): DebouncedFunc<T>
  • Creates a throttled function that only invokes func at most once per every wait milliseconds. The throttled function comes with a cancel method to cancel delayed invocations and a flush method to immediately invoke them. Provide an options object to indicate that func should be invoked on the leading and/or trailing edge of the wait timeout. Subsequent calls to the throttled function return the result of the last func call.

    Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only if the the throttled function is invoked more than once during the wait timeout.

    Type parameters

    • T: (...args: any) => any

    Parameters

    • func: T

      The function to throttle.

    • Optional wait: number

      The number of milliseconds to throttle invocations to.

    • Optional options: ThrottleSettings

      The options object.

    Returns DebouncedFunc<T>

    Returns the new throttled function.

trimAll

  • trimAll(str: string): string
  • 去除字符串中所有空格

    Parameters

    • str: string

    Returns string

trimEnd

  • trimEnd(str: string): string

trimStart

  • trimStart(str: string): string

tryParse

  • tryParse<T>(str: string, defaultVal?: T): T
  • JSON.parse字符串

    Type parameters

    • T: unknown

    Parameters

    • str: string
    • Optional defaultVal: T

    Returns T

uuid

  • uuid(): string

warn

  • warn(condition: boolean, msg: string): void
  • 如果值有问题则warn

    Parameters

    • condition: boolean
    • msg: string

    Returns void

windowShim

  • windowShim(): void

Promise Functions

asyncPool

  • asyncPool(option: AsyncPoolOption): { clear: () => void; executor: <T>(fn: PromiseFN<T>, opts?: AsyncPoolExecutorOpts) => Promise<T>; length: () => number }
  • 异步池,放入需要执行的异步任务,总并行执行任务不超过设置的最大并发数量

    Parameters

    Returns { clear: () => void; executor: <T>(fn: PromiseFN<T>, opts?: AsyncPoolExecutorOpts) => Promise<T>; length: () => number }

    • clear: () => void
        • (): void
        • 清理掉当前所有任务

          Returns void

    • executor: <T>(fn: PromiseFN<T>, opts?: AsyncPoolExecutorOpts) => Promise<T>
        • <T>(fn: PromiseFN<T>, opts?: AsyncPoolExecutorOpts): Promise<T>
        • 添加一个任务,返回当前任务的执行结果

          Type parameters

          • T

          Parameters

          • fn: PromiseFN<T>
          • Optional opts: AsyncPoolExecutorOpts

          Returns Promise<T>

    • length: () => number
        • (): number
        • 当前任务长度

          Returns number

          queue len

defer

  • defer<T>(): { promise: Promise<T>; reject: (reason?: any) => void; resolve: (value?: T | PromiseLike<T>) => void }
  • 返回一个promise,外部可以控制promise状态

    Type parameters

    • T

    Returns { promise: Promise<T>; reject: (reason?: any) => void; resolve: (value?: T | PromiseLike<T>) => void }

    • promise: Promise<T>
    • reject: (reason?: any) => void
        • (reason?: any): void
        • Parameters

          • Optional reason: any

          Returns void

    • resolve: (value?: T | PromiseLike<T>) => void
        • (value?: T | PromiseLike<T>): void
        • Parameters

          • Optional value: T | PromiseLike<T>

          Returns void

delay

  • delay<T>(delayTimeMs: number, value: T): Promise<T>
  • delay<T>(delayTimeMs: number): Promise<void>
  • 等待一段时间,返回一个promise

    default

    25

    Type parameters

    • T

    Parameters

    • delayTimeMs: number
    • value: T

    Returns Promise<T>

  • Type parameters

    • T

    Parameters

    • delayTimeMs: number

    Returns Promise<void>

immediate

  • immediate<T>(value: T): Promise<T>
  • immediate<T>(): Promise<void>

invert

  • invert(promise: Promise<any>, message?: string): Promise<any>
  • 成功就报错,取反的情况

    Parameters

    • promise: Promise<any>
    • Optional message: string

    Returns Promise<any>

mapLimit

  • mapLimit<T, V>(input: readonly T[], limit: number, iteratee: (value: T, index: number) => Promise<V>): Promise<V[]>
  • mapLimit<T, V>(input: readonly T[], limit: number, iteratee: (value: T) => Promise<V>): Promise<V[]>
  • mapLimit<T, V>(input: T, limit: number, iteratee: (value: T[keyof T], key: string) => Promise<V>): Promise<V[]>
  • mapLimit<T, V>(input: T, limit: number, iteratee: (value: T[keyof T]) => Promise<V>): Promise<V[]>
  • 按批次执行promise

    Type parameters

    • T

    • V

    Parameters

    • input: readonly T[]
    • limit: number
    • iteratee: (value: T, index: number) => Promise<V>
        • (value: T, index: number): Promise<V>
        • Parameters

          • value: T
          • index: number

          Returns Promise<V>

    Returns Promise<V[]>

  • Type parameters

    • T

    • V

    Parameters

    • input: readonly T[]
    • limit: number
    • iteratee: (value: T) => Promise<V>
        • (value: T): Promise<V>
        • Parameters

          • value: T

          Returns Promise<V>

    Returns Promise<V[]>

  • Type parameters

    • T: Object

    • V

    Parameters

    • input: T
    • limit: number
    • iteratee: (value: T[keyof T], key: string) => Promise<V>
        • (value: T[keyof T], key: string): Promise<V>
        • Parameters

          • value: T[keyof T]
          • key: string

          Returns Promise<V>

    Returns Promise<V[]>

  • Type parameters

    • T: Object

    • V

    Parameters

    • input: T
    • limit: number
    • iteratee: (value: T[keyof T]) => Promise<V>
        • (value: T[keyof T]): Promise<V>
        • Parameters

          • value: T[keyof T]

          Returns Promise<V>

    Returns Promise<V[]>

memoize

  • memoize<FnType>(fn: FnType, harsher?: (...args: Parameters<FnType>) => any, timeoutMs?: number): MemoizeReturnType<FnType>
  • 缓存promise结果,支持超时时间

    Type parameters

    • FnType: AnyPromiseFN<any, any, FnType>

    Parameters

    • fn: FnType

      被代理的异步函数

    • harsher: (...args: Parameters<FnType>) => any = ...

      返回标示本次运行结果的key

        • (...args: Parameters<FnType>): any
        • Parameters

          • Rest ...args: Parameters<FnType>

          Returns any

    • Optional timeoutMs: number

    Returns MemoizeReturnType<FnType>

pIf

  • pIf<ValueType, DoIfReturnType, DoElseReturnType>(condition: boolean | ((value: ValueType) => boolean | PromiseLike<boolean>), doIf: (value: ValueType) => DoIfReturnType | PromiseLike<DoIfReturnType>, doElse?: (value: ValueType) => DoElseReturnType | PromiseLike<DoElseReturnType>): (value: ValueType) => Promise<DoIfReturnType | DoElseReturnType>
  • promise 链式条件判断

    Type parameters

    • ValueType

    • DoIfReturnType

    • DoElseReturnType = ValueType

    Parameters

    • condition: boolean | ((value: ValueType) => boolean | PromiseLike<boolean>)

      true 调用 doIf 否则 doElse

    • doIf: (value: ValueType) => DoIfReturnType | PromiseLike<DoIfReturnType>

      如果 condition 为 true 执行

        • (value: ValueType): DoIfReturnType | PromiseLike<DoIfReturnType>
        • Parameters

          • value: ValueType

          Returns DoIfReturnType | PromiseLike<DoIfReturnType>

    • Optional doElse: (value: ValueType) => DoElseReturnType | PromiseLike<DoElseReturnType>

      如果 condition 为 false 执行

        • (value: ValueType): DoElseReturnType | PromiseLike<DoElseReturnType>
        • Parameters

          • value: ValueType

          Returns DoElseReturnType | PromiseLike<DoElseReturnType>

    Returns (value: ValueType) => Promise<DoIfReturnType | DoElseReturnType>

      • (value: ValueType): Promise<DoIfReturnType | DoElseReturnType>
      • Parameters

        • value: ValueType

        Returns Promise<DoIfReturnType | DoElseReturnType>

pTry

  • pTry<ValueType, ErrorType>(promise: Promise<ValueType>): Promise<[ErrorType, ValueType]>
  • 合并返回promise的结果和错误

    Type parameters

    • ValueType

    • ErrorType = any

    Parameters

    • promise: Promise<ValueType>

    Returns Promise<[ErrorType, ValueType]>

    Error and result array

padding

  • padding<T>(promise: T, paddingMs: number): Promise<T>
  • 延迟promise返回结果

    Type parameters

    • T

    Parameters

    • promise: T
    • paddingMs: number

    Returns Promise<T>

retry

  • promise重试 如果没有重试次数则一直重试

    Type parameters

    • T: Function

    Parameters

    • fn: T

      重试函数,需要返回promise

    • retryOption: RetryOption

    Returns T

sequenceChain

  • sequenceChain(handlers: [AnyPromiseFN, AnyPromiseFN][]): <T>(value?: any) => Promise<T>
  • 链式处理,向下传递结果

    Parameters

    • handlers: [AnyPromiseFN, AnyPromiseFN][]

    Returns <T>(value?: any) => Promise<T>

      • <T>(value?: any): Promise<T>
      • Type parameters

        • T

        Parameters

        • Optional value: any

        Returns Promise<T>

settleAll

  • settleAll<T, V>(promises: readonly Promise<T>[], errFn?: (err: any, ind: number) => Promise<V>): Promise<SettledPromises<T, V>>
  • settleAll<T, V>(promises: readonly Promise<T>[], errFn?: (err: any) => Promise<V>): Promise<SettledPromises<T, V>>
  • settleAll<T, V>(promises: readonly Promise<T>[], errFn?: (err: any, ind: number) => V): Promise<SettledPromises<T, V>>
  • settleAll<T, V>(promises: readonly Promise<T>[], errFn?: (err: any) => V): Promise<SettledPromises<T, V>>
  • 处理多个promise的时候,返回promise数组的成功失败结果,索引为promise数组下标 并行Promise.all执行

    Type parameters

    • T

    • V

    Parameters

    • promises: readonly Promise<T>[]
    • Optional errFn: (err: any, ind: number) => Promise<V>
        • (err: any, ind: number): Promise<V>
        • Parameters

          • err: any
          • ind: number

          Returns Promise<V>

    Returns Promise<SettledPromises<T, V>>

  • Type parameters

    • T

    • V

    Parameters

    • promises: readonly Promise<T>[]
    • Optional errFn: (err: any) => Promise<V>
        • (err: any): Promise<V>
        • Parameters

          • err: any

          Returns Promise<V>

    Returns Promise<SettledPromises<T, V>>

  • Type parameters

    • T

    • V

    Parameters

    • promises: readonly Promise<T>[]
    • Optional errFn: (err: any, ind: number) => V
        • (err: any, ind: number): V
        • Parameters

          • err: any
          • ind: number

          Returns V

    Returns Promise<SettledPromises<T, V>>

  • Type parameters

    • T

    • V

    Parameters

    • promises: readonly Promise<T>[]
    • Optional errFn: (err: any) => V
        • (err: any): V
        • Parameters

          • err: any

          Returns V

    Returns Promise<SettledPromises<T, V>>

singleLock

  • singleLock<T>(): { exit: <R>(args?: R) => void; lock: () => Promise<void> | Promise<T>; unLock: <T>(args: T) => void }
  • 获取一个锁

    Type parameters

    • T = any

    Returns { exit: <R>(args?: R) => void; lock: () => Promise<void> | Promise<T>; unLock: <T>(args: T) => void }

    lock 获得锁 unLock 解锁,promise.resolve exit 退出,promise.reject

    • exit: <R>(args?: R) => void
        • <R>(args?: R): void
        • Type parameters

          • R = any

          Parameters

          • Optional args: R

          Returns void

    • lock: () => Promise<void> | Promise<T>
        • (): Promise<void> | Promise<T>
        • Returns Promise<void> | Promise<T>

    • unLock: <T>(args: T) => void
        • <T>(args: T): void
        • Type parameters

          • T

          Parameters

          • args: T

          Returns void

timeout

  • timeout<T>(fn: T, expirationTime: number, errorMessage?: string): T
  • 设置时间限制超时返回报错

    Type parameters

    • T: Function

    Parameters

    • fn: T
    • expirationTime: number
    • Optional errorMessage: string

    Returns T

transformErrors

  • transformErrors<T>(fn: T, errorHandler: Function): T
  • 定义promise错误处理函数 一些符合预期的错误,不需要报错,可以加一层转换下

    Type parameters

    • T: Function

    Parameters

    • fn: T
    • errorHandler: Function

    Returns T

until

  • until<T>(fn: T, retryOption: BaseRetryOption): T
  • promise resolve 没有值的情况重试,每次失败reject都会报错 一定次数内重试获取获取一些异步的值

    Type parameters

    • T: (...args: any[]) => Promise<any>

    Parameters

    • fn: T
    • retryOption: BaseRetryOption

    Returns T