Skip to content

Depeng0929/tools

Repository files navigation

@depeng9527/tools

npm version

Opinionated collection of common JavaScript / TypeScript utils by Depeng0929.

Is

包括常用的数据类型判断。

import {
  isRegExp,
  isFunction,
  isString,
  isNumber,
  isObject,
  isDate,
  isSymbol,
  isSet,
  isMap,
  isNull,
  isUndefined,
} from '@depng9527/tools'
  • isNil: 是否是undefinednull
  • notNil: 与isNill相反
  • isBrowser:是否在游览器中

String

  • ensurePrefix

  • ensureSuffix

  • randomStr

  • pascalCase,camelCase,kebabCase, capitalize

Math

常用的数学运算

import {
  add, divide, subtract, multiply 
} from '@depng9527/tools'
  • sum: 求数组的和
  • clamp: clamp(n, min, max)返回n到min,max之间最近的点

Array

  • range

  • uniq

  • at

  • last

  • head

  • remove

  • removeElement

  • move

  • toArray

Object

  • deepClone

  • deepMerge

  • objectMap

  • renameKeys

// { b: 2 }
objectMap({ a: 1, b: 2 }, (k, v) => k === 'a' ? undefined : [k, v])

Function

  • tap: 通常执行一些副作用
  function createUser(name: string): User {
    return tap(new User, user => {
      user.name = name
    })
  }
  • assert: 断言

  • debug: debug

Vendor

  • throttle

  • debounce

  • findValueByKey

  • isEmpty

  • select: like sql

  • pick: like sql

time

  • formateTime

  • timeStamp

pLimit

  • p