npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yangmin412/data-list

v0.9.92

Published

handle array like stream in java

Downloads

7

Readme

collect tools for nodejs

DataList like java arraylist

  • warp array methods and use like stream in java
  • most of method are used like the same method in array, and it return a new DataList

usage

stream-like method: always return a new DataList wrapping a new array

import {datalist, DataList} from "./DataList";

const users = [{userId: "1", userAge: 18}, {userId: "2", userAge: 28}]
const orders = [{orderId: "1", userId: "1"}]


// instance DataList with array
let userDataList = new DataList(users)
let orderDataList = datalist(orders)

// filter element in datalist and return an new DataList with the elements 
// like  users.filter(user => user.userId === "2")
//and return DataList with array [{userId: 1, userAge: 18 }]
userDataList.filter(user => user.userId === 2)

// the same logic with such method below

userDataList.concat(userDataList)
userDataList.slice(0, 1)


userDataList.reverse()
userDataList.map(user => user.userAge)
userDataList.unshift(userDataList)
userDataList.reduce((sum, user) => sum + user.userAge, 0)
userDataList.reduceRight((sum, user) => sum + user.userAge, 0)
userDataList.every(user => user.age > 18)
userDataList.some(user => user.age > 18)
userDataList.forEach(user => user.age++)

// join DataList like sql join
// [{userId:"1",orderId:"1",userAge:18}]
useDataList.join(orderDataList,
    (user, order) => user.userId === order.userId,
    (user, order) => ({...user, ...order}))
// join DataList like sql join
// [{userId:"1",userAge:18,orderList:[{orderId:"1",userId:"1"}]}]
useDataList.leftJoin(orderDataList,
    (user, order) => user.userId === order.userId,
    "userOrderList")

// [{userId:"1",userAge:18,orderList:[{orderId:"1",userId:"1"}]}]
orderDataList.rightJoin(useDataList,
    (order, user) => user.userId === order.userId,
    "userOrderList")

// [1,2,3,4]
dataList([[1, 2], [3, 4]]).flatMap(item => item)

userDataList.distinct(user => user.userId)
/**
 * the methods below  won't change the array in origin DataList but return an new DataList warp an new array
 * which are different from array
 */
userDataList.sort((user1, user2) => user1.userAge - user2.userAge)

// splice is much a bit of more different,
// when the second is negative, it means back from the end of array
// when the second is positive, it means delete count after start index
userDataList.splice(1, -1)

calculate methods


/*
 * return the first element and index in DataList which satisfy the condition
 {
    item: {userId: "1", userAge: 18},
    index:0
 }
 */
userDataList.firstOf(user => user.age == 18)
userDataList.lastOf(user => user.age == 18)


// {value:28,items:[{userId:1,age:18}]}
userDataList.min(user => user.userAge)
// {value:28,items:[{userId:2,age:28}]}
userDataList.max(user => user.userAge)

userDataList.size()
userDataList.isEmpty()
userDataList.toArray()
userDataList.toString()
userDataList.getItem(1)
userDataList.getLastItem()

userDataList.toMap(user => user.userId)
userDataList.groupBy(user => user.userAge)
userDataList.toGroupMap(user => user.userAge, user => user)
userDataList.groupReduceMap(user => user.userAge, (pre, cur, list) => pre + cur.userAge, 0)