Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

gennifer

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gennifer

Fake social data generator

Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
12
500%
Maintainers
1
Weekly downloads
 
Created
Source

Deps

  npm install

Usage & installation

As a module

  npm install gennifer --save

  var gennifer = require( 'gennifer' );
  var tweetTmpl = function() {
    return {
      user: '@recursivefunk',
      text: 'I am the one'
    };
  };

  gennifer
    .registerTemplate( 'tweet', tweetTmpl )

    // optional
    .channel( anEventEmitter )

    // will return the genrated data and automatically emit the new data
    .generate( 'tweet' );

Loading templates from a file


  // in templates.js

  // casual is the preferred underlying data generator but you can generate
  // data with your templates in any manner you wish
  var casual = require('casual');

  module.exports = {
    aTemplate: function() {
      return {
        dateFoo: casual.date,
        aName: casual.name
      }
    }
  }

  // later...
  gennifer.loadTemplates( './templates.js' );
  var templates = gennifer.templates();
  console.log( templates );
  // { aTemplate: [Function] }

As a standalone-socket server

  [sudo] npm install -g gennifer
  genneifer [ -f 1000 -v 1 -p 8080 -t ]

Just type

  genneifer -h

For available options

Streams

Gennifer supports the usage of highland streams. Gennifer will act as a generator which gets lazily evaluated at the user's request

  // generates and returns a stream with the specified template
  var fooStream = gennifer.stream( 'templateName' );

  // lazily pull an item from the stream - generator style
  fooStream.pull(function(err, items){
    // you know the deal
  });

  // a wrapper form highland's .write function. The second (optional) argument, numWrites
  // tells gennifer how many times to write a generated data item to the stream.
  // CAREFUL => numWrites does not affect volume. If you set gennifers volume
  // to 5 then tell the stream to write 5 times you will get 5 writes of 5 items.
  gennifer.writeStream( 'templateName', numWrites );

  // to fetch the written items dump the stream (which also destroys the stream)
  gennifer.dumpStream('templateName', function(items){
    // items is an array of newly generated template instances
  });

On Dates & Strings

There's no good way to distinguish between a string that's a number and a date string. For Instance '1' is a "valid date", but in the context of an application, probably is not actually representative of any point in time. To remedy this, you'd have to override the property to manually set the data type. See usage below:

  var obj = { foo: 'bar', created_at: 'Fri Oct 24 23:22:09 +0000 2008' };
  var decoded = genneifer.resolveTypes( obj, { created_at: 'Date' } );
  console.log( decoded ); // { foo: 'String', created_at: 'Date' }

When gennifer sees this property, she will use the overridden type. This obviously isn't the ideal situation as it forces you to at least know a bit about the data ahead of time, but such is the world in which we live.

Run Tests

You'll need to have redis running locally for all tests to pass

  npm test

To Do

Check the issues section

FAQs

Package last updated on 10 Jan 2015

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