yh-js-Kit
Commonly used js tool functions
我将工作中常用的一些js函数封装成了npm package,如果使用的话,可以直接npm i yh-js-kit --save。
项目采用的是rollup打包,输出的format有umd和esm使用很方便。
git: github.com/Michaelhooo…
npm i yh-js-kit --save
import { timeFormat, setCookie } from 'yh-js-kit'
const obj = require('yh-js-kit')
AboutCookie
- setCookie(name, value)
- getCookie(name)
- delCookie(name)
arrayFlattening
let newArray = steamroller([1,2,[4,5,[1,23]]])
console.log(newArray)
arraySortByKey
let ary = [{name:1},{name:12},{name:10}]
ary.sort(arraySortByKey('name'))
console.log(ary)
changeDigitalDisplay
let demo = formatThousand(1234567)
console.log(demo)
complexArraysToRepeat
- unique
Deduplication of complex arrays
let array = [
{ name: "yu", artist: "air" },
{ name: "yu", artist: "air" },
{ name: "qing", artist: "zhou" },
{ name: "qing", artist: "zhou" },
];
unique(array, 'name')
countdown
console.log(getEndTime('2020/8/8 8:0:0'))
deepCopy
let ary = [{name: 1},{name: 2}]
let ary2 = deepCopy(ary)
console.log(ary2)
let ary3 = deepCopy(ary, {name: 3})
console.log(ary3)
filterParams
- filterParams
When the value is 0,null,undefined, it gets filtered
console.log(filterParams({a:0, b:1, c:"010", d:null, e:undefined,f:false}) )
letterSize
changeCase('Michael',1)
moneyChange
moneyChange(168752632)
moneyChange(1682)
moneyChange(-1693)
pagingComponent
console.log(getPagedArray(10, 6 , 2))
timeFormat
let time = new Date()
console.log(timeFormat(time, 'yyyy-MM-dd HH:mm'))
uaJudgment
- browserInfo
type: android, iphone, ipad, weixin
return: Boolean
git: github.com/Michaelhooo…