New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

genit

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

genit

Generator based utility belt

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 17 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc