Comparing version 1.1.11 to 1.1.12
@@ -9,2 +9,8 @@ # node | ||
or if you're using [yarn](https://yarnpkg.com/) | ||
```bash | ||
yarn add chance | ||
``` | ||
then in your app | ||
@@ -14,3 +20,3 @@ | ||
// Load Chance | ||
var Chance = require('chance'); | ||
var Chance = require("chance"); | ||
@@ -24,2 +30,15 @@ // Instantiate Chance so it can be used | ||
Or if you're using ES6 | ||
```js | ||
// Load Chance | ||
import Chance from "chance"; | ||
// Instantiate Chance so it can be used | ||
const chance = new Chance(); | ||
// Use Chance here. | ||
const my_random_string = chance.string(); | ||
``` | ||
As of version 0.5.5, the following is also offered as a convenience for getting | ||
@@ -30,3 +49,3 @@ an instance of Chance | ||
// Load and instantiate Chance | ||
var chance = require('chance').Chance(); | ||
var chance = require("chance").Chance(); | ||
@@ -33,0 +52,0 @@ // Use Chance here. |
@@ -11,3 +11,3 @@ # color | ||
Return a random color. | ||
Return a random color in a random format. | ||
@@ -19,3 +19,3 @@ ```js | ||
Colors have four base types: `hex`, `shorthex`, `rgb`, `0x` | ||
Colors have six base types: `hex`, `shorthex`, `rgb`, `rgba`, `0x`, `name` | ||
@@ -34,4 +34,10 @@ These are the kinds usable in HTML or CSS. The type can optionally be specified | ||
chance.color({ format:'rgba' }) | ||
=> 'rgba(76,11,110,0.1284)' | ||
chance.color({format: '0x'}) | ||
=> '0x67ae0b' | ||
chance.color({ format:'name' }) | ||
=> 'DarkOrange' | ||
``` | ||
@@ -38,0 +44,0 @@ |
@@ -8,3 +8,3 @@ # tld | ||
Return a random tld ([Top Level Domain][tld]) from the set: | ||
Return a random tld ([Top Level Domain][tld]) from the list of 2-letter country tld list plus the following set: | ||
@@ -11,0 +11,0 @@ ```js |
{ | ||
"name": "chance", | ||
"main": "./chance.js", | ||
"version": "1.1.11", | ||
"version": "1.1.12", | ||
"description": "Chance - Utility library to generate anything random", | ||
@@ -19,7 +19,5 @@ "homepage": "http://chancejs.com", | ||
"babel-eslint": "^7.2.3", | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.11.2", | ||
"dirty-chai": "^1.2.2", | ||
"docpress": "0.7.1", | ||
"eslint": "^6.3.0", | ||
"eslint": "^7.2.3", | ||
"git-update-ghpages": "1.3.0", | ||
@@ -29,9 +27,8 @@ "gulp": "^4.0.0", | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-jshint": "^2.0.4", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-sourcemaps": "^2.6.1", | ||
"jshint-stylish": "^2.2.1", | ||
"lodash": "^4.17.4", | ||
"gulp-rename": "^1.4.0", | ||
"gulp-sourcemaps": "^2.6.5", | ||
"gulp-uglify-es": "^3.0.0", | ||
"lodash": "^4.17.21", | ||
"nyc": "^10.3.2", | ||
"pump": "^1.0.2" | ||
"pump": "^1.0.3" | ||
}, | ||
@@ -55,5 +52,2 @@ "scripts": { | ||
], | ||
"jam": { | ||
"main": "chance.js" | ||
}, | ||
"github": "https://github.com/chancejs/chancejs", | ||
@@ -67,8 +61,2 @@ "maintainers": [ | ||
], | ||
"spm": { | ||
"main": "chance.js", | ||
"ignore": [ | ||
"test" | ||
] | ||
}, | ||
"docpress": { | ||
@@ -84,6 +72,3 @@ "scripts": [ | ||
] | ||
}, | ||
"devDependencies": { | ||
"gulp-uglify-es": "^3.0.0" | ||
} | ||
} |
@@ -52,4 +52,6 @@ # Chance | ||
1. Install dependencies from package.json by running `npm install` | ||
2. Run the test via `npm test` | ||
**Note: Make sure you have Yarn installed globally** | ||
1. Install dependencies from package.json by running ```yarn``` | ||
2. Run the test suite via ```yarn test``` | ||
3. Make some fun new modules! | ||
@@ -56,0 +58,0 @@ |
@@ -52,2 +52,48 @@ import test from 'ava' | ||
}) | ||
}) | ||
}) | ||
//chance.music_genre() | ||
const music_genres = [ | ||
'Rock', | ||
'Pop', | ||
'Hip-Hop', | ||
'Jazz', | ||
'Classical', | ||
'Electronic', | ||
'Country', | ||
'R&B', | ||
'Reggae', | ||
'Blues', | ||
'Metal', | ||
'Folk', | ||
'Alternative', | ||
'Punk', | ||
'Disco', | ||
'Funk', | ||
'Techno', | ||
'Indie', | ||
'Gospel', | ||
'Dance', | ||
'Children\'s', | ||
'World' | ||
] | ||
test('music_genre() returns an error if category given is invalid', t => { | ||
t.throws(() => { | ||
chance.music_genre('UnknownGenre'); | ||
}, Error); | ||
}) | ||
test('music_genre() returns a valid genre for general category', t => { | ||
const randomGenre = chance.music_genre('general'); | ||
t.true(typeof randomGenre === 'string'); | ||
}); | ||
music_genres.forEach(category => { | ||
test(`music_genre() returns a valid genre in the ${category} category`, t => { | ||
const genre = chance.music_genre(category.toLowerCase()); | ||
t.true(typeof genre === 'string'); | ||
}); | ||
}) | ||
@@ -124,1 +124,38 @@ import test from 'ava' | ||
}) | ||
test('emoji() will return a single emoji by default', t => { | ||
let emoji = chance.emoji(); | ||
t.true(_.isString(emoji)); | ||
t.is([...emoji].length, 1); | ||
}) | ||
test('emoji() will return as many emojis as you tell it to', t => { | ||
_.times(100, () => { | ||
let rand = _.random(1, 50); | ||
let emoji = chance.emoji({ length: rand }); | ||
t.true(_.isString(emoji)); | ||
t.is([...emoji].length, rand); | ||
}) | ||
}) | ||
test('emoji() will throw an error when category is unrecognised', t => { | ||
let fn = () => chance.emoji({ category: 'something-incorrect' }); | ||
t.throws(fn, "Chance: Unrecognised emoji category: [something-incorrect]."); | ||
}) | ||
test('emoji() will throw an error when length is 0', t => { | ||
let fn = () => chance.emoji({ length: 0 }); | ||
t.throws(fn, "Chance: length must be between 1 and 9007199254740992"); | ||
}) | ||
test('emoji() will throw an error when length is negative', t => { | ||
let fn = () => chance.emoji({ length: -1 }); | ||
t.throws(fn, "Chance: length must be between 1 and 9007199254740992"); | ||
}) | ||
test('emoji() will throw an error when length is greater than 9007199254740992', t => { | ||
let fn = () => chance.emoji({ length: BigInt('9007199254740993') }); | ||
t.throws(fn, "Chance: length must be between 1 and 9007199254740992"); | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
2134074
164
24290
62
15