summaryrefslogtreecommitdiff
path: root/src/node_modules/chance/docs/helpers
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
committerMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
commit46e43f4bde4a35785b4997b81e86cd19f046b69b (patch)
treec53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/chance/docs/helpers
downloadlangdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip
Commit
Diffstat (limited to 'src/node_modules/chance/docs/helpers')
-rw-r--r--src/node_modules/chance/docs/helpers/capitalize.md13
-rw-r--r--src/node_modules/chance/docs/helpers/mixin.md90
-rw-r--r--src/node_modules/chance/docs/helpers/pad.md40
-rw-r--r--src/node_modules/chance/docs/helpers/pick.md9
-rw-r--r--src/node_modules/chance/docs/helpers/pickone.md13
-rw-r--r--src/node_modules/chance/docs/helpers/pickset.md20
-rw-r--r--src/node_modules/chance/docs/helpers/set.md23
-rw-r--r--src/node_modules/chance/docs/helpers/shuffle.md13
8 files changed, 221 insertions, 0 deletions
diff --git a/src/node_modules/chance/docs/helpers/capitalize.md b/src/node_modules/chance/docs/helpers/capitalize.md
new file mode 100644
index 0000000..52b41a7
--- /dev/null
+++ b/src/node_modules/chance/docs/helpers/capitalize.md
@@ -0,0 +1,13 @@
+# capitalize
+
+```js
+// usage
+chance.capitalize(string)
+```
+
+Capitalize the first letter of a word
+
+```js
+chance.capitalize('bread')
+=> 'Bread'
+```
diff --git a/src/node_modules/chance/docs/helpers/mixin.md b/src/node_modules/chance/docs/helpers/mixin.md
new file mode 100644
index 0000000..499a98f
--- /dev/null
+++ b/src/node_modules/chance/docs/helpers/mixin.md
@@ -0,0 +1,90 @@
+# mixin
+
+```js
+// usage
+chance.mixin(<Object>)
+```
+
+Mixins are a very powerful way to extend **Chance** to fit the needs of your
+specific application.
+
+First, if you are thinking of using a mixin for **Chance**, please consider first
+whether your use is something from which others may benefit. If so, please
+submit a [pull request][PR] rather than using a mixin!
+
+Spread the love and give everyone the benefit of your awesome generator :)
+
+Now, that said, there are bound to be times when you want to generate something
+random that is specific to your application but not widely applicable. Enter
+mixins!
+
+**Chance** mixins allow you to add one-off methods to **Chance** which you can
+use later.
+
+For example, let's say I have a user object which consists of first, last,
+and email.
+
+```js
+
+var user = {
+first: 'John',
+last: 'Smith',
+email: 'john@aol.com'
+};
+
+```
+
+Let's say I want to be able to randomly generate these user objects.
+
+This is not the type of thing which would be widely applicable as it's specific
+to my application so it's perfect for a mixin!
+
+To create a mixin, build an object whose keys are the names of the methods, and
+whose values are the functions to be called.
+
+Note: Within each function, you will have access to `chance` itself!
+
+For example, to create a `user` mixin:
+
+```js
+chance.mixin({
+'user': function() {
+return {
+first: chance.first(),
+last: chance.last(),
+email: chance.email()
+};
+}
+});
+
+// Then you can call your mixin
+chance.user();
+
+=> {first: 'Eli', last: 'Benson', email: 'gembibuj@dugesan.com'}
+```
+
+Mixins can even include other mixins!
+
+For example, to "extend" the user object:
+```js
+chance.mixin({
+'user': function () {
+return {
+first: chance.first(),
+last: chance.last(),
+email: chance.email()
+};
+},
+'social_user': function () {
+var user = chance.user();
+user.network = chance.pick(['facebook', 'twitter']);
+return user;
+}
+});
+```
+
+So we have a second mixin here, `social_user` which is using the `user` mixin
+and adding to it! Note, these mixins can be defined in any order on the object
+if both declared at once.
+
+[PR]: https://github.com/victorquinn/chancejs/pulls
diff --git a/src/node_modules/chance/docs/helpers/pad.md b/src/node_modules/chance/docs/helpers/pad.md
new file mode 100644
index 0000000..8606767
--- /dev/null
+++ b/src/node_modules/chance/docs/helpers/pad.md
@@ -0,0 +1,40 @@
+# pad
+
+```js
+// usage
+chance.pad(number, width)
+chance.pad(number, width, padder)
+```
+
+Pad a number with some string until it reaches a desired width.
+
+By default, `chance.pad()` will pad with zeroes. For example, to zero-pad
+numbers such that the outcome width is 5, do the following.
+
+```js
+chance.pad(45, 5)
+=> '00045'
+
+chance.pad(284, 5)
+=> '00284'
+
+chance.pad(82843, 5)
+=> '82843'
+```
+
+Notice how every item returned is a string with leading zeroes until the width
+is 5 for each one.
+
+Can optionally specify a character if the desire is to pad with something other
+than zero.
+
+```js
+chance.pad(81, 5, 'Z')
+=> 'ZZZ81'
+
+chance.pad(692, 5, 'Z')
+=> 'ZZ692'
+
+chance.pad(52859, 5)
+=> '52859'
+```
diff --git a/src/node_modules/chance/docs/helpers/pick.md b/src/node_modules/chance/docs/helpers/pick.md
new file mode 100644
index 0000000..68f9824
--- /dev/null
+++ b/src/node_modules/chance/docs/helpers/pick.md
@@ -0,0 +1,9 @@
+# pick
+
+```js
+// usage
+chance.pick(array)
+chance.pick(array, count)
+```
+
+**`pick()` is now deprecated in favor of `pickone()` and `pickset()`**
diff --git a/src/node_modules/chance/docs/helpers/pickone.md b/src/node_modules/chance/docs/helpers/pickone.md
new file mode 100644
index 0000000..b3f1cbe
--- /dev/null
+++ b/src/node_modules/chance/docs/helpers/pickone.md
@@ -0,0 +1,13 @@
+# pickone
+
+```js
+// usage
+chance.pickone(array)
+```
+
+Given an array, pick a random element and return it
+
+```js
+chance.pickone(['alpha', 'bravo', 'charlie', 'delta', 'echo']);
+=> 'delta'
+```
diff --git a/src/node_modules/chance/docs/helpers/pickset.md b/src/node_modules/chance/docs/helpers/pickset.md
new file mode 100644
index 0000000..3c3b393
--- /dev/null
+++ b/src/node_modules/chance/docs/helpers/pickset.md
@@ -0,0 +1,20 @@
+# pickset
+
+```js
+// usage
+chance.pickset(array, quantity)
+```
+
+Given an array, pick some random elements and return them in a new array
+
+```js
+chance.pickset(['alpha', 'bravo', 'charlie', 'delta', 'echo'], 3);
+=> ['echo', 'alpha', 'bravo']
+```
+
+Optionally omit the quantity to retrieve a set with length 1
+
+```js
+chance.pickset(['alpha', 'bravo', 'charlie', 'delta', 'echo']);
+=> ['delta']
+```
diff --git a/src/node_modules/chance/docs/helpers/set.md b/src/node_modules/chance/docs/helpers/set.md
new file mode 100644
index 0000000..da0293f
--- /dev/null
+++ b/src/node_modules/chance/docs/helpers/set.md
@@ -0,0 +1,23 @@
+# set
+
+```js
+// usage
+chance.set(key, value)
+```
+
+Used for overriding the default data used by Chance.
+
+For example, if instead of the default set of last names (which were pulled from the U.S. census data and therefore obviously American biased), you could replace the data for the first names with something more suited to your task. For example, if you want instead to pick from last names of houses in *A Song of Ice and Fire*, you could do something like:
+
+```js
+chance.set('lastNames', ['Arryn', 'Baratheon', 'Bolton', 'Frey', 'Greyjoy', 'Lannister', 'Martell', 'Stark', 'Targaryen', 'Tully', 'Tyrell']);
+
+// then
+chance.last()
+=> 'Lannister'
+```
+
+This is very handy for internationalization.
+
+Available keys for datasets to override: `firstNames`, `lastNames`, `provinces`, `us_states_and_dc`, `territories`, `armed_forces`, `street_suffixes`, `months`, `cc_types`, `currency_types`
+
diff --git a/src/node_modules/chance/docs/helpers/shuffle.md b/src/node_modules/chance/docs/helpers/shuffle.md
new file mode 100644
index 0000000..dc80097
--- /dev/null
+++ b/src/node_modules/chance/docs/helpers/shuffle.md
@@ -0,0 +1,13 @@
+# shuffle
+
+```js
+// usage
+chance.shuffle(array)
+```
+
+Given an array, scramble the order and return it.
+
+```js
+chance.shuffle(['alpha', 'bravo', 'charlie', 'delta', 'echo']);
+=> ['echo', 'delta', 'alpha', 'charlie', 'bravo']
+```