Random Fixture Data
Adapted from casual's fake data generator. This version creates mixed-case methods that pass jshint tests when camelcase is set to true. New methods are documented below...
Installation
npm install random-fixture-data --save-dev
Usage
const data = ; // Generate random sentence// You don't need function call operator here// because most of generators use properties mechanismlet sentence = datasentence; // Generate random city namelet city = datacity; // Define custom generatordata; // Generate random pointlet point = datapoint; // And so on..
Random Fixture Data 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'casualzip // '26995'casualstreet // 'Jadyn Islands'casualaddress // '6390 Tremblay Pines Suite 784'casualaddress1 // '8417 Veda Circles'casualaddress2 // 'Suite 648'casualstate // 'Michigan'casualstate_abbr // 'CO'casualstateAbbr // 'CO'casuallatitude // 90.0610casuallongitude // 180.0778casualbuilding_number // 2413casualbuildingNumber // 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.'casualshortDescription // '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' ]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' // Person casualname // 'Alberto'casualusername // 'Darryl'casualfirst_name // 'Derek'casualfirstName // 'Derek'casuallast_name // 'Considine'casuallastName // 'Considine'casualfull_name // 'Kadin Torphy'casualpassword // '(205)580-1350Schumm'casualname_prefix // 'Miss'casualnamePrefix // 'Miss'casualname_suffix // 'Jr.'casualnameSuffix // 'Jr.'casualcompany_name // 'Cole, Wuckert and Strosin'casualcompanyName // 'Cole, Wuckert and Strosin'casualcompany_suffix // 'Inc'casualcompanySuffix // 'Inc'casualcatch_phrase // 'Synchronised optimal concept'casualcatchPhrase // 'Synchronised optimal concept'casualphone // '380 82 790 25 92' // Numbers casualrandom // 0.7171590146608651 (core generator)casual // 632casual // -234.12987444casual // [ 4, 8, 3, 1, 7, 6, 6 ]casual // [ 4, 8, 3, 1, 7, 6, 6 ]casual // [ -105, -7, -532, -596, -430, -957, -234 ]casual // [ -105, -7, -532, -596, -430, -957, -234 ]casual // [ -866.3755785673857, -166.62194719538093, ...] // 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 // 323casualdayOfYear // 323casualday_of_month // 9casualdayOfMonth // 9casualday_of_week // 4casualdayOfWeek // 4casualmonth_number // 9casualmonthNumber // 9casualmonth_name // 'March'casualmonthName // 'March'casualyear // 1990casualtimezone // 'America/Miquelon' // Payments casualcard_type // 'American Express'casualcardType // 'American Express'casual // '4716506247152101' (if no vendor specified then random)casual // '4716506247152101' (if no vendor specified then random)casualcard_exp // '03/04'casualcardExp // '03/04'casualcard_data // { type: 'MasterCard', number: '5307558778577046', exp: '04/88', holder_name: 'Jaron Gibson' }casualcardData // { type: 'MasterCard', number: '5307558778577046', exp: '04/88', holder_name: 'Jaron Gibson' } // Misc casualcountry_code // 'ES'casualcountryCode // 'ES'casuallanguage_code // 'ru'casuallanguageCode // 'ru'casuallocale // 'hi_IN'casualmime_type // 'audio/mpeg'casualmimeType // 'audio/mpeg'casualfile_extension // 'rtf'casualfileExtension // 'rtf' // Colors casualcolor_name // 'DarkOliveGreen'casualcolorName // 'DarkOliveGreen'casualsafe_color_name // 'maroon'casualsafeColorName // 'maroon'casualrgb_hex // '#2e4e1f'casualrgbHex // '#2e4e1f'casualrgb_array // [ 194, 193, 166 ]casualrgbArray // [ 194, 193, 166 ]
Define custom generators
casual; // Generate object with randomly generated fieldslet user = casualuser;
If you want to pass some params to your generator:
casual; // Generate object with random datalet 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:
let 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 (randomElement)
Get random array element
let item = casual;
random_value (randomValue)
Extract random object value
let val = casual;// val will be equal 1 or 3 or 42
random_key (randomKey)
Extract random object key
let 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
let formats = '{{first_name}}' '{{last_name}} {{city}}';casual; // Same as casual;
numerify
Replace all #
in string with digits
let format = '(##)-00-###-##';casual; // '(10)-00-843-32'
define
register_provider
Register generators provider
let words = 'flexible' 'great' 'ok' 'good';let doge_provider = { return 'such ' + casual; } { return 'wow ' + provider; }; 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 functionlet title = casual;// Same aslet title = casualtitle; // Pass generator as callbacklet { let result = ; for let i = 0; i < times; ++i result; return result;}; // Will generate array of five random timestampslet array_of_timestamps = ;
Or you can get functional version of casual generator:
let 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
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.