SB-6.1-PRE
This commit is contained in:
1 parent
690169a409
commit
358a25f522
3760 files changed
+300059
-36
No files matched your search
+24
@@ -0,0 +1,24 @@
|
||||
# bool
|
||||
|
||||
```js
|
||||
// usages
|
||||
chance.bool()
|
||||
chance.bool({ likelihood: 30 })
|
||||
```
|
||||
Return a random boolean value (`true` or `false`).
|
||||
|
||||
```js
|
||||
chance.bool();
|
||||
=> true
|
||||
```
|
||||
|
||||
The default likelihood of success (returning `true`) is 50%.
|
||||
Can optionally specify the likelihood in percent:
|
||||
|
||||
```js
|
||||
chance.bool({likelihood: 30});
|
||||
=> false
|
||||
```
|
||||
|
||||
In this case only a 30% likelihood of `true`, and a 70% likelihood of `false`.
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
# character
|
||||
|
||||
```js
|
||||
// usages
|
||||
chance.character()
|
||||
chance.character({ pool: 'abcde' })
|
||||
chance.character({ alpha: true })
|
||||
chance.character({ numeric: true })
|
||||
chance.character({ casing: 'lower' })
|
||||
chance.character({ symbols: true })
|
||||
```
|
||||
|
||||
Return a random character.
|
||||
|
||||
```js
|
||||
chance.character();
|
||||
=> 'v'
|
||||
```
|
||||
|
||||
By default it will return a string with random character from the following
|
||||
pool.
|
||||
|
||||
```js
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()'
|
||||
```
|
||||
|
||||
Optionally specify a pool and the character will be generated with characters
|
||||
only from that pool.
|
||||
|
||||
```js
|
||||
chance.character({ pool: 'abcde' });
|
||||
=> 'c'
|
||||
```
|
||||
|
||||
Optionally specify alpha for an alphabetic character.
|
||||
|
||||
```js
|
||||
chance.character({ alpha: true });
|
||||
=> 'N'
|
||||
```
|
||||
|
||||
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
|
||||
other.
|
||||
|
||||
```js
|
||||
chance.character({ casing: 'lower' });
|
||||
=> 'j'
|
||||
```
|
||||
|
||||
*Note, wanted to call this key just ```case``` but unfortunately that's a
|
||||
reserved word in JavaScript for use in a switch statement*
|
||||
|
||||
Optionally return only symbols
|
||||
|
||||
```js
|
||||
chance.character({ symbols: true });
|
||||
=> '%'
|
||||
```
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
# falsy
|
||||
|
||||
```js
|
||||
// usages
|
||||
chance.falsy()
|
||||
chance.falsy({ pool: [ NaN, undefined ] })
|
||||
```
|
||||
Return a random falsy value (`false`, `null`, `undefined`, `0`, `NaN`, `''`).
|
||||
|
||||
```js
|
||||
chance.falsy();
|
||||
=> false
|
||||
```
|
||||
|
||||
The default pool can be changed to better meet the needs:
|
||||
|
||||
```js
|
||||
chance.falsy({ pool: [ NaN, undefined ] });
|
||||
=> NaN
|
||||
```
|
||||
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
# floating
|
||||
|
||||
```js
|
||||
// usages
|
||||
chance.floating()
|
||||
chance.floating({ fixed: 7 })
|
||||
chance.floating({ min: 0, max: 100 })
|
||||
```
|
||||
<p class="pullquote">I wanted to use float or double as the method name but both are JS reserved words even though they aren't really used...</p>
|
||||
|
||||
Return a random floating point number.
|
||||
|
||||
```js
|
||||
chance.floating();
|
||||
=> -211920142886.5024
|
||||
```
|
||||
|
||||
By default it will return a fixed number of at most 4 digits after the decimal.
|
||||
|
||||
Note: *at most* 4 digits. This because, unless we returned trailing zeroes
|
||||
(which aren't allowed on the JavaScript float) we can't guarantee 4 digits after
|
||||
the decimal. So if random chance comes back with `82383854.2000` then
|
||||
`82383854.2` is what will be returned.
|
||||
|
||||
To retrieve a set number of fixed digits after the decimal, provide it as an option.
|
||||
|
||||
```js
|
||||
chance.floating({ fixed: 7 });
|
||||
=> -749512327.7447168
|
||||
```
|
||||
|
||||
As with other number functions, can include a min and/or max.
|
||||
|
||||
```js
|
||||
chance.floating({ min: 0, max: 100 });
|
||||
=> 31.9021
|
||||
```
|
||||
|
||||
Or combine them.
|
||||
|
||||
```js
|
||||
chance.floating({ min: 0, max: 100, fixed: 8 });
|
||||
=> 45.92367599
|
||||
```
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
# integer
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.integer()
|
||||
chance.integer({ min: -20, max: 20 })
|
||||
```
|
||||
|
||||
<p class="pullquote">9007199254740991 is 2^53 - 1 and is the largest number value in JavaScript</p>
|
||||
|
||||
Return a random integer.
|
||||
|
||||
_range: -9007199254740991 to 9007199254740991_
|
||||
|
||||
See: [Largest number in JavaScript](http://vq.io/16qnIYj)
|
||||
|
||||
```js
|
||||
chance.integer();
|
||||
=> -1293235
|
||||
```
|
||||
|
||||
Can optionally provide min and max.
|
||||
|
||||
```js
|
||||
chance.integer({ min: -20, max: 20 })
|
||||
=> -7
|
||||
```
|
||||
|
||||
|
||||
These min and max are inclusive, so they are included in the range. This means
|
||||
```js
|
||||
chance.integer({ min: -2, max: 2 })
|
||||
```
|
||||
would return either -2, -1, 0, 1, or 2.
|
||||
|
||||
```js
|
||||
// Specific case
|
||||
-2 <= random number <= 2
|
||||
|
||||
// General case
|
||||
min <= random number <= max
|
||||
```
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
# letter
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.letter()
|
||||
chance.letter({ casing: 'lower' })
|
||||
```
|
||||
|
||||
Return a random letter.
|
||||
|
||||
```js
|
||||
chance.letter();
|
||||
=> 'p'
|
||||
```
|
||||
|
||||
By default it will return a random lowercase letter.
|
||||
|
||||
<p class="pullquote">Note, wanted to call this option just <strong>case</strong> instead of <strong>casing</strong> but unfortunately that's a reserved word in JavaScript for use in a switch statement</p>
|
||||
|
||||
It's possible to specify upper case
|
||||
|
||||
```js
|
||||
chance.letter({casing: 'upper'});
|
||||
=> 'A'
|
||||
```
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
# natural
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.natural()
|
||||
chance.natural({ min: 1, max: 20 })
|
||||
```
|
||||
|
||||
Return a natural number.
|
||||
|
||||
_range: 0 to 9007199254740991_
|
||||
|
||||
```js
|
||||
chance.natural();
|
||||
=> 125019392395
|
||||
```
|
||||
|
||||
Can optionally provide min and max.
|
||||
|
||||
```js
|
||||
chance.natural({min: 1, max: 20});
|
||||
=> 14
|
||||
```
|
||||
|
||||
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
|
||||
```chance.natural({min: 1, max: 3});``` would return either 1, 2, or 3 or:
|
||||
|
||||
```js
|
||||
// Specific case
|
||||
1 <= random number <= 3
|
||||
|
||||
// General case
|
||||
min <= random number <= max
|
||||
```
|
||||
|
||||
|
||||
[Natural Number on Wikipedia][natural]
|
||||
|
||||
[natural]: https://en.wikipedia.org/wiki/Natural_number
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
# prime
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.prime()
|
||||
chance.prime({ min: 1, max: 20 })
|
||||
```
|
||||
|
||||
Return a prime number.
|
||||
|
||||
_default range: 0 to 10000_
|
||||
|
||||
```js
|
||||
chance.prime();
|
||||
=> 929
|
||||
```
|
||||
|
||||
Can optionally provide min and max.
|
||||
|
||||
```js
|
||||
chance.prime({min: 1, max: 20});
|
||||
=> 13
|
||||
```
|
||||
|
||||
|
||||
These are inclusive, so they are included in the range. This means
|
||||
```chance.prime({min: 2, max: 5});``` would return either 2, 3, or 5 or:
|
||||
|
||||
```js
|
||||
// Specific case
|
||||
2 <= random number <= 5
|
||||
|
||||
// General case
|
||||
min <= random number <= max
|
||||
```
|
||||
|
||||
|
||||
[Prime Number on Wikipedia][prime]
|
||||
|
||||
[prime]: https://en.wikipedia.org/wiki/Prime_number
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
# string
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.string()
|
||||
chance.string({ length: 5 })
|
||||
chance.string({ min: 5 })
|
||||
chance.string({ max: 50 })
|
||||
chance.string({ min: 5, max: 20 })
|
||||
chance.string({ pool: 'abcde' })
|
||||
chance.string({ alpha: true })
|
||||
chance.string({ casing: 'lower' })
|
||||
chance.string({ symbols: true })
|
||||
```
|
||||
|
||||
Return a random string.
|
||||
|
||||
```js
|
||||
chance.string();
|
||||
=> 'Z&Q78&fqkPq'
|
||||
```
|
||||
|
||||
By default it will return a string with random length of 5-20 characters and
|
||||
will contain any of the following characters.
|
||||
|
||||
```js
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()[]'
|
||||
```
|
||||
|
||||
Can optionally specify a length and the string will be exactly that length.
|
||||
|
||||
```js
|
||||
chance.string({ length: 5 });
|
||||
=> 'YN%fG'
|
||||
```
|
||||
|
||||
Can optionally specify a min and the string will have a minimum length
|
||||
|
||||
```js
|
||||
chance.string({ min: 5 });
|
||||
=> '6(Ow1wF)qjUm%W)B2[Q]'
|
||||
```
|
||||
|
||||
Can optionally specify a max and the string will have a maximum length
|
||||
|
||||
```js
|
||||
chance.string({ max: 20 });
|
||||
=> 'k7fubkfMS@gs#E'
|
||||
```
|
||||
|
||||
Can optionally specify a pool and the string will be generated with characters
|
||||
only from that pool.
|
||||
|
||||
```js
|
||||
chance.string({ pool: 'abcde' });
|
||||
=> 'cccdeeabedebb'
|
||||
```
|
||||
|
||||
Of course these options can also be combined, using length or min and max.
|
||||
|
||||
```js
|
||||
chance.string({ length: 5, pool: 'abcde' });
|
||||
=> 'cbbdc'
|
||||
```
|
||||
|
||||
```js
|
||||
chance.string({ min: 5, max: 20, pool: 'abcde' });
|
||||
=> 'ebddceaaceeda'
|
||||
```
|
||||
|
||||
All the options for [chance.character()](./character.md) are supported:
|
||||
|
||||
```js
|
||||
chance.string({ length: 8, casing: 'upper', alpha: true, numeric: true });
|
||||
=> '3THK7GB1'
|
||||
```
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
# template
|
||||
|
||||
Return a random string matching the given template.
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.template('{AA####}')
|
||||
=> 'ZQ7803'
|
||||
chance.template('{Aa}-{##}')
|
||||
=> 'Vr-78'
|
||||
chance.template('{####}:{####}:{####}')
|
||||
=> '1628:5987:7803'
|
||||
```
|
||||
|
||||
The template consists of any number of "character replacement" and "character
|
||||
literal" sequences. A "character replacement" sequence starts with a left
|
||||
brace, has any number of special replacement characters, and ends with a right
|
||||
brace. A character literal can be any character except a brace or a backslash.
|
||||
A literal brace or backslash character can be included in the output by
|
||||
escaping with a backslash.
|
||||
|
||||
The following replacement characters can be used in a replacement sequence:
|
||||
|
||||
* "#": a random digit
|
||||
* "a": a random lower case letter
|
||||
* "A": a random upper case letter
|
||||
|
||||
Reference in new issue
Block a user