arst
v1.2.5
Published
这是一个处理字符串,数组,对象的库,如:去重,排序,替换等等
Downloads
1
Readme
介绍
这是一个处理字符串,数组,对象的库,如:去重,排序,替换等等
安装使用
//源码
https://gitee.com/cheng-yunfen/arst
//下载
npm i arst
// 引入使用
import As from 'arst'
const as = new As()
dupRem:数组对象去重
import As from 'arst'
const as = new As()
let arr = [{id:1},{id:2},{id:1}]
const arr1 = as.dupRem(arr)
console.log(arr1)//[{id:1},{id:2}]
arrDupRem:普通数组去重
import As from 'arst'
const as = new As()
const arr = [1,2,3,1,2,3]
const arr1 = as.arrDupRem(arr1)
console.log(arr1)//[1,2,3]
arrObj:遍历指定多维数组对象
import As from 'arst'
const as = new As()
const arr = [{id:1,name:jack},[{id:1,name:'mac'}]]
const arr1 = as.arrObj(arr)
console.log(arr1)//[{name:'jack'},{name:mac}]
mulArrDupRem:多维数组去扁平化
import As from 'arst'
const as = new As()
const arr = [1,2,[3,4,[5,6]]]
const arr1 = as.mulArrDupRem(arr)
console.log(arr1)//[1,2,3,4,5,6]
strRemSpace:清除字符串里面的空格,如果只是左右有空格可以直接用trim
import As from 'arst'
const as = new As()
const str = ' 5 6 '
const str1 = as.strRemSpace(str)
console.log(str1) // 56
strNumber:选出字符串中的数字bl传入布尔值true则为找出字母,false则为数字 默认为false
import As from 'arst'
const as = new As()
const str = 'asd56fas56fas5'
const str1 = as.strNumber(str)
console.log(str1) // 56565
const str2 = as.strNumber(str,true)
console.log(str2) // asdfasfas
strIn:指定替换字符
import As from 'arst'
const as = new As()
const str = '1563'
const str1 = as.strIn(str,5,'a')
console.log(str1) // 1a63
throtStab: 节流和防抖fn调用的方法,day延迟多久
<input type="text">
import As from 'arst'
const as = new As()
let input = document.querySelector('input')
input.oninput = as.throtStab(function(){
console.log(this.value) //input里面的值 onscroll事件也可以一起用注意这里要用普通函数用箭头函数this会指向window
},500)
objRecursive: 找出对象最里面的每一个子孩子obj对象,返回的是一个数组
import As from 'arst'
const as = new As()
let obj = {
a:'1',
b:{
a:'2',
b:{
a:'3',
id:88
}
}
}
console.log(as.objRecursive(obj,'b')); //[ { a:'1' } , {a:'2' },{ a:'3',id:88}]
arrSorting:数组对象根据指定排序数字为从小到大,汉字字母则是a,b,c,英文同汉字一起 则汉字在前 英文在后
import As from 'arst'
const as = new As()
const data = [
{ id: 1, name: '张三', age: 15 },
{ id: 1, name: '奥张三', age: 15 },
{ id: 2, name: 'John', age: 18 },
{ id: 3, name: '李四', age: 18 },
{ id: 4, name: 'Jack', age: 18 },
{ id: 5, name: '王五', age: 10},
];
const arr = as.arrSorting(data,'name')
console.log(arr) //[{id: 1, name: '奥张三', age: 15},{ id: 3, name: '李四', age: 18 },{ id: 5, name: '王五', age: 10}, { id: 1, name: '张三', age: 15 },{ id: 2, name: 'John', age: 18 },{ id: 4, name: 'Jack', age: 18 }]
const arr1 = as.arrSorting(data,'id')
console.log(arr1) // [{id:1..},{id:1..},{id:2..}..]同上