Comparing version 1.0.18 to 1.1.0
@@ -8,2 +8,3 @@ # character | ||
chance.character({ alpha: true }) | ||
chance.character({ numeric: true }) | ||
chance.character({ casing: 'lower' }) | ||
@@ -35,3 +36,3 @@ chance.character({ symbols: true }) | ||
Optionally specify alpha for only an alphanumeric character. | ||
Optionally specify alpha for an alphabetic character. | ||
@@ -43,2 +44,9 @@ ```js | ||
Optionally specify numeric for a numeric character. | ||
```js | ||
chance.character({ numeric: true }); | ||
=> '8' | ||
``` | ||
Default includes both upper and lower case. It's possible to specify one or the | ||
@@ -45,0 +53,0 @@ other. |
@@ -25,3 +25,9 @@ # natural | ||
Can optionally provide numbers you wish to exclude. | ||
```js | ||
chance.natural({min: 1, max: 5, exclude: [1, 3]}); | ||
=> 2 | ||
``` | ||
These are inclusive, so they are included in the range. This means | ||
@@ -28,0 +34,0 @@ ```chance.natural({min: 1, max: 3});``` would return either 1, 2, or 3 or: |
@@ -8,2 +8,5 @@ # string | ||
chance.string({ pool: 'abcde' }) | ||
chance.string({ alpha: true }) | ||
chance.string({ casing: 'lower' }) | ||
chance.string({ symbols: true }) | ||
``` | ||
@@ -46,1 +49,8 @@ | ||
``` | ||
All the options for [chance.character()](./character.md) are supported: | ||
```js | ||
chance.string({ length: 8, casing: 'upper', alpha: true, numeric: true }); | ||
=> '3THK7GB1' | ||
``` |
@@ -26,2 +26,4 @@ # ![Chance](./logo.png) | ||
<iframe src="https://ghbtns.com/github-btn.html?user=chancejs&repo=chancejs&type=star&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="170px" height="20px"></iframe> | ||
Written by [Victor Quinn](https://www.victorquinn.com) | ||
@@ -54,1 +56,3 @@ | ||
<a id="true-random">[1]</a> Of course true mathematicians out there would say that this ought to be considered as only generating pseudo-random things, not true random. For that we'd need some external entropy, not depending on a Mersenne Twister, blah, blah, blah. However, for most practical uses of this library for which it was created and intended, such as generating random names and addresses for automated tests, our random is good enough. But it should probably NOT be used for any cryptographic applications requiring true-random. See [Wikipedia's article](http://vq.io/12hBd84) for more info. | ||
<a href="https://www.gosquared.com/analytics/?utm_campaign=badge"><img src="https://stats.gs/badge" alt="Analytics by GoSquared" /></a> |
@@ -29,1 +29,2 @@ # dice | ||
They return values between 1 and the number after the `d`, so `chance.d4()` returns 1, 2, 3, or 4, just like a 4 sided die would. |
@@ -6,3 +6,3 @@ # last | ||
chance.last() | ||
chance.last({ nationality: 'us' }) | ||
chance.last({ nationality: 'en' }) | ||
``` | ||
@@ -24,2 +24,2 @@ | ||
Note, currently support for nationality is limited to: `'us', 'it'`. | ||
Note, currently support for nationality is limited to: `'en', 'it', 'nl', 'uk', 'de', 'jp', 'es', 'fr'`. |
@@ -12,2 +12,3 @@ * [Chance](intro.md) | ||
* [bool](basics/bool.md) | ||
* [falsy](basics/falsy.md) | ||
* [character](basics/character.md) | ||
@@ -71,2 +72,3 @@ * [floating](basics/floating.md) | ||
* [latitude](location/latitude.md) | ||
* [locale](location/locale.md) | ||
* [longitude](location/longitude.md) | ||
@@ -73,0 +75,0 @@ * [phone](location/phone.md) |
@@ -6,3 +6,5 @@ # url | ||
chance.url() | ||
chance.url({protocol: 'ftp'}) | ||
chance.url({domain: 'www.socialradar.com'}) | ||
chance.url({domain_prefix: 'docs'}) | ||
chance.url({path: 'images'}) | ||
@@ -19,2 +21,9 @@ chance.url({extensions: ['gif', 'jpg', 'png']}) | ||
Optionally specify a protocol and the url will be random but the protocol will not. | ||
```js | ||
chance.url({protocol: 'ftp'}) | ||
=> 'ftp://mibfu.nr/kardate' | ||
``` | ||
Optionally specify a domain and the url will be random but the domain will not. | ||
@@ -27,2 +36,9 @@ | ||
Optionally specify a domain prefix and domain will be random, and domain prefix will not. | ||
```js | ||
chance.url({domain_prefix: 'docs'}) | ||
=> 'http://docs.tuos.ni/itecabup' | ||
``` | ||
Optionally specify a path and it will be obeyed. | ||
@@ -29,0 +45,0 @@ |
@@ -9,28 +9,24 @@ const gulp = require('gulp') | ||
gulp.task('lint', () => | ||
gulp.src(['**/*.js', '!docs/**', '!node_modules/**', '!dist/**', '!test/helpers/**/*.js']) | ||
.pipe(eslint({ | ||
gulp.task('lint', () => gulp.src(['**/*.js', '!docs/**', '!node_modules/**', '!dist/**', '!test/helpers/**/*.js']) | ||
.pipe(eslint({ | ||
parser: 'babel-eslint', | ||
rules: { | ||
// quotes: ['error', 'single'], | ||
'curly': 'error', | ||
'eqeqeq': 'error', | ||
'new-parens': 'error', | ||
'no-cond-assign': 'error', | ||
'no-console': 'error', | ||
'no-debugger': 'error', | ||
'no-empty': 'error', | ||
'no-fallthrough': 'error', | ||
'no-trailing-spaces': 'error', | ||
'no-mixed-spaces-and-tabs': 'error', | ||
// quotes: ['error', 'single'], | ||
'curly': 'error', | ||
'eqeqeq': 'error', | ||
'new-parens': 'error', | ||
'no-cond-assign': 'error', | ||
'no-console': 'error', | ||
'no-debugger': 'error', | ||
'no-empty': 'error', | ||
'no-fallthrough': 'error', | ||
'no-trailing-spaces': 'error', | ||
'no-mixed-spaces-and-tabs': 'error', | ||
} | ||
})) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()) | ||
) | ||
})) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError())) | ||
gulp.task('test', () => | ||
gulp.src('test/**/*.js') | ||
.pipe(ava({ verbose: true })) | ||
) | ||
gulp.task('test', () => gulp.src('test/**/*.js') | ||
.pipe(ava({ verbose: true }))) | ||
@@ -37,0 +33,0 @@ gulp.task('watch', () => { |
{ | ||
"name": "chance", | ||
"main": "./chance.js", | ||
"version": "1.0.18", | ||
"version": "1.1.0", | ||
"description": "Chance - Utility library to generate anything random", | ||
@@ -23,2 +23,3 @@ "homepage": "http://chancejs.com", | ||
"docpress": "0.7.1", | ||
"eslint": "^6.3.0", | ||
"git-update-ghpages": "1.3.0", | ||
@@ -38,3 +39,7 @@ "gulp": "^4.0.0", | ||
"scripts": { | ||
"test": "gulp travis" | ||
"coverage": "nyc npm test && nyc report --reporter=text-lcov --report-dir=./coverage > ./coverage/lcov.info", | ||
"docs": "docpress build", | ||
"docs:publish": "git-update-ghpages -e", | ||
"lint": "eslint --ignore-path .gitignore chance.js", | ||
"test": "ava" | ||
}, | ||
@@ -41,0 +46,0 @@ "keywords": [ |
@@ -525,2 +525,8 @@ import test from 'ava' | ||
test('states() with country of "mx" returns 32 MX states', t => { | ||
t.is(chance.states({ | ||
country: 'mx' | ||
}).length, 32) | ||
}) | ||
// chance.street() | ||
@@ -527,0 +533,0 @@ test('street() works', t => { |
@@ -372,2 +372,30 @@ import test from 'ava' | ||
test('natural() works with excluded numbers', t => { | ||
_.times(1000, () => { | ||
let natural = chance.natural({ min: 1, max: 5, exclude: [1, 3] }) | ||
t.true(natural <= 5) | ||
t.true(natural >= 1) | ||
t.true(natural !== 1) | ||
t.true(natural !== 3) | ||
}) | ||
}) | ||
test('natural() works within empty exclude option', t => { | ||
_.times(1000, () => { | ||
let natural = chance.natural({ min: 1, max: 5, exclude: [] }) | ||
t.true(natural <= 5) | ||
t.true(natural >= 1) | ||
}) | ||
}) | ||
test('natural() throws an error if exclude is not an array', t => { | ||
const fn = () => chance.natural({ min: 1, max: 5, exclude: "foo" }) | ||
t.throws(fn, 'Chance: exclude must be an array.') | ||
}) | ||
test('natural() throws an error if exclude is not an array', t => { | ||
const fn = () => chance.natural({ min: 1, max: 5, exclude: ["puppies", 1] }) | ||
t.throws(fn, 'Chance: exclude must be numbers.') | ||
}) | ||
test('natural() throws an error if min > max', t => { | ||
@@ -479,1 +507,44 @@ const fn = () => chance.natural({ min: 1000, max: 500 }) | ||
}) | ||
test('falsy() should return a falsy value', t => { | ||
_.times(1000, () => { | ||
const value = chance.falsy() | ||
t.falsy(value) | ||
}) | ||
}) | ||
test('falsy() should return a falsy value using a pool data', t => { | ||
_.times(1000, () => { | ||
const value = chance.falsy({pool: [null, undefined]}) | ||
t.falsy(value) | ||
}) | ||
}) | ||
test('template() returns alpha numeric substituted', t => { | ||
_.times(1000, () => { | ||
let str = chance.template('ID-{Aa}-{##}') | ||
t.regex(str, /^ID-[A-Z][a-z]-[0-9][0-9]$/) | ||
}) | ||
}) | ||
test('template() rejects unknown tokens', t => { | ||
t.throws(() => chance.template('{Aa-}'), 'Invalid replacement character: "-".') | ||
t.throws(() => chance.template('{Aa{}'), 'Invalid replacement character: "{".') | ||
t.throws(() => chance.template('{Aab}'), 'Invalid replacement character: "b".') | ||
}) | ||
test('template() allows escape sequnce', t => { | ||
t.is(chance.template('\\\\ID-\\{Aa\\}'), '\\ID-{Aa}') | ||
}) | ||
test('template() rejects invalid escape sequnce', t => { | ||
t.throws(() => chance.template('ID-\\Aa'), 'Invalid escape sequence: "\\A".') | ||
}) | ||
test('template() cannot be undefined', t => { | ||
t.throws(() => chance.template(), 'Template string is required') | ||
}) | ||
test('template() cannot be empty', t => { | ||
t.throws(() => chance.template(''), 'Template string is required') | ||
}) |
@@ -86,2 +86,13 @@ import test from 'ava' | ||
// chance.emotion() | ||
test('emotion() returns a random emotion', t => { | ||
_.times(1000, () => { | ||
let emotion = chance.emotion() | ||
t.true(_.isString(emotion)) | ||
t.true(emotion.length >= 2) | ||
t.true(emotion.length <= 30) | ||
}) | ||
}) | ||
// chance.guid() | ||
@@ -88,0 +99,0 @@ test('guid() returns a proper guid', t => { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
159
19920
1878564
19