1 | # Chance
|
2 |
|
3 | [![Chance Logo](http://chancejs.com/logo.png)](http://chancejs.com)
|
4 |
|
5 | [![Build Status](https://travis-ci.org/chancejs/chancejs.svg?branch=develop)](https://travis-ci.org/chancejs/chancejs) [![GitHub license](https://img.shields.io/github/license/chancejs/chancejs.svg)](https://github.com/chancejs/chancejs) [![GitHub stars](https://img.shields.io/github/stars/chancejs/chancejs.svg)](https://github.com/chancejs/chancejs) [![npm](https://img.shields.io/npm/dm/chance.svg)](https://npmjs.com/package/chance) [![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/chance/badge?style=rounded)](https://www.jsdelivr.com/package/npm/chance) [![npm](https://img.shields.io/npm/v/chance.svg)](https://npmjs.com/package/chance) [![Coverage Status](https://coveralls.io/repos/chancejs/chancejs/badge.svg?branch=master)](https://coveralls.io/r/chancejs/chancejs?branch=master) [![awesomeness](https://img.shields.io/badge/awesomeness-maximum-red.svg)](https://github.com/chancejs/chancejs)
|
6 |
|
7 | Chance - Random generator helper for JavaScript
|
8 |
|
9 | Homepage: [http://chancejs.com](http://chancejs.com)
|
10 |
|
11 | Many more details on [http://chancejs.com](http://chancejs.com) but this single
|
12 | library can generate random numbers, characters, strings, names, addresses,
|
13 | dice, and pretty much anything else.
|
14 |
|
15 | It includes the basic building blocks for all these items and is built on top
|
16 | of a Mersenne Twister so it can generate these things with repeatability, if
|
17 | desired.
|
18 |
|
19 | ## Packages
|
20 |
|
21 | ### Bower
|
22 |
|
23 | It can also be used with [Bower](http://bower.io)
|
24 |
|
25 | ```
|
26 | bower install chance
|
27 | ```
|
28 |
|
29 | then in the HTML of your app:
|
30 |
|
31 | ```html
|
32 | <!-- Load Chance -->
|
33 | <script type="text/javascript" src="app/bower_components/chance/chance.min.js"></script>
|
34 | <script>
|
35 | // Use Chance immediately!
|
36 | alert(chance.string());
|
37 | </script>
|
38 | ```
|
39 |
|
40 | ### npm
|
41 |
|
42 | ```shell
|
43 | npm install chance
|
44 | ```
|
45 |
|
46 | ### spm [![](http://spmjs.io/badge/chance)](http://spmjs.io/package/chance)
|
47 |
|
48 | It can also be used with [spm](http://spmjs.io/package/chance).
|
49 |
|
50 | ```
|
51 | spm install chance
|
52 | ```
|
53 |
|
54 | ## Usage
|
55 |
|
56 | ### Browser
|
57 |
|
58 | Chance instantiates itself onto the window. This means that in the simplest case you can just include the script tag then use an instance of Chance immediately.
|
59 |
|
60 | ```html
|
61 | <script src="chance.js"></script>
|
62 | <script>
|
63 | console.log(chance.string());
|
64 | </script>
|
65 | ```
|
66 |
|
67 | [More info](http://chancejs.com#browser)
|
68 |
|
69 | ### CLI
|
70 |
|
71 | Chance CLI has moved to its [own project](https://github.com/chancejs/chancejs-cli)!
|
72 |
|
73 | ### Node.js
|
74 |
|
75 | And it can be used in Node.js.
|
76 |
|
77 | ```js
|
78 | var Chance = require('chance'),
|
79 | chance = new Chance();
|
80 |
|
81 | // Get a random zip code
|
82 | chance.zip();
|
83 | ```
|
84 |
|
85 | ### RequireJS
|
86 |
|
87 | Chance also includes an AMD define so it can be used with RequireJS.
|
88 |
|
89 | ```js
|
90 | require(['Chance'], function(Chance) {
|
91 | // Instantiate
|
92 | var chance = new Chance();
|
93 |
|
94 | // Then just use it:
|
95 | var my_random_integer = chance.integer();
|
96 | });
|
97 | ```
|
98 |
|
99 | ## Dependent tools
|
100 |
|
101 | * [Chance CLI](https://github.com/chancejs/chance-cli) - Use Chance on the command line.
|
102 | * [Chance Token Replacer](https://github.com/drewbrokke/chance-token-replacer) - Replace tokens in a string with Chance generated items.
|
103 | * [Dream.js](https://github.com/adleroliveira/dreamjs) - Lightweight json data generator
|
104 | * [Fake JSON Schema](https://github.com/pateketrueke/json-schema-faker/) - Use chance generators to populate JSON Schema samples.
|
105 | * [Mocker Data Generator](https://github.com/danibram/mocker-data-generator/) - Minimal JSON data generator.
|
106 | * [swagger-mock-api](https://github.com/dzdrazil/swagger-mock-api/) - Generate API mocks from a Swagger spec file enriched with Chance types and constraints
|
107 | * [fony](https://github.com/captainsafia/fony) - A simple command line tool for generating fake data from a template string
|
108 |
|
109 | *Know a library that uses Chance that isn't here? Update the README and submit a PR!*
|
110 |
|
111 | ## Author
|
112 | ### Victor Quinn
|
113 | [https://www.victorquinn.com](https://www.victorquinn.com)
|
114 |
|
115 | Please feel free to reach out to me if you have any questions or suggestions.
|
116 |
|
117 | ### Contributors
|
118 |
|
119 | THANK YOU!
|
120 |
|
121 | ```
|
122 | project : chancejs
|
123 | repo age : 3 years, 1 month
|
124 | active : 195 days
|
125 | commits : 682
|
126 | files : 28
|
127 | authors :
|
128 | 446 Victor Quinn 65.4%
|
129 | 26 Oliver Salzburg 3.8%
|
130 | 13 Tim Petricola 1.9%
|
131 | 12 Alex DiLiberto 1.8%
|
132 | 11 davmillar 1.6%
|
133 | 11 Matteo Fogli 1.6%
|
134 | 7 Jan Tojnar 1.0%
|
135 | 7 AminaG 1.0%
|
136 | 7 jonbev 1.0%
|
137 | 6 Matt Klaber 0.9%
|
138 | 6 Patrick Mowrer 0.9%
|
139 | 5 Michael Cordingley 0.7%
|
140 | 4 Geoff Russel 0.6%
|
141 | 4 anio 0.6%
|
142 | 4 Chris Villarreal 0.6%
|
143 | 4 leesei 0.6%
|
144 | 4 Kevin Garnett 0.6%
|
145 | 4 Abhijeet Pawar 0.6%
|
146 | 4 spayton 0.6%
|
147 | 4 Dominic Barnes 0.6%
|
148 | 4 Avishaan 0.6%
|
149 | 3 Nicholas Johnson 0.4%
|
150 | 3 Nate Clark 0.4%
|
151 | 3 qjcg 0.4%
|
152 | 3 Alexandr Lozovyuk 0.4%
|
153 | 2 somejeff 0.3%
|
154 | 2 Rafael Andrade de Oliveira 0.3%
|
155 | 2 Kris Van Houten 0.3%
|
156 | 2 vird 0.3%
|
157 | 2 xshyamx 0.3%
|
158 | 2 Adam Krebs 0.3%
|
159 | 2 Franco Victorio 0.3%
|
160 | 2 The Usual Coder 0.3%
|
161 | 2 Michael Sakaluk 0.3%
|
162 | 2 Mihail Petrov 0.3%
|
163 | 2 Nathan MacInnes 0.3%
|
164 | 2 Ng Patrick 0.3%
|
165 | 2 dhilipsiva 0.3%
|
166 | 2 Stefan Penner 0.3%
|
167 | 2 Iskren Chernev 0.3%
|
168 | 2 Cube ix 0.3%
|
169 | 2 Daniel Biedma 0.3%
|
170 | 2 Pascal Borreli 0.3%
|
171 | 2 Andreas Koeberle 0.3%
|
172 | 2 SeeSchloss 0.3%
|
173 | 2 max4ever 0.3%
|
174 | 2 path411 0.3%
|
175 | 2 shyam 0.3%
|
176 | 1 mamrehn 0.1%
|
177 | 1 Adam Pointer 0.1%
|
178 | 1 Amit Merchant 0.1%
|
179 | 1 Billy Moon 0.1%
|
180 | 1 Bitdeli Chef 0.1%
|
181 | 1 Brian.Barnett 0.1%
|
182 | 1 Danny Yates 0.1%
|
183 | 1 Doug Lawrence 0.1%
|
184 | 1 Drew Brokke 0.1%
|
185 | 1 Eu Rafa 0.1%
|
186 | 1 Guillaume Bourel 0.1%
|
187 | 1 Hilke Heremans 0.1%
|
188 | 1 Jean Paulo de Almeida 0.1%
|
189 | 1 Johannes Stein 0.1%
|
190 | 1 Joshua Bemenderfer 0.1%
|
191 | 1 Matt Altermatt 0.1%
|
192 | 1 Piotrek Dąbrowski 0.1%
|
193 | 1 Richard Anaya 0.1%
|
194 | 1 Ryan Tenney 0.1%
|
195 | 1 Samuel Greene 0.1%
|
196 | 1 Thomas Rueckstiess 0.1%
|
197 | 1 Tomasz Ducin 0.1%
|
198 | 1 Winker Xiao 0.1%
|
199 | 1 afc163 0.1%
|
200 | 1 ddunning 0.1%
|
201 | 1 flaviolivolsi 0.1%
|
202 | 1 flrent 0.1%
|
203 | 1 kiran 0.1%
|
204 | 1 kkroner 0.1%
|
205 | 1 lkptrzk 0.1%
|
206 | 1 tsc 0.1%
|
207 | ```
|
208 |
|
209 | ### Contribute!
|
210 |
|
211 | Be a part of this project! You can run the test using the following.
|
212 |
|
213 | 1. Install dependencies from package.json by running `npm install`
|
214 | 2. Run the test via `npm test`
|
215 | 3. Make some fun new modules!
|
216 |
|
217 | *Note: Formerly, there was a `develop` branch where active development would
|
218 | happen, but now it's all on `master` baby. Just submit PRs directly to `master`.
|
219 | Sorry if the `develop` branch going away caused any trouble, but it was time to
|
220 | rip the bandaid off.*
|
221 |
|
222 | This project is licensed under the [MIT License](http://en.wikipedia.org/wiki/MIT_License) so feel free to hack away :)
|
223 |
|
224 | Proudly written in Washington, D.C.
|
225 |
|