simple-d
TypeScript icon, indicating that this package has built-in type declarations

1.0.29 • Public • Published

Simple Data

主要是集合的处理,收集一些以及工作中用到过,或者会用到的一些集合处理方法,不喜勿喷,励志做一个合格的小开发

let a = [ {"a":"aaaa", "b": "bbbbbbb", "c": "cccccccccccc", "d": "dddddddddd", e: "test", f: "1ee", num: 12, num1: -45}, {"a":"wer", "b": "11313", "c": "s3fdd", "d": "041", e: "e", f: "f",num: 3, num1: -60}, {"a":"aa", "b": "bb", "c": "cc", "d": "dd", num: 100, num1: 2}, {"a":"aa1", "b1": "bb1", "c1": "cc1", "d1": "dd1", num: 100, num1: 21}, {"a":"a112", "b": "b11", "c": "c00", "d": "dkc", e: "test", f: "test1",num: -100, num1: 1}, {"a":"aa", "b": "bb", "c": "000", "d00": "7800", e: "e", f: "0f0",num: -10, num1: 10}, {"a":"aa", "b": "bb", "c": "asd", "d": "dd", e: "eyt", f: "0f0",num: -17, num1: 11}, {"a":"f", "b": "u", "c": "c", "d": "k", e: "!", f: "!!",num: 5, num1: 5} ];

let b = [2,"ad", undefined,null,"2", 2, 4, 5, "e12", 1, 3, 3, 2, "sdf", "12",null, undefined,"fuck", "fuckup", "sdf"]

let b_1 = [100,"qwe", "as","sd",-911, 2, "12ds","sd","fd","ds","as","sd","dx1","100t","50g","128g","256g","100t","100","1001","1022"]

let b_2 = [12,343,44,33,-132,0,-1,31,3,4,65,-9,0,3,11,1,2]

let b_3 = ['12', '3430', '44', 33, '-132', 0, -1, 31, 3, '4', 65, -9, 0, '3', 11, '1', '2', 0, undefined, false, null,NaN,'']

let c = [ {name:"dragon", win:3, lose:2, status: false}, {name:"jack", win:3.5, lose:1, status: false}, {name:"ben", win:1, lose:1.5, status: true}, {name:"skip", win:4, lose:0.5, status: false}, {name:"bobi", win:1.1, lose:1.6, status: true} ]

let d = [ // { // title: "dragon", num: 440, children: [{money: "25000", time: 12},{money: "25000", time: 13},{money: "25000", time: 6}] // }, // { // title: "jack", num: 227, children: [{money: "35000", time: 48},{money: "25000", time: 24},{money: "25000", time: 36}] // }, // { // title: "ben", num: 428, children: [{money: "30000", time: 31},{money: "30000", time: 22},{money: "25000", time: 100000}] // }, { title: "skip", num: 428, children: [ {base: "2019", angele: true, child: [ {time: 324}, {time: 100}, {time: 475} ]} ] }, { title: "duck", num: 338, children: [ {base: "2017", angele: true, child: [ {time: 3424}, {time: 70}, {time: 71} ]} ] } ]

data_item_array

data_item_number

数组里的元素为 number 元素

最大值 getMax: true

最小值 getMin: true

simpArr_Num(b_3, {getMax: true, getMin: true});

data_item_string

数组里的元素为 string 元素

去重 repeat:true

得到集合每个元素出现的次数 same: true ,100 和 "100" 视为同一个

simpArr_Str(b_1, {same: true, repeat:true});

data_item_object

数组里的元素为 object 元素

为每个item添加索引:key:true (渲染列表时有时需要key=index)

filterObj: {[key]:[value]} 筛选得到,对应所出现的item阵列:{e: [{……},{……}], f: …… ……, filterIndex;[]} ,filterResult为出现的索引集合

sortKey:[arg1, arg2] 排序默认取arg1的值排序,相同值的话则取arg2的值排序

direction: "asc" | "desc" 排序字段是升序还是降序,一定要配合sortKey使用, 因为要匹配 sortKey:[] 里的key

repeatKeys: ["a", "b","f"] 以repeatKeys里的元素为key取得每条item对应key的value值,拼接在一起,查看是否有相同的 repeatKeysResult["res"]为最终不重复的集合,repeatKeysResult["repeat"]为筛选出重复的item

max:["num"]: 得到数组里[num]对应key的最大值的那条item

min:["num"]: 得到数组里[num]对应key的最小值的那条item

keyVlaue:{key:"title", value:"time", child:["children", "child"]} key对应最终返回的对象那个Key,value对应的是你所要取的值那个Key, child对应你所要遍历几层才能拿到value

selectAmountKey: [key, key] key是数组单个元素里对应的key , 最终计算出数组元素以key的值为参考,得到[value]出现的次数

simpArr_Obj(a, {
    key:true, 
    filterObj:{e: "test",f: "0f0"}, 
    sortKey:["num", "num1"],
    direction: "asc",   //升序和降序 Ascending Descending
    repeatKeys: ["a", "b","f"],
    max:["num"], 
    min:["num"] 
})
simpArr_Obj(d, {
    keyVlaue: {key: "title", value: "time", child: ["children", "child"]}
})

SetArray()

不断往数组里unshift最新的元素,并且不能有重复的,不能超过设定长度

setArray.spliceItem(33, 4):预想阵列length为4,传入第一个数为33,后续继续调用方法传入,每次传入unshift到阵列的第0个,如果下次传入的值在之前的阵列里存在,就把之前那个旧值删掉,新值依旧unshift在第0个,之后查看最新的阵列是否大于length为4,如果大于则切掉后面多余的

setArray.spliceItem(obj, key, length):预想阵列长度lengthobj为预想插入的itemObj, key为预想用来判断的[key]:[value]

const setArray = new SetArray();

const { spliceItem, spliceObjItem } = setArray;

SetBroad()

广播效果,排序,以及类似主播开和关的socket推送

sortObjItem(c, "status"): 上面定义的c数组,以"status"为key排序,筛选出true或false的值

subscribeMes(msg, "status", "name"): 接收一条msgObj, 通过"status", "name"为key的对应的值,来改变原数组对应namestatus值,类似于主播开播和关播的推送状态到前端

const setBroad = new SetBroad();

const {sortObjItem, subscribeMes, resSort: {active, other, result}} = SetBroad();

var msg = {name:"jack", status: true}

var msg1 = {name:"skip", status: true}

var msg2 = {name:"ben", status: false}

sortObjItem(c, "status") 需要先`sort`一遍

setBroad.subscribeMes(msg, "status", "name")
setBroad.subscribeMes(msg1, "status", "name")
setBroad.subscribeMes(msg2, "status", "name")

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.291latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.291
1.0.281
1.0.270
1.0.250
1.0.240
1.0.231
1.0.220
1.0.211
1.0.201
1.0.191
1.0.180
1.0.170
1.0.160
1.0.151
1.0.140
1.0.130
1.0.121
1.0.110
1.0.101
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i simple-d

Weekly Downloads

2

Version

1.0.29

License

ISC

Unpacked Size

380 kB

Total Files

31

Last publish

Collaborators

  • karso.he