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

stuffd

v0.7.1

Published

Like a turkey.

Downloads

5

Readme

stuffd

I like my data how I like my turkeys. Stuffd. :turkey:

TravisCI Build Status AzurePipelines Build Status Codecov Dependencies DevDependencies npm Monthly Downloads Total Downloads

Create lots of random data, nested or relational (or both) and do whatever you want with it. Output the JSON, manipulate it in TS/JS land, or pipe each object into your database (both objectMode and standard stream suppported)!

Installation

npm i stuffd

Features:

  • Fluid API or TypeScript Decorators for super smooth model definitions.
  • Easily create heaps of nested or relational data in milliseconds.
  • CLI tool for kickin' back and running tasks.
  • Works perfectly with gulp/grunt/any task runner.
  • Packed full of tests, so dense. Over 230 tests and counting!

Examples

Basic (Nested with Fluent API)

cosnt { Stuffd, Context } = require('stuffd');

  // Create Typescript-like enums with explicit integers!
  const ModuleType = Stuffd.createEnum({
    SleepingQuarters: 0,
    DiningRoom: 1,
    RecRoom: 2,
    Agricultural: 3,
    MedicalBay: 4,
    Engineering: 5,
    FitnessCenter: 6,
    ResearchStation: 7,
    NavigationStation: 8,
    WeaponsBay: 9,
    ShieldRoom: 10,
    CargoBay: 11
  });

  // Create Typescript-like enums with implicit integers!
  const ModuleSize = Stuffd.createEnum(['Small', 'Medium', 'Large']);

  // Create custom, re-usable attributes!
  const personName = (c) => `${c.first()} ${c.last()}`;

  const Manufacturer = Stuffd.create('Manufacturer')
    .key('id', id => id.guid())
    .prop('name', n => n.pick(['Rocketdyne', 'Areojet', 'Boeing', 'Lockheed', 'SpaceX', 'Kerbal']))
    .prop('operatingSince', os => os.date(new Date('01/01/1950'), new Date()))
    .prop('ceo', c => c.custom(c => `${c.first()} ${c.last()}`))
    .prop('founder', f => f.custom(personName))
    .build();

  const Engine = Stuffd.create('Engine')
    .prop('model', m => m.str(/[A-Z]{1,3}-\d{1,3}[DXS]{0,1}/))
    .prop('year', y => y.integer(1967, 2020))
    .prop('thrust', t => t.float(1, 5, 12))
    .prop('mass', m => m.float(3, 200, 2000))
    .prop('manufacturer', m => m.type(Manufacturer))
    .toString(function () {
      return `${this.manufacturer.name} ${this.model} (${this.year})`;
    })
    .build();

  const Module = Stuffd.create('Module')
    .prop('type', t => t.enum(ModuleType, String))
    .prop('size', s => s.enum(ModuleSize, Number))
    .prop('operational', op => op.bool(3 / 4))
    .prop('mass', m => m.float(3, 200, 5000))
    .toString(function () {
      return `[${ModuleSize[this.size]}] ${this.type}${this.operational ? '' : ' (undergoing maintenance)'}`;
    })
    .build();

  const Spaceship = Stuffd.create('Spaceship')
    .prop('name', n => n.str(/((Ares|Athena|Hermes|Icarus|Jupiter|Odyssey|Orion|Daedalus|Falcon|[A-Z] Wing) [XXIIVVCD]{2,3})/))
    .prop('captain', m => m.custom(personName))
    .prop('primaryEngines', pe => pe.type(Engine))
    .prop('primaryEngineCount', pec => pec.integer(1, 5))
    .prop('secondaryEngines', se => se.type(Engine))
    .prop('secondaryEngineCount', sec => sec.integer(0, 20))
    .prop('modules', m => m.list(Module, 3, 8))
    .prop('hullMass', m => m.float(3, 5000, 20000))
    .getter('totalThrust', function () {
      let total = (this.primaryEngines.thrust * this.primaryEngineCount) + (this.secondaryEngines.thrust * this.secondaryEngineCount);
      return Math.round(total * 10) / 10;
    })
    .getter('totalMass', function () {
      let total = this.hullMass;

      total += this.primaryEngines.mass * this.primaryEngineCount;
      total += this.secondaryEngines.mass * this.secondaryEngineCount;

      this.modules.forEach((m) => total += m.mass);

      return Math.round(total);
    })
    .toString(function () {
      let str = [this.name + ':'];
      str.push(`  Crew:`);
      str.push(`    ${this.captain}`);
      str.push(`  Engines:`);
      str.push(`    ${this.primaryEngineCount}x ${this.primaryEngines}`);
      if (this.secondaryEngineCount > 0) str.push(`    ${this.secondaryEngineCount}x ${this.secondaryEngines}`);
      str.push(`  Modules:`);
      str.push('    ' + this.modules.map((m) => m.toString()).join(EOL + '    '));
      str.push(`  Stats:`);
      str.push(`    Total Thrust: ${this.totalThrust} tons`);
      str.push(`    Total Mass: ${this.totalMass} kg`);
      
      return str.join(EOL);
    })
    .build();

  // Optionally provide a seed (same seed + same operations = same result)
  const ctx = new Context(2187);

  const fleet = ctx.create(Spaceship, 3);

  console.log(fleet.map(ship => ship.toString()).join(''));
  // Prints out ALL the ship details...

Basic (Relational with Decorators)

import { Stuffd, Context } from 'stuffd';
import { Key, Guid, Custom, Range, Str, Ref, Integer, Float } from 'stuffd/decorators';

@Stuffd()
class Student {

  @Key() @Guid()
  id: string;

  @Custom(c => `${c.first()} ${c.last()}`)
  name: string;
  
  @Range(new Date('01/01/1950'), new Date('12/31/2010'))
  dateOfBirth: Date;

  @Str(/\(\d{3}\)\d{3}-\d{4}/)
  phone: string;
}

@Stuffd()
class Teacher {

  @Key() @Guid()
  id: string;

  @Custom(c => `${c.first()} ${c.last()}`)
  name: string;
}

@Stuffd()
class Class {
  
  @Str(/[A-Z]{2}-\d{4}-[a-e]/)
  id: string;

  @Ref(Teacher)
  teacherId: string;

  @Integer(1, 9)
  period: number;
}

@Stuffd()
class Grade {

  @Ref(Student)
  studentId: string;

  @Ref(Class, 'id')
  classId: string;

  @Float(1, 60, 100)
  grade: number;
}

const ctx = new Context(246);

// Create array of 50 students...
const students = ctx.create(Student, 50);
// [...]

const teachers = ctx.create(Teacher, 3);
// [...]

// Create array of 5 classes referencing a teacher's id from the 3 in that list...
const classes = ctx.using({ 'teacherId': teachers }).create(Class, 5);
// [...]

// Create array of grades, using the 3 classes above for the classId and making one for each student.
const grades = ctx.using({ 'classId': classes }).cross({ 'studentId': students }).create(Grade);
// [...]

const isStudent = students[0] instanceof Student;
// true

// Get an object with all the instances created...
const allData = ctx.data();
// { "Student": [...], "Teacher": [...], etc. }

const allJson = ctx.json(true); // Formatted
// '{ "Student": [...], "Teacher": [...], etc. }'

// Pipe the data somewhere!
ctx.stream().pipe(myDbInserter);
// { "type": "Student", "value": { ... } }

// Pipe the JSON somewhere!
ctx.stream().pipe(myFileInserter);
// (same as above but 1 per line)

CLI


// Docs coming soon! (see ~/examples/stuffd.typescript.ts for example)

stuffd run default --seed 2319

stuffd create Spaceship 2 > ships.json

Contribute

  1. Fork it
  2. npm i
  3. npm run watch
  4. Make changes and write tests.
  5. Send pull request! :sunglasses:

License:

MIT