1.0.30 • Published 3 years ago
barbie v1.0.30
barbie
barbie is an easily useful javascript utils library for your daily usage, which will work only in ES6+ and typescript environment
Installation
Using npm
$ npm i barbie --save
In node.js (es6+ && ts)
import barbie from 'barbie'
Usage
1 stampTimeFormat
let time = barbie.stampTimeFormat(1578965868,true,'-'); // 1970-01-01 08:00:00
let time1 = barbie.stampTimeFormat(1578965868,false,'-'); // 1970-01-01 08:00
let time2 = barbie.stampTimeFormat(1578965868,'-'); // 1970-01-01 08:00
let time3 = barbie.stampTimeFormat(1578965868); // 1970/01/01 08:00
let time4 = barbie.stampTimeFormat(1578965868,true); // 1970/01/01 08:00:00
2 numberFormat
let str = barbie.numberFormat(12345657); // '1,234,567'
let str1 = barbie.numberFormat(12345657.90); // '1,234,567.90'
3 emptyStringReplace
let str = barbie.emptyStringReplace('hello','/'); // 'hello'
let str2 = barbie.emptyStringReplace(' ','/'); // '/'
let str3 = barbie.emptyStringReplace(' '); // '/'
let str4 = barbie.emptyStringReplace(false); // '/'
let str5 = barbie.emptyStringReplace(0); // '/'
let str6 = barbie.emptyStringReplace(null); // '/'
let str7 = barbie.emptyStringReplace(undifined); // '/'
4 listEmptyStringReplace
let objlist = [
{
id:0,
name:'',
age:20
},
{
id:1,
name:'jack',
age:30
},
{
id:2,
name:'bob',
age:35
},
];
let arr = barbie.listEmptyStringReplace(objlist,'/');
// [
{
id:0,
name:'/',
age:20
},
{
id:1,
name:'jack',
age:30
},
{
id:2,
name:'bob',
age:35
},
];
5 cleanString
let str = barbie.cleanString(' a\rb\nc '); // 'abc'
6 stringToFixed
let str = barbie.stringToFixed('abcdefghigk',3); // 'abc...'
7 uniqueObjArr
let objlist = [
{
id:0,
name:'jack',
age:20
},
{
id:1,
name:'jack',
age:30
},
{
id:2,
name:'bob',
age:35
},
];
let objArr1 = barbie.uniqueObjArr(objlist,'name');
// [
{
id:0,
name:'jack',
age:20
},
{
id:2,
name:'bob',
age:35
},
]
8 uniqueArr
let arr = barbie.uniqueArr([1,2,3,4,5,3,5]); // [1,2,3,4,5]
9 removeArrayItem
let arr = barbie.removeArrayItem([1,2,3,4,5,3,5],3) // [1,2,4,5,3,5]
let arr1 = barbie.removeArrayItem(['hello','hi','hey'],'hello') // ['hi','hey']
let objlist = [
{
id:0,
name:'jack',
age:20
},
{
id:1,
name:'jack',
age:30
},
{
id:2,
name:'bob',
age:35
},
];
let arr2 = barbie.removeArrayItem(objlist,objlist[0])
let arr3 = barbie.removeArrayItem(objlist,{id:0, name:'jack',age:20});
// [
{
id:1,
name:'jack',
age:30
},
{
id:2,
name:'bob',
age:35
},
];
10 getRandom
let num = barbie.getRandom(); // 9
let num1 = barbie.getRandom(5,100); // 23
11 getTimeStamp
let stamp = barbie.getTimeStamp(true); // 1578965868345
let stamp1 = barbie.getTimeStamp(); // 1578965868
12 findCommonInList
let flag = barbie.findCommonInList([1,3,4,6]); // false
let flag1 = barbie.findCommonInList([1,3,,3,4,6]); // true
let objlist = [
{
id:0,
name:'jack',
age:20
},
{
id:1,
name:'jack',
age:30
},
{
id:2,
name:'bob',
age:35
},
];
let flag2 = barbie.findCommonInList(objlist,'name'); // true
13 getValOfCss
let height = barbie.getValOfCss(35); // 35px
let height2 = barbie.getValOfCss('35px'); // 35px
let height3 = barbie.getValOfCss('35%'); // 35%
14 downLoad
barbie.downLoad('http://www.filename.com/abc.xls'); // downLoad A abc.xls file
15 formData
let data = {
name:'jack',
id:1
};
let formData = barbie.formData(data);
16 getUrlQuery
let str = 'pages/index/index.html?name=jack&age=28';
let query = barbie.getUrlQuery(str);
// query = {
name : 'jack',
age : '28'
}
17 excelMaker
barbie.excelMaker({
columns : [
{header:'Name',key:'name',width:10},
{header:'Age',key:'age',width:20},
{header:'Sex',key:'sex',width:20},
{header:'Position',key:'position',width:20}
],
data : [{
name : 'jack',
age : 30,
sex : 'M',
position : 'manager'
}],
name : 'workSheet'
});
18 clickCopy
const val = 'I am the king of the world!';
const flag = barbie.clickCopy(val);
if(flag){
alert('copied!');
}
19 checkNet
const flag = barbie.checkNet(); // true | false
20 showArrDuplicateItem
let arr = barbie.showArrDuplicateItem([1,1,2,2,4,5,2,1,4,6,3]); // [1,2,4]
let arr1 = barbie.showArrDuplicateItem(['1','2','1','2','3']); // ['1','2']
let arr2 = barbie.showArrDuplicateItem([{count:1},{count:1}]); // [{count:1}]
21 numAccurate
let num = barbie.numAccurate((0.01+0.02),2); // 0.03
22 resetPageZoom
barbie.resetPageZoom();
23 deepCopy
const obj = barbie.deepCopy({name:'jack'}); // {name:'jack'}
24 percentInt
const int = barbie.percentInt(20,100); // 50
25 accurateNum
const num = barbie.acurateNum((0.1+0.2),2); // 0.30
26 utcTimeFormat
let time = barbie.utcTimeFormat('2020-06-09T03:25:03.961Z',true,'-'); // 2020-06-09 03:25:03
let time1 = barbie.utcTimeFormat('2020-06-09T03:25:03.961Z',false,'-'); // 2020-06-09 03:25
let time2 = barbie.utcTimeFormat('2020-06-09T03:25:03.961Z','-'); // 2020-06-09 03:25
let time3 = barbie.utcTimeFormat('2020-06-09T03:25:03.961Z'); // 2020/06/09 03:25
let time4 = barbie.utcTimeFormat('2020-06-09T03:25:03.961Z',true); // 2020/06/09 03:25:03
27 excelJson
const obj = barbie.excelJson(file); // file must be *.xlsx file
28 cameCase
const str = barbie.cameCase('came-case'); // CameCase
29 maxInArr
const num = barbie.maxInArr([1,2,3]); // 3
30 minInArr
const num = barbie.minInArr([1,2,3]); // 1
31 upperCaseFirstLetter
const str = barbie.upperCaseFirstLetter('hello, my name is jack!'); // Hello, My Name Is Jack!
32 longestStr
const str = barbie.longestStr('hello, my name is jack!'); // Hello,
33 fibonacciSequence
const arr = barbie.fibonacciSequence(10); // [0,1,1,2,3,5,8]
34 factorial
const num = barbie.factorial(3); // 6
35 primeNums
const arr = barbie.primeNums(0,10); // [2,3,5,7]
36 hashCode
const str = barbie.hashCode(10); // h2j3skf3j4
37 isSameStyleStr
const val = barbie.isSameStyleStr('bbb','aaa'); // true
38 arrayCheck
const val = barbie.arrayCheck([123,345]); // true
const val1 = barbie.arrayCheck([]); // false
const val2 = barbie.arrayCheck(234); // false
39 isHasChildren
const val = barbie.isHasChildren([{
name:'jack',
children:[
{name:'bob'}
]
}]); // true
40 getChineseNumber
const str = getChineseNumber(2421203261835, false);
// 两兆四千两百一十二亿〇三百二十六万一千八百三十五
const str1 = getChineseNumber(2421203261835);
// 两兆四千两百一十二亿〇三百二十六万一千八百三十五
const str2 = getChineseNumber(2421203261835,true);
// 俩兆肆仟俩佰壹拾貳億零叁佰貳拾陸萬壹仟捌佰叁拾伍
1.0.30
3 years ago
1.0.29
3 years ago
1.0.28
4 years ago
1.0.27
4 years ago
1.0.26
4 years ago
1.0.25
4 years ago
1.0.24
4 years ago
1.0.23
4 years ago
1.0.22
4 years ago
1.0.21
4 years ago
1.0.20
4 years ago
1.0.19
4 years ago
1.0.17
4 years ago
1.0.16
4 years ago
1.0.15
4 years ago
1.0.14
4 years ago
1.0.13
4 years ago
1.0.11
4 years ago
1.0.12
4 years ago
1.0.10
4 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago