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

genit

v1.0.3

Published

Generator based utility belt

Downloads

11

Readme

genit

Generator based utility belt

Build Status npm Dependencies Join the chat at https://gitter.im/fleekjs/genit

$ npm install genit

Key

Usage

Direct

  'use strict'

  let genit  = require('genit');
  let fooFunc = function *(someSet) {
     return yield genit.map(someSet, function *(value, index) {
      return yield someGeneratorFunction('foo', 'bar', value);  
    });
  }

Module Extension

  'use strict'

  let _       = require('lodash');
  let genit  = require('genit');

  genit.inject(_);

  _.each(someSet, function () {  }); //existing
  _.isGenerator(mightBeAGenerator) // injected
   function *() {
    return yield _.genit.map(someSet, function *(value, index) {   }); // injected to .genit property (name collision)
  }

Utilities

Synchronous

Mixed Synchronous

each

  • Parameters
    • [Required] [Mixed] - Collection to operate on,
    • [Required] [Generator Function] - Operation to perform
  • Functionality
    • Iterates over every item in the collection (objec tor array)
    • Executes the operation on each item
  • Returns
    • Undefined
yield genit.each([one, two, three], function *(value, index) {
  console.log(index + ' = ' + this + ' ~ ' + value);
});
// console:
// 1 = one ~ one
// 2 = two ~ two
// 3 = three ~ three

yield genit.each({ one:'foo', two:'bar', three:'biz'  }, function *(value, key) {
  console.log(key + ' = ' + this + ' ~ ' + value);
});
// console:
// one = foo ~ foo
// two = bar ~ bar
// three = biz ~ biz

map

  • Parameters
    • [Required] [Mixed] - Collection to operate on,
    • [Required] [Generator Function] - Operation to perform
  • Functionality
    • Iterates over every item in the collection (objec tor array)
    • Executes the operation on each item
    • Returned value is added to the resulting array
  • Returns
    • Array of values returned
let result = yield genit.each(['one', 'two', 'three'], function *(value, index) {
  console.log(index + ' = ' + this + ' ~ ' + value);
  return index * 2;
});
// console:
// 1 = one ~ one
// 2 = two ~ two
// 3 = three ~ three
console.log(result);
// console:
// [0, 1, 2]

let result = yield genit.each({ one:'foo', two:'bar', three:'biz'  }, function *(value, key) {
  console.log(key + ' = ' + this + ' ~ ' + value);
  return value;
});
// console:
// one = foo ~ foo
// two = bar ~ bar
// three = biz ~ biz
console.log(result);
// console:
// ['foo', 'bar', 'biz']

filter

  • Parameters
    • [Required] [Mixed] - Collection to operate on,
    • [Required] [Generator Function] - Operation to perform
  • Functionality
    • Iterates over every item in the collection (object or array)
    • Reserve only the item that passed the checking condition
    • Returned value is added to the resulting array or object
  • Returns
    • Array or object values returned
let result = yield genit.filter([-1, -2, -3, 4, 5], function *(value) {
  return value > 0;
});
console.log(result);
// console:
// [4,5]

let result = yield genit.filter({ one:'foo', two:'bar', three:'biz'  }, function *(value, key) {
  return value == "biz" || value == "bar";
});
console.log(result);
// console:
// {two : 'bar', three: 'biz'}

Asynchronous

Coming Soon

Miscellaneous

isGenerator

  • Parameters
    • [Required] [Mixed] - object to type check
  • Functionality
    • Test whether or not a function is a generator
  • Returns
    • Boolean of generator status
let result = yield genit.isGenerator(function () {});
console.log(result); // => false

let result = yield genit.isGenerator(function *() {});
console.log(result); // => true

inject

  • Parameters
    • [Required] [Object] - object to inject properties to
  • Functionality
    • Inject properties into target Object
    • Collision in property name move genit property to the .genit property
  • Returns
    • target object with injected properties
'use strict'

  let test   = { each : function () { return 'Original Each';  }  };
  let genit = require('genit');

  genit.inject(test);

  console.log(test.each()); // => "Original Each"
  console.log(test.isGenerator(function () {})) // => "false"
  console.log(test.isGenerator(test.genit.each)) // => "true"

Authors

  • John Hofrichter
  • Contributor Lan Nguyen