Skip to content

ny0m/nonsense

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm (scoped) npm bundle size npm

Nonsense generates structured random data.

A step toward simple fuzz testing. Use it for testing code that accepts uncontrollable input 🐊🐊🐊


Usage

import { Generators, Nonsense } from '@bradmerlin/nonsense';

// Define data structure.
let bankAccount = {
  accountNumber:  Generators.INT,
  beneficiaryIDs: Generators.INT(5),
  accountType:    Generators.CHOICE(['cheque', 'savings', 'credit']),
  user:           {
    fullName:        Generators.STRING,
    someStaticValue: Generators.VALUE('Do not change'),
  },
};

// Create generator
let generator = Nonsense(bankAccount);

// New random values each time the generator generates.
let output = [];
for (let i = 0; i < 3; i++) {
  output.push(generator());
  // But actually use this in a test.
}
Output:

[
  {
    accountNumber: 1,
    beneficiaryIDs: [16, 53, 46, 7, 73],
    accountType: 'cheque',
    user: {
      fullName: "'=S:[~U£Æ¬�¥U8Sİ6µ�V��G)-�_^h�G¢f�12g�¨��w@ÇM�N&~",
      someStaticValue: 'Do not change'
    }
  },
  {
    accountNumber: 99,
    beneficiaryIDs: [84, 33, 5, 99, 74],
    accountType: 'cheque',
    user: {
      fullName: 'F�¯Á�I%w·½·\\¯´^ª%X?p�S�Â]p��®J�kE¶º}?Ty�J9��¬3³¨�À',
      someStaticValue: 'Do not change'
    }
  },
  {
    accountNumber: 52,
    beneficiaryIDs: [25, 6, 3, 33, 43],
    accountType: 'savings',
    user: {
      fullName: 'HEse�¼V�9I_·C�MµS6r·Lª47º�ª;4�v_P>�&<ÇqP®�b{PF�(�l',
      someStaticValue: 'Do not change'
    }
  }
]

About

A random object generator with a nice API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages