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

async-simple-iterator

v0.1.5

Published

Making simple iterator for [async][] lib that adds beforeEach, afterEach, error hooks and support for settling. It also emits `beforeEach`, `afterEach` and `error` events.

Downloads

9

Readme

async-simple-iterator npmjs.com The MIT License

Making simple iterator for async lib that adds beforeEach, afterEach, error hooks and support for settling. It also emits beforeEach, afterEach and error events.

code climate standard code style travis build status coverage status dependency status

Install

npm i async-simple-iterator --save

Usage

For more use-cases see the tests

var base = require('async-simple-iterator')
// or get constructor
var AsyncSimpleIterator = require('async-simple-iterator').AsyncSimpleIterator

API

AsyncSimpleIterator

Initialize AsyncSimpleIterator with options.

Params

  • options {Object=}: Pass beforeEach, afterEach and error hooks or settle:true.

Example

var ctrl = require('async')
var AsyncSimpleIterator = require('async-simple-iterator').AsyncSimpleIterator

var fs = require('fs')
var base = new AsyncSimpleIterator({
  settle: true,
  beforeEach: function (val) {
    console.log('before each:', val)
  },
  error: function (err, res, val) {
    console.log('on error:', val)
  }
})
var iterator = base.wrapIterator(fs.stat, {
  afterEach: function (err, res, val) {
    console.log('after each:', val)
  }
})

ctrl.map([
  'path/to/existing/file.js',
  'filepath/not/exist',
  'path/to/file'
], iterator, function (err, results) {
  // => `err` will always be null, if `settle:true`
  // => `results` is now an array of stats for each file
})

.wrapIterator

Wraps iterator function which then can be passed to async lib. You can pass returned iterator function to every async method that you want.

Params

  • iterator {Function}: Iterator to pass to async lib.
  • options {Object=}: Pass beforeEach, afterEach and error hooks or settle option.
  • returns {Function}: Wrapped iterator function which can be passed to every async method.

Events

  • emits: beforeEach with signature val[, value], next
  • emits: afterEach with signature err, res, val[, value], next
  • emits: error with signature err, res, val[, value], next

Example

var ctrl = require('async')
var base = require('async-simple-iterator')

base
  .on('afterEach', function (err, res, value, key, next) {
    console.log('after each:', err, res, value, key)
  })
  .on('error', function (err, res, value, key, next) {
    console.log('on error:', err, res, value, key)
  })

var iterator = base.wrapIterator(function (value, key, next) {
  console.log('actual:', value, key)

  if (key === 'dev') {
     var err = new Error('err:' + key)
     err.value = value
     next(err)
     return
   }
   next(null, 123 + key + 456)

}, {
  settle: true,
  beforeEach: function (value, key, next) {
    console.log('before each:', value, key)
  }
})

ctrl.forEachOf({
  dev: './dev.json',
  test: './test.json',
  prod: './prod.json'
}, iterator, function done (err) {
  // if settle:false, `err`
  // if settle:true, `null`
  console.log('end:', err)
})

Related

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github