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

@osmium/iterate

v0.2.2

Published

Osmium project - Universal iterator

Downloads

10

Readme

@osmium/iterate

About

Installation

Just use command:

 npm i --save @osmium/iterate

And import iterator function what you need (see API), for example universal sync/async value-key iterator:

{iterate} from '@osmium/iterate'

Usage

Iteration

Can iterate this types (async versions/modes also support Promise of them)

  • Array
  • object
  • Iterableobject with keys [Symbol.iterator] / [Symbol.asyncIterator]
  • Set
  • Map
  • string - iterate each char in string
  • number - certain number of times
  • true - until inter.break() called

Async

Support only native ES Promises

IMPORTANT NOTICE!

Be carefull with code compilers like Babel - such things often turn asynchronous functions into synchronous, without the ability to determine their type in run-time through constructor.name='AsyncFunction'or a rather specific code pattern from compiled function source text

Mapping

  • Array
  • Object
  • Set
  • Map
  • number - count not undefined returns from iterator callback

Set boolean to true if iterator callback returned something other than undefined

Chunks

API

iterateSync

Reference: iterateSync(values: Iterable, cb: (value, idx, control: Control)=> mapRow|undefined, map?:Mappable, mapUndefined?:true): MapResult|undefined

Iterate values using synchronously callback, mapping result also synchronously.

iterateSync([1, 2, 3], (val, idx)=>{
    console.log(val, idx);    
});
// 1 0
// 2 1
// 3 2

iterateAsync

Reference: iterateAsync(values: Iterable, cb: async(value, idx, control: Control)=> Promise<mapRow|undefined>, map?:Mappable, mapUndefined?:true): Promise<MapResult|undefined>

Iterate values using asynchronously callback, mapping result also asynchronously.

await iterateSync([1, 2, 3], async(val, idx)=>{
    console.log(val, idx);    
});
// 1 0
// 2 1
// 3 2

iterate

Reference sync: iterate(values: Iterable, cb: (value, idx, control: Control)=> mapRow|undefined, map?:Mappable, mapUndefined?:true): MapResult|undefined

Reference async: iterate(values: Iterable, cb: async(value, idx, control: Control)=> Promise<mapRow|undefined>, map?:Mappable, mapUndefined?:true): Promise<MapResult|undefined>

Try to detect callback type - if callback sync - used iterateSync else used iterateAsync

iterateKeysSync

Reference: 1

Same as iterateSync, but arguments order in callback changed - (idx, value, control)

iterateKeysAsync

Reference: 1

Same as iterateAsync, but arguments order in callback changed - (idx, value, control)

iterateKeys

Reference: 1

Same as iterate, but arguments order in callback changed - (idx, value, control)

iterateParallel

Reference: 1

Same as iterateAsync, but сallbacks run in parallel like Promise.all.

iterateKeysParallel

Reference: 1

Same as iterateAsync, but сallbacks run in parallel like Promise.all. Arguments order in callback changed - (idx, value, control)

iterateKeysParallelLimit

Reference: 1

Same as iterateKeysParallel, but сallbacks run in parallel batches like Promise.all with limit.

iterateKeysChunk

Reference: 1