Commonly used js tool functions
我将工做中经常使用的一些js函数封装成了npm package,若是使用的话,能够直接npm i yh-js-kit --save。
项目采用的是rollup打包,输出的format有umd和esm使用很方便。
复制代码
git: github.com/Michaelhooo…android
npm i yh-js-kit --save
复制代码
import { timeFormat, setCookie } from 'yh-js-kit'
const obj = require('yh-js-kit')
复制代码
let newArray = steamroller([1,2,[4,5,[1,23]]])
console.log(newArray) //[1, 2, 4, 5, 1, 23]
复制代码
let ary = [{name:1},{name:12},{name:10}]
ary.sort(arraySortByKey('name'))
console.log(ary) // [ { name: 1 }, { name: 10 }, { name: 12 } ]
复制代码
let demo = formatThousand(1234567)
console.log(demo) //1,234,567
复制代码
let array = [
{ name: "yu", artist: "air" },
{ name: "yu", artist: "air" },
{ name: "qing", artist: "zhou" },
{ name: "qing", artist: "zhou" },
];
unique(array, 'name')
//[ { name: 'yu', artist: 'air' }, { artist: 'zhou', name: 'qing' } ]
复制代码
console.log(getEndTime('2020/8/8 8:0:0'))
//返回倒计时,距离2020/8/8 8:0:0还剩多久
//{ day: 467, hour: 14, minutes: 35, seconds: 49 }
复制代码
let ary = [{name: 1},{name: 2}]
let ary2 = deepCopy(ary)
console.log(ary2)
// [{name: 1},{name: 2}]
let ary3 = deepCopy(ary, {name: 3})
console.log(ary3)
// [{name: 3},{name: 3}]
复制代码
console.log(filterParams({a:0, b:1, c:"010", d:null, e:undefined,f:false}) )
// {b:1, c:"010"}
复制代码
// 1:首字母大写 / The first child is capitalized
// 2:首子母小写 / The first child is lowercase
// 3:大小写转换 / Case conversion
// 4:所有大写 / All caps
// 5:所有小写 / All lowercase
changeCase('Michael',1)
复制代码
moneyChange(168752632)
//"人民币壹亿陆仟捌佰柒拾伍万贰仟陆佰叁拾贰元整"
moneyChange(1682)
//"人民币壹仟陆佰捌拾贰元整"
moneyChange(-1693)
//"欠人民币壹仟陆佰玖拾叁元整"
复制代码
/** * * Get paged array * @param {*} total The total number of pages * @param {*} cur The current page 3 * @param {*} around 1 2 3 4 5 around = 2 * @returns */
console.log(getPagedArray(10, 6 , 2))
//[ 1, '...', 4, 5, 6, 7, 8, 9, 10 ]
复制代码
/** * * * @param {*} {time, format = 'yyyy-MM-dd HH:mm'} * @returns */
let time = new Date()
console.log(timeFormat(time, 'yyyy-MM-dd HH:mm'))
//2019-04-28 17:34
复制代码
git: github.com/Michaelhooo…git