Comparing version 0.0.6 to 1.0.0
24
index.js
@@ -1,6 +0,20 @@ | ||
var c = require('./'); | ||
var moment = require('moment'); | ||
var casual = require('./'); | ||
var helpers = require('./src/helpers'); | ||
var count = 20; | ||
for (i = 0; i < count; ++i) { | ||
console.log(c.double(5,10)) | ||
} | ||
var words = ['flexible', 'great', 'ok', 'good']; | ||
var provider = { | ||
such: function() { | ||
return 'such ' + casual.random_element(words); | ||
}, | ||
doge_phrase: function() { | ||
return 'wow ' + provider.such(); | ||
} | ||
}; | ||
casual.register_provider(provider); | ||
console.log(casual.such) // 'such good' | ||
console.log(casual.doge_phrase); // 'wow such flexible' |
{ | ||
"name": "casual", | ||
"version": "0.0.6", | ||
"version": "1.0.0", | ||
"description": "Neat fake data generator", | ||
@@ -19,3 +19,4 @@ "main": "src/casual.js", | ||
"dependencies": { | ||
"Faker": "~0.5.11" | ||
"Faker": "~0.5.11", | ||
"moment": "~2.5.1" | ||
}, | ||
@@ -22,0 +23,0 @@ "devDependencies": { |
206
README.md
@@ -1,7 +0,3 @@ | ||
## WARNING: MODULE IS UNDER CONSTRUCTION | ||
## Fake data generator [![Build Status](https://travis-ci.org/boo1ean/casual.png?branch=master)](https://travis-ci.org/boo1ean/casual) | ||
## Neat fake data generator [![Build Status](https://travis-ci.org/boo1ean/casual.png?branch=master)](https://travis-ci.org/boo1ean/casual) | ||
Better [faker](https://github.com/Marak/Faker.js) api. | ||
## Installation | ||
@@ -38,36 +34,107 @@ | ||
## Available generators | ||
## Embedded generators | ||
```javascript | ||
casual.name // Miracle.Stoltenberg | ||
casual.firstname // Willard | ||
casual.lastname // Breitenberg | ||
casual.domain // avery.com | ||
casual.sentence // iusto numquam voluptates sapiente ut hic nostrum modi | ||
casual.title // et possimus rem quibusdam quod repellat magni sed autem | ||
casual.email // Morris_Flatley@norberto.com | ||
casual.city // Marksville | ||
casual.text // adipisci iste id suscipit amet laudantium eum at tenetur impedit... | ||
casual.password // laboriosam quia sit dolorem doloribus et inventore possimus aut | ||
casual.description // doloribus non velit dolore aliquid omnis err... | ||
casual.short_description // doloremque omnis blanditiis officia maxime | ||
casual.zip // 63235 | ||
casual.street // Monahan Tunnel | ||
casual.address // 618 Huels Dam Suite 859 | ||
casual.address1 // 85818 Ondricka Rest | ||
casual.address2 // Suite 086 | ||
casual.state // Connecticut | ||
casual.latitude // 70.0007 | ||
casual.longitude // 149.6702 | ||
casual.lat // 20.2150 | ||
casual.lng // 53.6056 | ||
casual.long // -65.9813 | ||
casual.ip // 39.68.84.100 | ||
casual.company_name // Wisozk, Kshlerin and Weber | ||
casual.integer() // 54 | ||
casual.double() // 23.918293 | ||
casual.country // Northern Ireland | ||
// Address | ||
casual.zip // '33894-7000' | ||
casual.city // 'New Sydneeton' | ||
casual.street // 'Sydni Trail' | ||
casual.address // '1547 Reid Centers Suite 022' | ||
casual.address1 // '012 Obie Walks' | ||
casual.address2 // 'Suite 657' | ||
casual.state // 'Montana' | ||
casual.state_abbr // 'MA' | ||
casual.latitude // -0.5006 | ||
casual.longitude // -56.1632 | ||
casual.lat // -77.4857 | ||
casual.lng // 31.9197 | ||
casual.long // 128.8257 | ||
casual.country // 'Wales' | ||
casual.building_number // 4480 | ||
// Text | ||
casual.sentence // 'laborum eius porro consequatur' | ||
casual.sentences(n = 3) // 'dolorum fuga nobis sit natus consequatur laboriosam sapiente natus quos ut' | ||
casual.title // 'systematic' | ||
casual.text // 'nemo tempore natus non accusamus eos placeat nesciunt et fugit ut odio nisi dolore non' | ||
casual.description // 'vel et rerum nostrum quia' | ||
casual.short_description // 'qui iste similique iusto' | ||
casual.string // 'saepe quia molestias voluptates et' | ||
casual.word // 'voluptatem' | ||
casual.words(n = 7) // 'sed quis ut beatae id adipisci aut' | ||
casual.array_of_words(n = 7) // [ 'voluptas', 'atque', 'vitae', 'vel', 'dolor', 'saepe', 'ut' ] | ||
casual.letter // 'k' | ||
// Internet | ||
casual.ip // '21.44.122.149' | ||
casual.domain // 'darrion.us' | ||
casual.url // 'germaine.net' | ||
casual.email // 'Josue.Hessel@claire.us' | ||
// Person | ||
casual.name // 'Alberto' | ||
casual.username // 'Darryl' | ||
casual.first_name // 'Derek' | ||
casual.last_name // 'Considine' | ||
casual.full_name // 'Kadin Torphy' | ||
casual.password // '(205)580-1380Schumm' | ||
casual.name_prefix // 'Miss' | ||
casual.name_suffix // 'Jr.' | ||
casual.company_name // 'Cole, Wuckert and Strosin' | ||
casual.catch_phrase // 'Synchronised optimal concept' | ||
casual.phone // '380 82 790 25 92' | ||
// Numbers | ||
casual.integer(from = -1000, to = 1000) // 632 | ||
casual.double(from = -1000, to = 1000) // -234.12987444 | ||
casual.array_of_digits(n = 7) // [ 4, 8, 3, 1, 7, 6, 6 ] | ||
casual.array_of_integers(n = 7) // [ -105, -7, -532, -596, -430, -957, -234 ] | ||
casual.array_of_doubles(n = 7) // [ -866.3755785673857, -166.62194719538093, ...] | ||
// Date | ||
casual.unix_time // 659897901 | ||
casual.moment // moment.js object see http://momentjs.com/docs/ | ||
casual.date(format = 'YYYY-MM-DD') // '2001-07-06' (see available formatters http://momentjs.com/docs/#/parsing/string-format/) | ||
casual.time() // '03:08:02' (see available formatters http://momentjs.com/docs/#/parsing/string-format/) | ||
casual.century // 'IV' | ||
casual.am_pm // 'am' | ||
casual.day_of_year // 323 | ||
casual.day_of_month // 9 | ||
casual.day_of_week // 4 | ||
casual.month_number // 9 | ||
casual.month_name // 'March' | ||
casual.year // 1990 | ||
casual.timezone // 'America/Miquelon' | ||
// Payments | ||
casual.card_type // 'American Express' | ||
casual.card_number(vendor) // '4716506247152101' (if no vendor specified then random) | ||
casual.card_exp // '03/04' | ||
casual.card_data // { type: 'MasterCard', number: '5307558778577046', exp: '04/88', holder_name: 'Jaron Gibson' } | ||
// Misc | ||
casual.country_code // 'ES' | ||
casual.language_code // 'ru' | ||
casual.locale // 'hi_IN' | ||
casual.mime_type // 'audio/mpeg' | ||
casual.file_extension // 'rtf' | ||
// Colors | ||
casual.color_name // 'DarkOliveGreen' | ||
casual.safe_color_name // 'maroon' | ||
casual.rgb_hex // '#2e4e1f' | ||
casual.rgb_array // [ 194, 193, 166 ] | ||
``` | ||
## Custom generators | ||
## Define custom generators | ||
@@ -78,4 +145,4 @@ ```javascript | ||
email: casual.email, | ||
firstname: casual.firstname, | ||
lastname: casual.lastname, | ||
firstname: casual.first_name, | ||
lastname: casual.last_name, | ||
password: casual.password | ||
@@ -107,4 +174,69 @@ }; | ||
## Helpers | ||
#### random_element | ||
Get random array element | ||
```javascript | ||
var item = casual.random_element(['ball', 'clock', 'table']); | ||
``` | ||
#### random_value | ||
Extract random object value | ||
```javascript | ||
var val = casual.random_value({ a: 1, b: 3, c: 42 }); | ||
// val will be equal 1 or 3 or 42 | ||
``` | ||
#### random_key | ||
Extract random object key | ||
```javascript | ||
var val = casual.random_key({ a: 1, b: 3, c: 42 }); | ||
// val will be equal 'a' or 'b' or ;c' | ||
``` | ||
#### numerify | ||
Replace all `#` in string with digits | ||
```javascript | ||
var format = '(##)-00-###-##'; | ||
casual.numerify(format); // '(10)-00-843-32' | ||
``` | ||
#### define | ||
See custom generators | ||
#### register_provider | ||
Register generators provider | ||
```javascript | ||
var words = ['flexible', 'great', 'ok', 'good']; | ||
var doge_provider = { | ||
such: function() { | ||
return 'such ' + casual.random_element(words); | ||
}, | ||
doge_phrase: function() { | ||
return 'wow ' + provider.such(); | ||
} | ||
}; | ||
casual.register_provider(doge_provider); | ||
casual.such; // 'such good' | ||
casual.doge_phrase; // 'wow such flexible' | ||
``` | ||
# License | ||
Heavily inspired by https://github.com/fzaninotto/Faker | ||
The MIT License (MIT) | ||
@@ -111,0 +243,0 @@ Copyright (c) 2014 Egor Gumenyuk <boo1ean0807@gmail.com> |
@@ -1,59 +0,15 @@ | ||
var casual = {}; | ||
var define = casual.define = function(name, generator) { | ||
if (typeof generator != 'function') { | ||
throw new Error('Casual generator must be defined by function'); | ||
} | ||
var helpers = require('./helpers'); | ||
if (generator.length) { | ||
casual[name] = generator; | ||
} else { | ||
casual.__defineGetter__(name, generator); | ||
} | ||
}; | ||
var casual = helpers.extend({}, helpers); | ||
casual.random_element = function(array) { | ||
var index = casual.integer(0, array.length); | ||
return array[index]; | ||
}; | ||
casual.register_provider(require('./providers/text')); | ||
casual.register_provider(require('./providers/person')); | ||
casual.register_provider(require('./providers/address')); | ||
casual.register_provider(require('./providers/internet')); | ||
casual.register_provider(require('./providers/number')); | ||
casual.register_provider(require('./providers/date')); | ||
casual.register_provider(require('./providers/payment')); | ||
casual.register_provider(require('./providers/misc')); | ||
casual.register_provider(require('./providers/color')); | ||
// Text | ||
define('domain', require('./generators/domain')); | ||
define('title', require('./generators/sentence')); | ||
define('sentence', require('./generators/sentence')); | ||
define('text', require('./generators/text')); | ||
define('description', require('./generators/text')); | ||
define('short_description', require('./generators/sentence')); | ||
// User-related | ||
define('name', require('./generators/name')); | ||
define('email', require('./generators/email')); | ||
define('firstname', require('./generators/firstname')); | ||
define('lastname', require('./generators/lastname')); | ||
define('password', require('./generators/password')); | ||
define('phone', require('./generators/phone')); | ||
// Address | ||
define('country', require('./generators/country')); | ||
define('city', require('./generators/city')); | ||
define('zip', require('./generators/zip')); | ||
define('street', require('./generators/street')); | ||
define('address', require('./generators/address')); | ||
define('address1', require('./generators/address1')); | ||
define('address2', require('./generators/address2')); | ||
define('state', require('./generators/state')); | ||
define('latitude', require('./generators/latitude')); | ||
define('longitude', require('./generators/longitude')); | ||
define('lat', require('./generators/latitude')); | ||
define('lng', require('./generators/longitude')); | ||
define('long', require('./generators/longitude')); | ||
// Stuff | ||
define('ip', require('./generators/ip')); | ||
define('company_name', require('./generators/company_name')); | ||
define('integer', require('./generators/integer')); | ||
define('double', require('./generators/double')) | ||
module.exports = casual; |
var casual = require('../'); | ||
describe('API', function() { | ||
var max_times = 5; | ||
var test = function(name) { | ||
if (typeof casual[name] === 'function') { | ||
var first = casual[name](); | ||
var second = casual[name](); | ||
} else { | ||
var first = casual[name]; | ||
var second = casual[name]; | ||
} | ||
it('casual.' + name + ' should be ok', function(done) { | ||
if (typeof casual[name] === 'function') { | ||
var pivot = casual[name](); | ||
} else { | ||
var pivot = casual[name]; | ||
} | ||
first.should.not.be.equal(second); | ||
for (var i = 0; i < max_times; i++) { | ||
if (typeof casual[name] === 'function') { | ||
var result = casual[name](); | ||
} else { | ||
var result = casual[name]; | ||
} | ||
if (result != pivot) { | ||
return done(); | ||
} | ||
} | ||
done('Fail'); | ||
}); | ||
}; | ||
describe('Common generators', function() { | ||
it('Should work pretty well', function() { | ||
test('name'); | ||
test('firstname'); | ||
test('lastname'); | ||
test('domain'); | ||
test('sentence'); | ||
test('title'); | ||
test('email'); | ||
describe('Embedded generators', function() { | ||
describe('Address address provider', function() { | ||
test('zip'); | ||
test('city'); | ||
test('text'); | ||
test('password'); | ||
test('description'); | ||
test('short_description'); | ||
test('zip'); | ||
test('street'); | ||
@@ -36,2 +38,3 @@ test('address'); | ||
test('state'); | ||
test('state_abbr'); | ||
test('latitude'); | ||
@@ -42,37 +45,170 @@ test('longitude'); | ||
test('long'); | ||
test('country'); | ||
test('building_number'); | ||
}); | ||
describe('Text provider', function() { | ||
test('sentence'); | ||
test('sentences'); | ||
test('title'); | ||
test('text'); | ||
test('description'); | ||
test('short_description'); | ||
test('string'); | ||
test('word'); | ||
test('words'); | ||
test('array_of_words'); | ||
test('letter'); | ||
}); | ||
describe('Internet provider', function() { | ||
test('ip'); | ||
test('domain'); | ||
test('url'); | ||
test('email'); | ||
}); | ||
describe('Person provider', function() { | ||
test('name'); | ||
test('username'); | ||
test('first_name'); | ||
test('last_name'); | ||
test('full_name'); | ||
test('password'); | ||
test('name_prefix'); | ||
test('name_suffix'); | ||
test('company_name'); | ||
test('catch_phrase'); | ||
test('phone'); | ||
}); | ||
describe('Number generator', function() { | ||
test('integer'); | ||
test('double'); | ||
test('country'); | ||
test('digit'); | ||
test('array_of_digits'); | ||
test('array_of_integers'); | ||
test('array_of_doubles'); | ||
}); | ||
describe('Date provider', function() { | ||
test('unix_time'); | ||
test('moment'); | ||
test('date'); | ||
test('time'); | ||
test('century'); | ||
test('am_pm'); | ||
test('day_of_year'); | ||
test('day_of_month'); | ||
test('day_of_week'); | ||
test('month_number'); | ||
test('month_name'); | ||
test('year'); | ||
test('timezone'); | ||
}); | ||
describe('Payment provider', function() { | ||
test('card_type'); | ||
test('card_number'); | ||
test('card_exp'); | ||
test('card_data'); | ||
}); | ||
describe('Misc provider', function() { | ||
test('country_code'); | ||
test('language_code'); | ||
test('locale'); | ||
test('mime_type'); | ||
test('file_extension'); | ||
}); | ||
describe('Color provider', function() { | ||
test('color_name'); | ||
test('safe_color_name'); | ||
test('rgb_hex'); | ||
test('rgb_array'); | ||
}); | ||
}); | ||
describe('Defining new generator', function() { | ||
it('Should create new casual property if getter doesn\'t have arguments', function() { | ||
casual.define('wow', function() { | ||
return 'wow wow'; | ||
describe('Casual helpers', function() { | ||
describe('define', function() { | ||
it('Should create new casual property if getter doesn\'t have arguments', function() { | ||
casual.define('wow', function() { | ||
return 'wow wow'; | ||
}); | ||
casual.wow.should.be.equal('wow wow'); | ||
}); | ||
casual.wow.should.be.equal('wow wow'); | ||
it('Should create new casual method if getter does have arguments', function() { | ||
casual.define('x2', function(x) { | ||
return x * 2; | ||
}); | ||
casual.x2(3).should.be.equal(6); | ||
}); | ||
}); | ||
it('Should create new casual method if getter does have arguments', function() { | ||
casual.define('x2', function(x) { | ||
return x * 2; | ||
describe('random_element', function() { | ||
it('Should pick random element from array', function(done) { | ||
var array = [1,2,3,4,5,23,6,7,8,95,43]; | ||
var pivot = casual.random_element(array); | ||
for (var i = 0; i < max_times; ++i) { | ||
if (pivot != casual.random_element(array)) { | ||
return done(); | ||
} | ||
} | ||
done('Fail'); | ||
}); | ||
}); | ||
casual.x2(3).should.be.equal(6); | ||
describe('random_key', function() { | ||
it('Should return random object key', function(done) { | ||
var key = casual.random_key({ a: 1, b: 2}); | ||
if (key === 'a' || key === 'b') { | ||
return done(); | ||
} | ||
done('Fail'); | ||
}); | ||
}); | ||
}); | ||
describe('random_element', function() { | ||
it('Should pick random element from array', function() { | ||
var array = [1,2,3,4,5,23,6,7,8,95,43]; | ||
var first = casual.random_element(array); | ||
var second = casual.random_element(array); | ||
describe('random_value', function() { | ||
it('Should return random object value', function(done) { | ||
var key = casual.random_value({ a: 1, b: 2}); | ||
if (key === 1 || key === 2) { | ||
return done(); | ||
} | ||
first.should.not.be.equal(second); | ||
done('Fail'); | ||
}); | ||
}); | ||
describe('extend', function() { | ||
it('Should extend object', function() { | ||
var result = casual.extend({}, {a: 42}); | ||
result.should.have.property('a', 42); | ||
}); | ||
}); | ||
describe('numerify', function() { | ||
it('Should replace every # in string with digit', function() { | ||
var format = '####'; | ||
var numbers = casual.numerify(format); | ||
parseInt(numbers).should.be.within(0, 9999); | ||
}); | ||
}); | ||
describe('register_provider', function() { | ||
it('Should define generators', function() { | ||
casual.register_provider({ | ||
really_custom_generator: function() { return 'custom' } | ||
}); | ||
casual.really_custom_generator.should.be.equal('custom'); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
66029
1272
1
259
2
19
1
+ Addedmoment@~2.5.1
+ Addedmoment@2.5.1(transitive)