SB-6.1-PRE
This commit is contained in:
1 parent
690169a409
commit
358a25f522
3760 files changed
+300059
-36
No files matched your search
+13
@@ -0,0 +1,13 @@
|
||||
# ampm
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.ampm()
|
||||
```
|
||||
|
||||
Return am or pm. Very simple.
|
||||
|
||||
```js
|
||||
chance.ampm();
|
||||
=> 'am'
|
||||
```
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
# date
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.date()
|
||||
chance.date({string: true})
|
||||
chance.date({string: true, american: false})
|
||||
chance.date({year: 1983})
|
||||
```
|
||||
|
||||
Generate a random date
|
||||
|
||||
```js
|
||||
chance.date();
|
||||
=> Sat Apr 09 2072 00:00:00 GMT-0400 (EDT)
|
||||
```
|
||||
|
||||
By default, returns an actual [Date][Date] object
|
||||
|
||||
Can optionally specify that a date be returned as a string
|
||||
|
||||
```js
|
||||
chance.date({string: true});
|
||||
=> "5/27/2078"
|
||||
```
|
||||
|
||||
This will return a date string of the format MM/DD/YYYY.
|
||||
|
||||
Now of course MM/DD/YYYY is the "American" date method, but it's the default
|
||||
because there isn't much support for internationalization here yet. Further,
|
||||
it's the format used by [Facebook][FB] and other services for birthdays and
|
||||
other non-Date object dates.
|
||||
|
||||
However, we support returning dates in DD/MM/YYYY format as well when requesting
|
||||
a date by a string and passing `american: false`.
|
||||
|
||||
```js
|
||||
chance.date({string: true, american: false});
|
||||
=> "13/2/2017"
|
||||
```
|
||||
|
||||
If you want richer control over date format, strongly suggest using the
|
||||
[Moment][Moment] library. Our formatting is very minimalist, and it's out of our
|
||||
core competency to offer dates in a myriad of formats.
|
||||
|
||||
Can optionally specify defaults for any of day, month, or year.
|
||||
|
||||
```js
|
||||
chance.date({year: 1983});
|
||||
=> Wed May 04 1983 00:00:00 GMT-0400 (EDT)
|
||||
|
||||
chance.date({month: 0});
|
||||
=> Tue Jan 18 2084 00:00:00 GMT-0500 (EST)
|
||||
|
||||
chance.date({day: 21});
|
||||
=> Sun Oct 21 2103 00:00:00 GMT-0400 (EDT)
|
||||
```
|
||||
|
||||
A random date is generated, but the default you specify is kept constant.
|
||||
|
||||
Note, month is 0-indexed. This is a carryover from the core JavaScript
|
||||
[Date][Date] object which we use internally to generate the date. We
|
||||
considered
|
||||
|
||||
[Date]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
|
||||
[FB]: https://developers.facebook.com/docs/reference/api/user/
|
||||
[Moment]: http://momentjs.com
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
# hammertime
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.hammertime()
|
||||
```
|
||||
|
||||
<p class="pullquote" data-pullquote='Stop. Hammertime.' markdown="1"></p>
|
||||
|
||||
Generate a random hammertime.
|
||||
|
||||
```js
|
||||
chance.hammertime();
|
||||
=> 2273327300317
|
||||
```
|
||||
|
||||
Hammertime is the name given to a [Unix time](http://en.wikipedia.org/wiki/Unix_time) with
|
||||
milliseconds. Which is the same as saying the number of milliseconds since 1970. It has
|
||||
finer granularity than a normal Unix timestamp and thus is often used in realtime
|
||||
applications.
|
||||
|
||||
According to startup lore, Hammertime was coined by a startup whose founder had an
|
||||
interesting interaction with M.C. Hammer. There was no name given to "Unix time with
|
||||
milliseconds" and while brainstorming ideas (because Unix time with milliseconds is
|
||||
a confusing mouthful), someone suggested Hammertime and it stuck.
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
# hour
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.hour()
|
||||
chance.hour({twentyfour: true})
|
||||
```
|
||||
|
||||
Generate a random hour
|
||||
|
||||
```js
|
||||
chance.hour();
|
||||
=> 9
|
||||
```
|
||||
|
||||
By default, returns an hour from 1 to 12 for a standard [12-hour clock][12h].
|
||||
|
||||
Can optionally specify a full twenty-four.
|
||||
|
||||
```js
|
||||
chance.hour({twentyfour: true});
|
||||
=> 21
|
||||
```
|
||||
|
||||
This will return an hour from 1 to 24.
|
||||
|
||||
[12h]: https://en.wikipedia.org/wiki/12-hour_clock
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# millisecond
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.millisecond()
|
||||
```
|
||||
|
||||
Generate a random millisecond
|
||||
|
||||
```js
|
||||
chance.millisecond();
|
||||
=> 729
|
||||
```
|
||||
|
||||
By default, returns a millisecond from 0 to 999. Idea is for generating a clock time.
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# minute
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.minute()
|
||||
```
|
||||
|
||||
Generate a random minute
|
||||
|
||||
```js
|
||||
chance.minute();
|
||||
=> 35
|
||||
```
|
||||
|
||||
By default, returns a minute from 0 to 59. Idea is for generating a clock time.
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
# month
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.month()
|
||||
```
|
||||
|
||||
Generate a random month.
|
||||
|
||||
```js
|
||||
chance.month();
|
||||
=> 'January'
|
||||
```
|
||||
|
||||
By default, returns just the full name.
|
||||
|
||||
Optionally specify raw to get the whole month object consisting of name,
|
||||
short_name, and numeric.
|
||||
|
||||
```js
|
||||
chance.month({raw: true});
|
||||
=> {name: 'October', short_name: 'Oct', numeric: '10'}
|
||||
```
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# second
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.second()
|
||||
```
|
||||
|
||||
Generate a random second
|
||||
|
||||
```js
|
||||
chance.second();
|
||||
=> 19
|
||||
```
|
||||
|
||||
By default, returns a second from 0 to 59. Idea is for generating a clock time.
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
# timestamp
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.timestamp()
|
||||
```
|
||||
|
||||
Generate a random timestamp. This is a standard Unix time, so a random number of
|
||||
seconds since January 1, 1970.
|
||||
|
||||
```js
|
||||
chance.timestamp();
|
||||
=> 576556683
|
||||
```
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
# timezone
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.timezone()
|
||||
```
|
||||
|
||||
Return a random timezone
|
||||
|
||||
```js
|
||||
chance.timezone();
|
||||
=> {
|
||||
"name": "India Standard Time",
|
||||
"abbr": "IST",
|
||||
"offset": 5.5,
|
||||
"isdst": false,
|
||||
"text": "(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi",
|
||||
"utc": ["Asia/Calcutta"]
|
||||
}
|
||||
```
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
# weekday
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.weekday()
|
||||
chance.weekday({weekday_only: true})
|
||||
```
|
||||
|
||||
Return a weekday
|
||||
|
||||
```js
|
||||
chance.weekday();
|
||||
=> 'Tuesday'
|
||||
```
|
||||
|
||||
By default, weekday_only is false. If set to true it will never return Saturday or Sunday.
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
# year
|
||||
|
||||
```js
|
||||
// usage
|
||||
chance.year()
|
||||
chance.year({min: 1900, max: 2100})
|
||||
```
|
||||
|
||||
Generate a random year
|
||||
|
||||
```js
|
||||
chance.year();
|
||||
=> '2053'
|
||||
```
|
||||
|
||||
By default, min is the current year and max is 100 years greater than min.
|
||||
|
||||
This is returned as a string. If for some reason you need it numeric, just
|
||||
parse it:
|
||||
|
||||
```js
|
||||
parseInt(chance.year());
|
||||
=> 2042
|
||||
```
|
||||
|
||||
Optionally specify min, max, or both to limit the range.
|
||||
|
||||
```js
|
||||
chance.year({min: 1900, max: 2100});
|
||||
=> '1983'
|
||||
```
|
||||
Reference in new issue
Block a user