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

listag

v0.8.4

Published

List Manager for Array Operations & Query by Tag

Downloads

31

Readme

LISTAG

Linux Build Status npm version TypeScript definitions on DefinitelyTyped Greenkeeper badge

Listag

List Manager supports Array Operation & Query by Tags.

FEATURES

  1. Javascript Array like
    can be used like a normal array with [], length, forEach, map, reduce functions.
  2. Tags Associated with Each Item
    can be queried by tags, return a array with items that has the specified tags.
  3. Event Support
    listag will emit add and del event which can be listened on.
  4. TypeScript Support
    with Type Definition File included.

WHY LISTAG

When we have some of hash values, we put them into a array:

const List = [
  { name: 'tom', value: 1 }
  { name: 'bob', value: 2 }
  { name: 'bob', value: 3 }
]

If we want to get the value out whose name is 'tom', we have to use filter:

const filteredList = List.filter(v => {
  return v.name === 'tom'
})

Listag is a convinience way to do this, with more powerful enhancements.

const lt = new Listag()
lt.add(1, {
  name: 'tom'
})
lt.add([2, 3], {
  name: 'bob'
})

lt.get({
  name: 'bob'
})
.forEach(v => {
  console.log('value of name bob: %s', v)
})

EXAMPLE

Create listag

let lt = new Listtag(1, {
  color: 'blue'
})

let lt2 = new Listtag([2, 3], {
  color: 'green',
  owner: 'tom',
})

Add item(s) to a listag

lt.add(4, {
  color: 'red'
})
lt.add([5, 6], {
  color: 'yellow'
  , owner: 'mike'
})

Del item(s) from a listag

lt.del(4)

ltDel = lt.get({
  color: 'red'
})
lt.del(ltDel)

Get item(s) from a listag

let blueLt = lt.get({
  color: 'blue'
})
blueLt.forEach(i => {
  console.log('items with color blue: %s', i)
})

get can filter the result by exclude some tag value, by add a minus sign - before the value:

let notBlueLt = lt.get({
  color: '-blue'
})

Array Operation

console.log('lt length: %s', lt.length)
console.log('lt[0] = %s', lt[0])

lt.forEach(item => {
  console.log('item: %s', item)
})

lt.map(item => {
  return item * 2
})

lt.filter(item => {
  return item % 2
})

Event

lt.on('add', item => {
  console.log('add item: %s', item)
})

lt.on('del', item => {
  console.log('del item: %s', item)
})

Set Tags to a listag

lt.set({
  lang: 'js'
})

TEST

Unit Test can be found here:

https://github.com/huan/listag/blob/master/tests/

KNOWN ISSUES & SUPPORT

Github Issue - https://github.com/huan/listag/issues

  1. Listag can not be instanceof because it has been Proxy-ed

CHANGELOG

v0.8 master

  1. Upgrade TypeScript to the latest version
  2. DevOps with npm@next

v0.4 (9th Auth 2016)

  1. support create listag from listag, keep all tags information right
  2. add Listag.item() method to get a ListagItem from Listag, for read tag information

v0.2.3 (7th Aug 2016)

  1. add TypeScript Declaration File
  2. support to exclude a tag value by add minus sign(-) to value

v0.1.0 (22 Jul 2016)

  1. support array with tags powered by ES6 Proxy

TODO

  • [ ] support for ... in Listag
  • [ ] support for ... of Listag

AUTHOR

Zhuohuan LI [email protected] (http://linkedin.com/in/zixia)

COPYRIGHT & LICENSE

  • Code & Docs 2016-2018© zixia
  • Code released under the ISC license
  • Docs released under Creative Commons