Fake data generator
Installation
npm install casual
Usage
var casual = ; // Generate random sentence// You don't need function call operator here// because most of generators use properties mechanismvar sentence = casualsentence; // Generate random city namevar city = casualcity; // Define custom generatorcasual; // Generate random pointvar point = casualpoint; // And so on..
Casual uses javascript properties for common generators so you don't need to use function call operator
Embedded generators
// Address casualcountry // 'United Kingdom'casualcity // 'New Ortiz chester'casual // '26995-7979' (if no digits specified then random selection between ZIP and ZIP+4)casualstreet // 'Jadyn Islands'casualaddress // '6390 Tremblay Pines Suite 784'casualaddress1 // '8417 Veda Circles'casualaddress2 // 'Suite 648'casualstate // 'Michigan'casualstate_abbr // 'CO'casuallatitude // 90.0610casuallongitude // 180.0778casualbuilding_number // 2413 // Text casualsentence // 'Laborum eius porro consequatur.'casual // 'Dolorum fuga nobis sit natus consequatur. Laboriosam sapiente. Natus quos ut.'casualtitle // 'Systematic nobis'casualtext // 'Nemo tempore natus non accusamus eos placeat nesciunt. et fugit ut odio nisi dolore non ... (long text)'casualdescription // 'Vel et rerum nostrum quia. Dolorum fuga nobis sit natus consequatur.'casualshort_description // 'Qui iste similique iusto.'casualstring // 'saepe quia molestias voluptates et'casualword // 'voluptatem'casual // 'sed quis ut beatae id adipisci aut'casual // [ 'voluptas', 'atque', 'vitae', 'vel', 'dolor', 'saepe', 'ut' ]casualletter // 'k' // Internet casualip // '21.44.122.149'casualdomain // 'darrion.us'casualurl // 'germaine.net'casualemail // 'Josue.Hessel@claire.us'casualuser_agent // 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0' // Person casualname // 'Alberto'casualusername // 'Darryl'casualfirst_name // 'Derek'casuallast_name // 'Considine'casualfull_name // 'Kadin Torphy'casualpassword // '(205)580-1350Schumm'casualname_prefix // 'Miss'casualname_suffix // 'Jr.'casualcompany_name // 'Cole, Wuckert and Strosin'casualcompany_suffix // 'Inc'casualcatch_phrase // 'Synchronised optimal concept'casualphone // '982-790-2592' // Numbers casualrandom // 0.7171590146608651 (core generator)casual // 632casual // -234.12987444casual // [ 4, 8, 3, 1, 7, 6, 6 ]casual // [ -105, -7, -532, -596, -430, -957, -234 ]casual // [ -866.3755785673857, -166.62194719538093, ...]casualcoin_flip // true // Date casualunix_time // 659897901casualmoment // moment.js object see http://momentjs.com/docs/casual // '2001-07-06' (see available formatters http://momentjs.com/docs/#/parsing/string-format/)casual // '03:08:02' (see available formatters http://momentjs.com/docs/#/parsing/string-format/)casualcentury // 'IV'casualam_pm // 'am'casualday_of_year // 323casualday_of_month // 9casualday_of_week // 4casualmonth_number // 9casualmonth_name // 'March'casualyear // 1990casualtimezone // 'America/Miquelon' // Payments casualcard_type // 'American Express'casual // '4716506247152101' (if no vendor specified then random)casualcard_exp // '03/04'casualcard_data // { type: 'MasterCard', number: '5307558778577046', exp: '04/88', holder_name: 'Jaron Gibson' } // Misc casualcountry_code // 'ES'casuallanguage_code // 'ru'casuallocale // 'hi_IN'casualcurrency // { symbol: 'R', name: 'South African Rand', symbol_native: 'R', decimal_digits: 2, rounding: 0, code: 'ZAR', name_plural: 'South African rand' } casualcurrency_code // 'TRY'casualcurrency_symbol // 'TL'casualcurrency_name // Turkish Liracasualmime_type // 'audio/mpeg'casualfile_extension // 'rtf'casualboolean // truecasualuuid // '2f4dc6ba-bd25-4e66-b369-43a13e0cf150' // Colors casualcolor_name // 'DarkOliveGreen'casualsafe_color_name // 'maroon'casualrgb_hex // '#2e4e1f'casualrgb_array // [ 194, 193, 166 ]
Define custom generators
casual; // Generate object with randomly generated fieldsvar user = casualuser;
If you want to pass some params to your generator:
casual; // Generate object with random datavar profile = casualprofile'public';
NOTE: if getter function has non-empty arguments list then generator should be called as function casual.profile('public')
,
otherwise it should be accessed as property casual.profile
.
Localization
You can get localized version of casual generator:
var casual = ru_RU;casualstreet; // 'Бухарестская'
Default locale is en_US
.
See src/providers/{{locale}} for more details about available locales and locale specific generators.
If you don't find necessary locale, please create an issue or just add it :)
Helpers
random_element
Get random array element
var item = casual;
random_value
Extract random object value
var val = casual;// val will be equal 1 or 3 or 42
random_key
Extract random object key
var val = casual;// val will be equal 'a' or 'b' or 'c'
populate
Replace placeholders with generators results
casual;// 'Dallin.Konopelski@yahoo.com Lyla'
populate_one_of
Pick random element from given array and populate it
var formats = '{{first_name}}' '{{last_name}} {{city}}';casual; // Same as casual;
numerify
Replace all #
in string with digits
var format = '(##)-00-###-##';casual; // '(10)-00-843-32'
define
register_provider
Register generators provider
var words = 'flexible' 'great' 'ok' 'good';var doge_provider = { return 'such ' + casual; } { return 'wow ' + casual; }; casual; casualsuch; // 'such good'casualdoge_phrase; // 'wow such flexible'
Seeding
If you want to use a specific seed in order to get a repeatable random sequence:
casual;
It uses Mersenne Twister pseudorandom number generator in core.
Generators functions
If you want to pass generator as a callback somewhere or just hate properties you always can access generator function at casual._{generator}
// Generate value using functionvar title = casual;// Same asvar title = casualtitle; // Pass generator as callbackvar { var result = ; for var i = 0; i < times; ++i result; return result;}; // Will generate array of five random timestampsvar array_of_timestamps = ;
Or you can get functional version of casual generator:
var casual = ; // Generate titlecasualtitle; // Generate timestampcasual;
View providers output cli
There is a simple cli util which could be used to view/debug providers output:
# Will render table with columns [generator_name, result] for all providers
node utils/show.js
# Will render table with columns [generator_name, result] only for person provider
node utils/show.js person
Browserify support
Currently you can't use casual with browserify. Please check out this browserify-friendly fork Klowner/casual-browserify
Contributing
License
Heavily inspired by https://github.com/fzaninotto/Faker
The MIT License (MIT) Copyright (c) 2014 Egor Gumenyuk boo1ean0807@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.