stub-objects

    1.4.0 • Public • Published

    stubJs

    Js stub generator for creating smart dummy data, mock generator

    Basic Usage

    var data = stubJs( 'random(cat,dog,mouse,fish)', 5 ); 
    
    // [ 'cat', 'fish', 'fish', 'dog', 'mouse' ];
    

    Objects / Arrays

    var data = stubJs({
    
    	boolean  : 'boolean', 
    	string   : 'string',
    	objectId : 'objectId',
    	number   : 'number',
    	object   : { number : 'number', string : 'string' },
    	array    : ['number',10],
    	date     : 'date',
    	color    : 'color',
    	animal   : 'random(dog,cat,mouse,fish)',
    	static   : 'my static string',
    	dynamic  : 'my number is {{number(1,10)}}!',
    	custom   : function(){ return 'hello world' } // can return any value
    
    },2 );
    

    Resulting stub data :

    [
    	{
    		boolean  : true,
    		string   : 'd32kj',
    		objectId : '558afc069972eb6550e04dd7'
    		number   : 7,
    		object   : { number : 2, string : 'dsk2j' },
    		array    : [ 1, 6, 9, 3, 6, 7, 2, 1, 6, 3 ],
    		date     : js Date object,
    		color    : '#32cc12',
    		animal   : 'dog',
    		static   : 'my static string',
    		dynamic  : 'my number is 7!',
    		custom   : 'hello world'
    	},
    	{
    		boolean  : false,
    		string   : '234jk',
    		objectId : '558afc069972eb6550e04dd7'
    		number   : 2,
    		object   : { number : 1, string : '0dsal' },
    		array    : [ 6, 2, 8, 1, 9, 1, 0, 1, 7, 7 ],
    		date     : js Date object,
    		color    : '#99aabb',
    		animal   : 'fish',
    		static   : 'my static string',
    		dynamic  : 'my number is 9!',
    		custom   : 'hello world'
    	}
    ]
    

    Options

    • 'boolean'
    • 'string(length)'
    • 'objectId'
    • 'number(min,max)'
    • 'object'
    • 'array / array of objects'
    • 'date(start,end)'
    • 'color'
    • 'random(list,of,available,items)'
    • function(){ return }

    👍

    אין עוד מלבדו

    Keywords

    none

    Install

    npm i stub-objects

    DownloadsWeekly Downloads

    7

    Version

    1.4.0

    License

    ISC

    Unpacked Size

    8.4 kB

    Total Files

    7

    Last publish

    Collaborators

    • eliyahulevi