alea-deck 1.1.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2014 Kenan Yildirim <http://kenany.me/>
1
+ Copyright 2014–2022 Kenan Yildirim <https://kenany.me/>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
@@ -15,4 +15,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
15
  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
16
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
17
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # alea-deck
2
2
 
3
- [![build status](https://img.shields.io/travis/KenanY/alea-deck.svg)](https://travis-ci.org/KenanY/alea-deck)
4
- [![dependency status](https://img.shields.io/gemnasium/KenanY/alea-deck.svg)](https://gemnasium.com/KenanY/alea-deck)
5
-
6
3
  Uniform and weighted shuffling and sampling, just like
7
4
  [deck](https://github.com/substack/node-deck), but utilizing
8
5
  [Alea](https://github.com/coverslide/node-alea) instead of `Math.random`.
@@ -72,4 +69,4 @@ Otherwise, if `collection` is an _Object_, returns a random key from
72
69
  Return a new `obj` _Object_ where the values have been divided by the sum of all
73
70
  the values such that the sum of all the values in the returned _Object_ is 1.
74
71
 
75
- If any weights are `< 0`, an _Error_ is thrown.
72
+ If any weights are `< 0`, an _Error_ is thrown.
package/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  var random = require('alea-random');
2
- var isArray = require('lodash.isarray');
3
2
  var isPlainObject = require('lodash.isplainobject');
4
3
  var keys = require('lodash.keys');
5
4
  var reduce = require('lodash.reduce');
6
5
  var isNumber = require('lodash.isnumber');
7
6
 
8
7
  function deck(xs) {
9
- if (!isArray(xs) && !isPlainObject(xs)) {
8
+ if (!Array.isArray(xs) && !isPlainObject(xs)) {
10
9
  throw new TypeError('Must be an Array or an Object');
11
10
  }
12
11
 
@@ -17,7 +16,7 @@ function deck(xs) {
17
16
  }
18
17
 
19
18
  function shuffle(xs) {
20
- if (isArray(xs)) {
19
+ if (Array.isArray(xs)) {
21
20
  var res = xs.slice();
22
21
  for (var i = res.length - 1; i >= 0; i--) {
23
22
  var n = Math.floor(random(true) * i);
@@ -49,7 +48,7 @@ function shuffle(xs) {
49
48
  }
50
49
 
51
50
  function pick(xs) {
52
- if (isArray(xs)) {
51
+ if (Array.isArray(xs)) {
53
52
  return xs[Math.floor(random(true) * xs.length)];
54
53
  }
55
54
  else if (isPlainObject(xs)) {
@@ -77,7 +76,7 @@ function pick(xs) {
77
76
 
78
77
  function normalize(weights) {
79
78
  if (!isPlainObject(weights)) {
80
- throw 'Not an Object';
79
+ throw new TypeError('`weights` must be an object');
81
80
  }
82
81
 
83
82
  var keyz = keys(weights);
@@ -101,12 +100,12 @@ function normalize(weights) {
101
100
  return total === 1
102
101
  ? weights
103
102
  : reduce(keyz, function(acc, key) {
104
- acc[key] = weights[key] / total;
105
- return acc;
106
- }, {});
103
+ acc[key] = weights[key] / total;
104
+ return acc;
105
+ }, {});
107
106
  }
108
107
 
109
108
  module.exports = deck;
110
109
  module.exports.shuffle = shuffle;
111
110
  module.exports.pick = pick;
112
- module.exports.normalize = normalize;
111
+ module.exports.normalize = normalize;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alea-deck",
3
- "version": "1.1.6",
3
+ "version": "3.0.0",
4
4
  "description": "Uniform and weighted shuffling and sampling with Alea",
5
5
  "keywords": [
6
6
  "alea",
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "repository": "KenanY/alea-deck",
11
11
  "license": "MIT",
12
- "author": "Kenan Yildirim <kenan@kenany.me> (http://kenany.me/)",
12
+ "author": "Kenan Yildirim <kenan@kenany.me> (https://kenany.me/)",
13
13
  "main": "index.js",
14
14
  "files": [
15
15
  "index.js",
@@ -18,21 +18,32 @@
18
18
  "directories": {
19
19
  "test": "test"
20
20
  },
21
+ "engines": {
22
+ "node": "12 || 14 || >=16"
23
+ },
21
24
  "scripts": {
22
- "test": "tape test/*.js"
25
+ "lint": "eslint *.js test/*.js",
26
+ "test": "tape test/*.js",
27
+ "posttest": "npm run lint",
28
+ "release": "semantic-release"
23
29
  },
24
30
  "dependencies": {
25
- "alea-random": "^1.1.1",
26
- "lodash.isarray": "^3.0.0",
27
- "lodash.isnumber": "^3.0.0",
28
- "lodash.isplainobject": "^3.0.0",
29
- "lodash.keys": "^3.0.4",
30
- "lodash.reduce": "^3.0.0"
31
+ "alea-random": "^3.0.0",
32
+ "lodash.isnumber": "^3.0.3",
33
+ "lodash.isplainobject": "^4.0.6",
34
+ "lodash.keys": "^4.2.0",
35
+ "lodash.reduce": "^4.6.0"
31
36
  },
32
37
  "devDependencies": {
33
- "lodash.every": "^3.0.0",
34
- "lodash.isundefined": "^3.0.0",
35
- "lodash.map": "^3.0.0",
36
- "tape": "^3.0.3"
38
+ "@kenan/eslint-config": "^9.0.4",
39
+ "@semantic-release/changelog": "^6.0.1",
40
+ "@semantic-release/git": "^10.0.1",
41
+ "conventional-changelog-conventionalcommits": "^4.6.3",
42
+ "eslint": "^7.32.0",
43
+ "lodash.every": "^4.6.0",
44
+ "lodash.isundefined": "^3.0.1",
45
+ "lodash.map": "^4.6.0",
46
+ "semantic-release": "^19.0.2",
47
+ "tape": "^5.5.0"
37
48
  }
38
49
  }