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

neupack

v1.1.0

Published

Module for alternative array methods and for mapping data as an array.

Downloads

3

Readme

NeuPack

Module for alternative array methods and for mapping data as an array. It makes it easier to iterate through objects. And fast and productive static array methods.

Table of Contents

  1. Install
  2. Usage

Install

npm i neupack 

Usage

Default:

// CJS require
const NeuPack = require('neupack')
// ESM import
import NeuPack from 'neupack'

const items = [
  { id: 'ID3', name: 'Name 1', rel: '1574' },
  { id: 'ID2', name: 'Name 2', rel: '1574' }
]
const pack = new NeuPack({
  input: items,
  id: 'id'
})

pack.includes('Name 1')
pack.filter(el => el.rel === '1574')
pack.edit('NM587', { rel: '2000' })
pack.delete('NM202')
pack.push({ id: 'NM456', name: 'NeuTest', rel: '2020' })

for (const el of pack) {
  // do something with el
}

const arr = await pack.all(async el => {
  // do something async with el
})

const arr = await pack.allSettled(async el => {
  // do something async with el
})

const arr = await pack.any(async el => {
  // do something async with el
})

const arr = pack.map(el => {
  // do something with el
})

const result = pack.some(el => {
  // do something with el
})

pack.each(el => {
  // do something with el
})

const packGenerator = pack.generator // get generator
packGenerator.next() // get next { value, done }

Static:

// CJS require
const NeuPack = require('neupack')
// ESM import
import NeuPack from 'neupack'

const items = [
  { id: 'ID3', name: 'Name 1', rel: '1574' },
  { id: 'ID2', name: 'Name 2', rel: '1574' }
]

NeuPack.each(items, (el, i) => {
  console.log(el)
})

const packMap = NeuPack.map(items, (el, i) => {
  return el
})

const packValuedMap = NeuPack.valuedMap(items, (el, i) => {
  return el || null
})

/**
 * Awaits for each callback to finish.
 * Similar to [ await Promise.all(items.map(asyncFn)) ]
 */
const packPack = await NeuPack.pack(items, async (el, i) => {
  return el
})

const packToObject = NeuPack.toObject(items, 'id')

/**
 * Runs callback on each element while in reverse and reverses the array back on return.
 */
const packReverseBack = NeuPack.reverseBack(items, (el, i) => {
  return el
})

Methods:

class NeuPack {
  constructor ({input = null, id }): NeuPack
  keys: Array<string>
  data: object
  id: string
  length: number
  lastIndex: number
  nextIndex: number

  get: (...args: string[]) => any
  push: (input: object) => NeuPack
  edit: (key: string, input: any) => NeuPack
  delete: (key: string) => NeuPack
  has: (key: string) => boolean
  find: (searchParam: object) => Array<object>
  values: () => Array<object>
  each: (callback:(value: any, key: string, index: number) => void) => NeuPack
  some: (callback:(value: any, key: string, index: number) => any) => any
  map: (callback:(value: any, key: string, index: number) => any) => Array<any>
  pack: (callback:(value: any, key: string, index: number) => Promise<any>) => Promise<any[]>
  all: (callback:(value: any, key: string, index: number) => Promise<any>) => Promise<any[]>
  allSettled: (callback:(value: any, key: string, index: number) => Promise<any>) => Promise<any[]>
  any: (callback:(value: any, key: string, index: number) => Promise<any>) => Promise<any[]>
  reduce: (callback:(container: any, value: any, key: string, index: number) => void, output: any) => any
  filter: (callback:(value: any, key: string, index: number) => any) => Array<any>
  range: (array:Array<any>, start: number, end: number) => Array<any>
  includes: (searchParam: object) => boolean

  static each: (array:Array<any>, callback:(element: any, index: number) => void) => Array<any>
  static valuedMap: (array:Array<any>, callback:(element: any, index: number) => any) => Array<any>
  static map: (array:Array<any>, callback:(element: any, index: number) => any) => Array<any>
  static pack: (array:Array<any>, callback:(element: any, index: number) => any) => Promise<any[]>
  static all: (array:Array<any>, callback:(element: any, index: number) => any) => Promise<any[]>
  static allSettled: (array:Array<any>, callback:(element: any, index: number) => any) => Promise<any[]>
  static any: (array:Array<any>, callback:(element: any, index: number) => any) => Promise<any[]>
  static reduce: (array:Array<any>, callback:(element: any, index: number) => void, output: any) => any
  static toObject: (array:Array<any>, key: string) => object
  static filter: (array:Array<any>, callback:(element: any, index: number) => any) => Array<any>
  static range: (array:Array<any>, start: number, end: number) => Array<any>
  static includes: (array:Array<any>, element: any) => boolean
  static reverse: (array:Array<any>, callback?:(element: any, index: number) => any) => Array<any>
  static reverseBack: (array:Array<any>, callback:(element: any, index: number) => any) => Array<any>
}