Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "casual", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Neat fake data generator", | ||
@@ -5,0 +5,0 @@ "main": "src/casual.js", |
@@ -19,5 +19,16 @@ ## WARNING: MODULE IS UNDER CONSTRUCTION | ||
// Generates random city name | ||
// Generate random city name | ||
var city = casual.city; | ||
// Define custom generator | ||
casual.define('point', function() { | ||
return { | ||
x: Math.random(), | ||
y: Math.random() | ||
}; | ||
}); | ||
// Generate random point | ||
var point = casual.point; | ||
// And so on.. | ||
@@ -28,16 +39,69 @@ ``` | ||
## List of available generators | ||
## Available generators | ||
Property 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 | ||
``` | ||
- name | ||
- firstname | ||
- lastname | ||
- domain | ||
- sentence | ||
- title | ||
- city | ||
- text | ||
## Custom generators | ||
```javascript | ||
casual.define('user', function() { | ||
return { | ||
email: casual.email, | ||
firstname: casual.firstname, | ||
lastname: casual.lastname, | ||
password: casual.password | ||
}; | ||
}); | ||
// Generate object with randomly generated fields | ||
var user = casual.user; | ||
``` | ||
If you want to pass some params to your generator: | ||
```javascript | ||
casual.define('profile', function(type) { | ||
return { | ||
title: casual.title, | ||
description: casual.description, | ||
type: type || 'private' | ||
}; | ||
}); | ||
// Generate object with random data | ||
var profile = casual.profile('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`. | ||
# License | ||
@@ -44,0 +108,0 @@ |
@@ -14,15 +14,47 @@ var casual = {}; | ||
define('name', require('./generators/name')); | ||
define('firstname', require('./generators/firstname')); | ||
define('lastname', require('./generators/lastname')); | ||
define('email', require('./generators/email')); | ||
casual.random_element = function(array) { | ||
var index = casual.integer(0, array.length); | ||
return array[index]; | ||
}; | ||
// Text | ||
define('domain', require('./generators/domain')); | ||
define('title', require('./generators/sentence')); | ||
define('sentence', require('./generators/sentence')); | ||
define('city', require('./generators/city')); | ||
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; |
@@ -5,4 +5,10 @@ var casual = require('../'); | ||
var test = function(name) { | ||
var first = casual[name]; | ||
var second = casual[name]; | ||
if (typeof casual[name] === 'function') { | ||
var first = casual[name](); | ||
var second = casual[name](); | ||
} else { | ||
var first = casual[name]; | ||
var second = casual[name]; | ||
} | ||
first.should.not.be.equal(second); | ||
@@ -25,2 +31,18 @@ }; | ||
test('short_description'); | ||
test('zip'); | ||
test('street'); | ||
test('address'); | ||
test('address1'); | ||
test('address2'); | ||
test('state'); | ||
test('latitude'); | ||
test('longitude'); | ||
test('lat'); | ||
test('lng'); | ||
test('long'); | ||
test('ip'); | ||
test('company_name'); | ||
test('integer'); | ||
test('double'); | ||
test('country'); | ||
}); | ||
@@ -45,3 +67,13 @@ }); | ||
}); | ||
}) | ||
}); | ||
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); | ||
first.should.not.be.equal(second); | ||
}); | ||
}); | ||
}); |
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
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
10571
35
199
127