Coder Social home page Coder Social logo

feku's Introduction

Feku

Generate intelligent random data based on a spec file.

Features

  • CLI
  • examples
  • helper functions to generate random data
  • customizable output JSON lines (jsonld / ndjson) or JSON Array
  • custom spec files to generate new rows based on previously generated data (for example account balance must take into account previous transaction as well)

Installation

  • using PNPM pnpm add -D feku
  • using NPM npm install --save-dev feku

Using as a CLI

Note

When installed locally in a project using pnpm, run CLI using PNPM pnpm feku <spec-file.js> [options]

Options

  • --count or -n accepts number of items to generate
  • --array or -a

Examples:

feku examples/movies.js by default produces json lines (jsonld / ndjson)

{"title":"sint voluptatem","year":2014,"rating":4,"duration":102,"genre":"Romance","image":"http://loremflickr.com/640/480/abstract","description":"Laudantium minima quae libero asperiores voluptatem adipisci. Doloribus rerum praesentium.","cast":["Shawna Pollich DVM","Miss Josefina Schmidt","Lizeth"]}
{"title":"aperiam nostrum odit excepturi sint","year":2001,"rating":2,"duration":110,"genre":"Comedy","image":"http://loremflickr.com/640/480/business","description":"Fuga quod culpa qui. Provident voluptatum qui eum omnis.","cast":["Phil Casper","Sergio Pfeffer","Yvonne"]}
{"title":"iure","year":1985,"rating":5,"duration":134,"genre":"Drama","image":"http://loremflickr.com/640/480/abstract","description":"Quia incidunt ipsum maiores. Libero similique assumenda deserunt aliquam harum iure nemo fuga consequatur.","cast":["Kristin Hintz","Dr. Danielle Batz","Mavis"]}
{"title":"aliquam","year":1989,"rating":1,"duration":113,"genre":"Comedy","image":"http://loremflickr.com/640/480/people","description":"Et omnis ipsam placeat est harum adipisci. Illum et consequatur.","cast":["Gerardo MacGyver","Miss Lester Brakus","Retha"]}

feku examples/people.js --count=5 --array produces an array of five person objects

[
  {
    "name": "Lindsay Swaniawski",
    "age": 85
  },
  {
    "name": "Mattie Romaguera",
    "age": 37
  },
  {
    "name": "Tabitha Harber",
    "age": 99
  },
  {
    "name": "Virginia Schinner",
    "age": 69
  },
  {
    "name": "Kara Kihn",
    "age": 47
  }
]

We can pass in extra args like start and end date.

feku examples/account.js --count 5 --startDate 2022-04-01 --endDate 2022-04-30

{"date":"2022-04-01","desc":"laudantium quae","amt":-8,"bal":1241}
{"date":"2022-04-02","desc":"dolorum eligendi omnis officiis qui","amt":22,"bal":1263}
{"date":"2022-04-05","desc":"rem qui incidunt et","amt":-61,"bal":1202}
{"date":"2022-04-08","desc":"libero porro","amt":-32,"bal":1170}
{"date":"2022-04-20","desc":"aut id","amt":-20,"bal":1150}

Writing a spec file

At minimum, the spec file needs to export a default function (you can give it whatever name the suits it purpose, see examples)

export default function rowBuilder({faker}) {
    return {
        name: faker.name.findName()
    }
}

we can export initialContext, that is passed to the rowBuilder as well which can be used to control seed data. These attributes can be overridden from the CLI as well.

export const initialContext = {
    count: 30
}

Using as a Library

We can use feku to generate data on the fly in browser/node or any other javascript environment. Following is an example:

import { generate } from "feku";

export function generateData(n = 10) {
  const data = [];

  function rowBuilder({ faker }) {
    return {
      name: faker.name.findName(),
      age: faker.datatype.number({ min: 1, max: 100 }),
      city: faker.address.city(),
      phone: faker.phone.phoneNumber("(+##) #### ### ###")
    };
  }

  for (let row of generate({ count: n }, rowBuilder)) {
    data.push(row);
  }

  return data;
}

Built on libraries

Other libraries worth checking out:

feku's People

Contributors

dependabot[bot] avatar kdabir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.