alea-deck 2.0.0 → 2.0.1

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–2015 Kenan Yildirim <http://kenany.me/>
1
+ Copyright 2014–2021 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
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": "2.0.0",
3
+ "version": "2.0.1",
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,33 @@
18
18
  "directories": {
19
19
  "test": "test"
20
20
  },
21
+ "engines": {
22
+ "node": "10 || 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": "^2.0.0",
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": "^2.1.6",
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": "^4.2.2"
38
+ "@kenan/eslint-config": "^9.0.4",
39
+ "@kenan/renovate-config": "^1.5.1",
40
+ "@semantic-release/changelog": "^6.0.1",
41
+ "@semantic-release/git": "^10.0.1",
42
+ "conventional-changelog-conventionalcommits": "^4.6.1",
43
+ "eslint": "^7.32.0",
44
+ "lodash.every": "^4.6.0",
45
+ "lodash.isundefined": "^3.0.1",
46
+ "lodash.map": "^4.6.0",
47
+ "semantic-release": "^18.0.1",
48
+ "tape": "^5.3.1"
37
49
  }
38
50
  }