Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-utils-plus

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-utils-plus

Javascript工具包

  • 0.5.3
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

js-utils-plus

介绍

Javascript 工具包

安装

  npm i js-utils-plus --save

使用

// ES6
import * as utilsPlus from "js-utils-plus";

// CommonJS(不支持)
const utilsPlus = require("js-utils-plus");

使用说明

Array
  • treeToArray:树转列表,(tree: any[], key = "children"): any[]
  • arrayToTree:列表转树,(arr: any[], key: string, parentKey = "parentId"): any[]
  • arrayToObject:列表转对象,(arr: [], key: string, value: string): object
  • arrayDistinct:数组去重,(arr: any[], key?: string): any[]
  • arraySameAbove:默认同上,(arr: any[], props: string | string[]): any[]
Object
  • objectPick:创建对象中选中属性的新对象,(obj: object, props: string | string[]): T
  • objectOmit:创建对象中忽略属性的新对象,(obj: object, props: string | string[]): T
  • objectFormatKey: 创建格式化对象键的新对象,(obj: object, format: RegExp | Function): T
  • objectFormatValue: 创建格式化对象值的新对象,(obj: object, format: RegExp | Function): T
Function
  • promisify:回调函数快速转换 promise 对象,(fn: Function, _this?: any): Function
  • delay: promise 等待函数(毫秒),(time: number): Promise
  • debounce:防抖函数(固定延时后触发),(func: Function, wait = 1000): Function
  • throttle:节流函数(固定时间内触发),(func: Function, wait = 1000, leading = true): Function
  • throttleWithArgsList:节流函数合并参数(固定时间内触发),(func: Function, wait = 1000): Function
String
  • camelCase:蛇形转驼峰,(str: string): string
  • snakeCase:驼峰转蛇形,(str: string): string
  • byteLength:字符串字节长度,(str: string): number
  • strSeparated:分割数字/字符串(倒序),(str: string, separator = ',', length = 3): string
  • replaceSubstr: 替换子字符串,(str: string, start: number, end: number, replacement: string): string
Number
  • toInt: 转为整数,(num: any): number | boolean
  • toNumber: 转为数字,(num: any): number | boolean
  • toFixed: 数字精度转换,(num: number, digit = 2): number
  • meterToFt: 米(m)转英尺(ft),(num: number, digit = 2): number
  • ftToMeter: 英尺(ft)转米(m),(num: number, digit = 2): number
  • meter2ToFt2: 平方米(m²)转平方英尺(ft²),(num: number, digit = 2): number
  • ft2ToMeter2: 平方英尺(ft²)转平方米(m²),(num: number, digit = 2): number
  • celsiusToFahrenheit: 摄氏度(°C)转华氏度(°F),(num: number, digit = 0): number
  • fahrenheitToCelsius: 华氏度(°F)转摄氏度(°C),(num: number, digit = 0): number
  • numberToChinese:数字转大写金额,(num: any): string
Date
  • moment:时间格式化,(...args: any[]): Moment
  • localToUtc: 本地转 UTC 时间
  • utcToLocal: UTC 转本地时间
  • offsetDay:获取偏移天,(date: any, num: number): Moment
  • offsetMonth:获取偏移月,(date: any, num: number, boundary: "startOf" | "endOf" | undefined): Moment
  • beforeDay: 是否今天(日期)之前,(date: any, target: any, isSame: boolean ): boolean
  • afterDay: 是否今天(日期)之后,(date: any, target: any, isSame: boolean): boolean
  • betweenDay:是否日期在区间内,(date: any, start: any, end: any, boundary: "()" | "[)" | "(]" | "[]" | undefined):boolean
Validate
  • isObject: 是否为对象,(arg: any): boolean
  • isArray: 是否为数组,(arg: any): boolean
  • isRegExp: 是否为正则,(regex: any): boolean
  • isFunction: 是否为函数,(arg: any): boolean
  • isBoolean: 是否为布尔值,(arg: any): boolean
  • isNumber: 是否为数字,(arg: any): boolean
  • isInt:是否为整数,(arg: any): boolean
  • isString: 是否为字符串,(arg: any): boolean
  • isNumberString: 是否为数字字符串,(arg: any): boolean
  • isNullOrUndefined: 是否为 null 或 undefined,(arg: any): boolean
  • isUndefined: 是否为 undefined,(arg: any): boolean
  • isNull: 是否为 null,(arg: any): boolean
  • isDate: 是否为日期(?:YYYY-MM-DD HH:mm:ss),isDate(arg: any, format?: string): boolean
  • isTrueEmpty: 是否为空,(undefined/null/''/NaN),(arg: any): boolean
  • isEmpty: 是否为空,(isTrueEmpty/[]/{}/0/false),(arg: any): boolean
  • isChinese: 是否包含中文,(arg: any): boolean
  • isMobile:是否为手机号,(arg: string): boolean
  • isEmail:是否为邮箱地址,(arg: any): boolean
  • isBank:是否为银行卡号,(arg: any): boolean
  • isVersion: 是否为版本号(X.Y.Z),(arg: any): boolean
  • isAccount: 是否为账号(字母/数字/下划线/-),(arg: any, min = 5, max = 16): boolean
  • isPwd:是否为密码(字母/数字/特殊符,任意 2 种),(arg: any, min = 8, max = 16): boolean
Window
  • loadScript: 异步加载 script 脚本,(src: string): Promise
  • getQueryObject 获取 url 参数,(url: string): Record<string, unknown>

Keywords

FAQs

Package last updated on 02 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc