0.4.6 • Published 5 years ago

js-expand-tool v0.4.6

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

js-expand-tool

js拓展工具库

目的:高效率完成前端业务代码

业务开发过程中,会经常用到String,Number,Array,Object,Function,Date扩展方法浏览器类型判断等常用函数,为避免不同项目多次复制粘贴的麻烦,这里统一封装,并发布到npm,以提高开发效率。如果你也有常用的代码,欢迎为本项目提交pr。

安装使用

  1. 直接下载dist目录下的index.js使用,支持UMD,CMD,AMD各模块化规范。
  2. 使用npm/yarn/cnpm安装。

浏览器:

<script src="./node_modules/js-expand-tool/dist/index.js"></script>
<!-- <script src="./dist/index.js"></script> -->
<script>
	let pwd = jst.mask('password:123456789',4);
	console.log('pwd:',pwd) // pwd: **************6789
</script>

npm:

$ npm i js-expand-tool

yarn:

$ yarn add js-expand-tool

cnpm:

$ cnpm i js-expand-tool

React、VueJS,小程序等javascript环境

// 完整引入
import jst from 'js-expand-tool'
let pwd = jst.mask('password:123456789',4);
console.log('pwd:',pwd) // pwd: **************6789

推荐使用方法

你真的不需要完整引入所有函数,所以只引入需要使用的方法即可。

import { mask } from 'js-expand-tool'
let pwd = mask('password:123456789',4);
console.log('pwd:',pwd) // pwd: **************6789

:package: API文档

Object

  • deepClone 深度克隆。
  • orderBy 返回按属性(props)和顺序(orders)排序的对象数组。
  • findPathByLeafId 根据 key 递归查找链带关系。

Array

  • uniqueBy 根据属性去重数组。
  • unique 普通数组去重。
  • flat 数组完全展开
  • range 创建一个长度length,值从start开始递增的数组,每次递增step
  • repeat 重复数组

    Date

  • formatTime 格式化时间。

  • formatHMS 将秒数转为 xx小时xx分钟xx秒 例如1h0m10s。

Function

  • throttle 函数节流(首次执行)。

String

  • mask 使用 * 遮蔽字符串。
  • camelCaseToUnderLine 驼峰写法转下划线写法
  • underlineToCamelCase 下划线写法转驼峰写法

Number

  • randomNum 返回指定范围内的随机整数。
  • round 将数字四舍五入到指定的小数位数。
  • sum 返回两个或两个以上数字/数字数组中元素之和。
  • sumBy 根据函数映射每个元素,然后返回数组的和。
  • toDecimalMark 将数字转化为千分位格式。

TypeOf

  • $isNull 判断类型Null
  • $isUndefined 判断类型Undefined
  • $isBoolean 判断类型Boolean
  • $isNumber 判断类型Number
  • $isString 判断类型String
  • $isSymbol 判断类型Symbol
  • $isObject 判断类型Object
  • $isRegExp 判断类型RegExp
  • $isArray 判断类型Array
  • $isFunction 判断类型Function

url

  • Url 根据对象 拼接参数
  • URLSearchParams url 序列化和反序列化

prototype

  • match_all 扩展 String的原型方法 es2019的matchAll(未兼容浏览器)
0.4.6

5 years ago

0.4.5

5 years ago

0.3.3

5 years ago

0.1.21

5 years ago

0.1.20

5 years ago

0.1.19

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago