random-weighted-pick 1.0.12 → 2.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.
@@ -1,194 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <title>Code coverage report for src/weightList.js</title>
5
- <meta charset="utf-8" />
6
- <link rel="stylesheet" href="../prettify.css" />
7
- <link rel="stylesheet" href="../base.css" />
8
- <meta name="viewport" content="width=device-width, initial-scale=1">
9
- <style type='text/css'>
10
- .coverage-summary .sorter {
11
- background-image: url(../sort-arrow-sprite.png);
12
- }
13
- </style>
14
- </head>
15
- <body>
16
- <div class='wrapper'>
17
- <div class='pad1'>
18
- <h1>
19
- <a href="../index.html">All files</a> / <a href="index.html">src</a> weightList.js
20
- </h1>
21
- <div class='clearfix'>
22
- <div class='fl pad1y space-right2'>
23
- <span class="strong">100% </span>
24
- <span class="quiet">Statements</span>
25
- <span class='fraction'>33/33</span>
26
- </div>
27
- <div class='fl pad1y space-right2'>
28
- <span class="strong">100% </span>
29
- <span class="quiet">Branches</span>
30
- <span class='fraction'>6/6</span>
31
- </div>
32
- <div class='fl pad1y space-right2'>
33
- <span class="strong">100% </span>
34
- <span class="quiet">Functions</span>
35
- <span class='fraction'>12/12</span>
36
- </div>
37
- <div class='fl pad1y space-right2'>
38
- <span class="strong">100% </span>
39
- <span class="quiet">Lines</span>
40
- <span class='fraction'>24/24</span>
41
- </div>
42
- </div>
43
- </div>
44
- <div class='status-line high'></div>
45
- <pre><table class="coverage">
46
- <tr><td class="line-count quiet">1
47
- 2
48
- 3
49
- 4
50
- 5
51
- 6
52
- 7
53
- 8
54
- 9
55
- 10
56
- 11
57
- 12
58
- 13
59
- 14
60
- 15
61
- 16
62
- 17
63
- 18
64
- 19
65
- 20
66
- 21
67
- 22
68
- 23
69
- 24
70
- 25
71
- 26
72
- 27
73
- 28
74
- 29
75
- 30
76
- 31
77
- 32
78
- 33
79
- 34
80
- 35
81
- 36
82
- 37
83
- 38
84
- 39
85
- 40
86
- 41
87
- 42
88
- 43
89
- 44</td><td class="line-coverage quiet"><span class="cline-any cline-yes">2140978x</span>
90
- <span class="cline-any cline-neutral">&nbsp;</span>
91
- <span class="cline-any cline-yes">3700401x</span>
92
- <span class="cline-any cline-neutral">&nbsp;</span>
93
- <span class="cline-any cline-yes">1x</span>
94
- <span class="cline-any cline-yes">7400805x</span>
95
- <span class="cline-any cline-neutral">&nbsp;</span>
96
- <span class="cline-any cline-yes">2x</span>
97
- <span class="cline-any cline-neutral">&nbsp;</span>
98
- <span class="cline-any cline-yes">500203x</span>
99
- <span class="cline-any cline-yes">1000405x</span>
100
- <span class="cline-any cline-yes">2x</span>
101
- <span class="cline-any cline-neutral">&nbsp;</span>
102
- <span class="cline-any cline-yes">1000403x</span>
103
- <span class="cline-any cline-neutral">&nbsp;</span>
104
- <span class="cline-any cline-neutral">&nbsp;</span>
105
- <span class="cline-any cline-yes">2x</span>
106
- <span class="cline-any cline-neutral">&nbsp;</span>
107
- <span class="cline-any cline-yes">1x</span>
108
- <span class="cline-any cline-neutral">&nbsp;</span>
109
- <span class="cline-any cline-yes">500204x</span>
110
- <span class="cline-any cline-yes">1x</span>
111
- <span class="cline-any cline-neutral">&nbsp;</span>
112
- <span class="cline-any cline-neutral">&nbsp;</span>
113
- <span class="cline-any cline-yes">500203x</span>
114
- <span class="cline-any cline-neutral">&nbsp;</span>
115
- <span class="cline-any cline-yes">500201x</span>
116
- <span class="cline-any cline-yes">3700401x</span>
117
- <span class="cline-any cline-yes">500201x</span>
118
- <span class="cline-any cline-yes">500201x</span>
119
- <span class="cline-any cline-neutral">&nbsp;</span>
120
- <span class="cline-any cline-neutral">&nbsp;</span>
121
- <span class="cline-any cline-yes">500201x</span>
122
- <span class="cline-any cline-neutral">&nbsp;</span>
123
- <span class="cline-any cline-yes">500200x</span>
124
- <span class="cline-any cline-yes">2140978x</span>
125
- <span class="cline-any cline-yes">2140978x</span>
126
- <span class="cline-any cline-yes">2140978x</span>
127
- <span class="cline-any cline-neutral">&nbsp;</span>
128
- <span class="cline-any cline-yes">500200x</span>
129
- <span class="cline-any cline-neutral">&nbsp;</span>
130
- <span class="cline-any cline-neutral">&nbsp;</span>
131
- <span class="cline-any cline-neutral">&nbsp;</span>
132
- <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">const selectOption = (arr, i) =&gt; ({ id: arr[i].id, item: arr[i].item });
133
- &nbsp;
134
- const getProp = (arr, prop) =&gt; arr.map(opt =&gt; opt[prop]);
135
- &nbsp;
136
- const checkProperty = (arr, prop) =&gt;
137
- arr.every(item =&gt; Object.prototype.hasOwnProperty.call(item, prop));
138
- &nbsp;
139
- const propErrorMsg = prop =&gt; `Every list item should have [${prop}] property`;
140
- &nbsp;
141
- const checkProperties = (options, props) =&gt; props.map((prop) =&gt; {
142
- if (!checkProperty(options, prop)) {
143
- throw new TypeError(propErrorMsg(prop));
144
- }
145
- return true;
146
- });
147
- &nbsp;
148
- const throwTypeError = (msg) =&gt; { throw new TypeError(msg); };
149
- &nbsp;
150
- const weightedList = (options) =&gt; {
151
- &nbsp;
152
- if (!Array.isArray(options)) {
153
- return throwTypeError('Weighted List expect Array of Objects as argument');
154
- }
155
- &nbsp;
156
- checkProperties(options, ['weight', 'item']);
157
- &nbsp;
158
- const weights = getProp(options, 'weight');
159
- const totalWeights = Number(weights.reduce((a, b) =&gt; a + b, 0).toPrecision(1));
160
- const num = Math.random();
161
- let set = 0;
162
- let selected;
163
- &nbsp;
164
- if (totalWeights !== 1) throwTypeError("Sum of 'weights' should be equal 1");
165
- &nbsp;
166
- weights.some((weight, i) =&gt; {
167
- set += weight;
168
- selected = selectOption(options, i);
169
- return num &lt; set;
170
- });
171
- return selected;
172
- };
173
- &nbsp;
174
- export default weightedList;
175
- &nbsp;</pre></td></tr>
176
- </table></pre>
177
- <div class='push'></div><!-- for sticky footer -->
178
- </div><!-- /wrapper -->
179
- <div class='footer quiet pad2 space-top1 center small'>
180
- Code coverage
181
- generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Feb 19 2018 08:26:02 GMT-0300 (-03)
182
- </div>
183
- </div>
184
- <script src="../prettify.js"></script>
185
- <script>
186
- window.onload = function () {
187
- if (typeof prettyPrint === 'function') {
188
- prettyPrint();
189
- }
190
- };
191
- </script>
192
- <script src="../sorter.js"></script>
193
- </body>
194
- </html>
@@ -1,106 +0,0 @@
1
- TN:
2
- SF:/home/phellipe/Documents/GIT/personal/probabilities/src/weightList.js
3
- FN:1,(anonymous_0)
4
- FN:3,(anonymous_1)
5
- FN:3,(anonymous_2)
6
- FN:5,(anonymous_3)
7
- FN:6,(anonymous_4)
8
- FN:8,(anonymous_5)
9
- FN:10,(anonymous_6)
10
- FN:10,(anonymous_7)
11
- FN:17,(anonymous_8)
12
- FN:19,(anonymous_9)
13
- FN:28,(anonymous_10)
14
- FN:35,(anonymous_11)
15
- FNF:12
16
- FNH:12
17
- FNDA:2140978,(anonymous_0)
18
- FNDA:500201,(anonymous_1)
19
- FNDA:3700401,(anonymous_2)
20
- FNDA:1000405,(anonymous_3)
21
- FNDA:7400805,(anonymous_4)
22
- FNDA:2,(anonymous_5)
23
- FNDA:500203,(anonymous_6)
24
- FNDA:1000405,(anonymous_7)
25
- FNDA:2,(anonymous_8)
26
- FNDA:500204,(anonymous_9)
27
- FNDA:3700401,(anonymous_10)
28
- FNDA:2140978,(anonymous_11)
29
- DA:1,2140978
30
- DA:3,3700401
31
- DA:5,1
32
- DA:6,7400805
33
- DA:8,2
34
- DA:10,500203
35
- DA:11,1000405
36
- DA:12,2
37
- DA:14,1000403
38
- DA:17,2
39
- DA:19,1
40
- DA:21,500204
41
- DA:22,1
42
- DA:25,500203
43
- DA:27,500201
44
- DA:28,3700401
45
- DA:29,500201
46
- DA:30,500201
47
- DA:33,500201
48
- DA:35,500200
49
- DA:36,2140978
50
- DA:37,2140978
51
- DA:38,2140978
52
- DA:40,500200
53
- LF:24
54
- LH:24
55
- BRDA:11,0,0,2
56
- BRDA:11,0,1,1000403
57
- BRDA:21,1,0,1
58
- BRDA:21,1,1,500203
59
- BRDA:33,2,0,1
60
- BRDA:33,2,1,500200
61
- BRF:6
62
- BRH:6
63
- end_of_record
64
- TN:
65
- SF:/home/phellipe/Documents/GIT/personal/probabilities/src/utils/tests.utils.js
66
- FN:5,(anonymous_0)
67
- FN:9,(anonymous_1)
68
- FN:9,(anonymous_2)
69
- FN:14,(anonymous_3)
70
- FN:16,(anonymous_4)
71
- FN:18,(anonymous_5)
72
- FN:21,(anonymous_6)
73
- FN:21,(anonymous_7)
74
- FNF:8
75
- FNH:7
76
- FNDA:6,(anonymous_0)
77
- FNDA:5,(anonymous_1)
78
- FNDA:500000,(anonymous_2)
79
- FNDA:5,(anonymous_3)
80
- FNDA:0,(anonymous_4)
81
- FNDA:5,(anonymous_5)
82
- FNDA:5,(anonymous_6)
83
- FNDA:500000,(anonymous_7)
84
- DA:3,1
85
- DA:5,6
86
- DA:7,1
87
- DA:9,5
88
- DA:10,500000
89
- DA:11,500000
90
- DA:14,5
91
- DA:16,1
92
- DA:18,1
93
- DA:19,5
94
- DA:21,500000
95
- LF:11
96
- LH:11
97
- BRDA:5,0,0,6
98
- BRDA:5,0,1,1
99
- BRDA:10,1,0,500000
100
- BRDA:10,1,1,36
101
- BRDA:14,2,0,5
102
- BRDA:14,2,1,5
103
- BRDA:18,3,0,5
104
- BRF:7
105
- BRH:7
106
- end_of_record
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babel-polyfill")):"function"==typeof define&&define.amd?define("weightedPick",["babel-polyfill"],t):"object"==typeof exports?exports.weightedPick=t(require("babel-polyfill")):e.weightedPick=t(e["babel-polyfill"])}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){r(3),e.exports=r(1)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}var o=r(2),i=n(o);e.exports=i.default},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t){return{id:e[t].id,item:e[t].item}},n=function(e,t){return e.map(function(e){return e[t]})},o=function(e,t){return e.every(function(e){return Object.prototype.hasOwnProperty.call(e,t)})},i=function(e){return"Every list item should have ["+e+"] property"},u=function(e,t){return t.map(function(t){if(!o(e,t))throw new TypeError(i(t));return!0})},f=function(e){throw new TypeError(e)},c=function(e){if(!Array.isArray(e))return f("Weighted List expect Array of Objects as argument");u(e,["weight","item"]);var t=n(e,"weight"),o=Number(t.reduce(function(e,t){return e+t},0).toPrecision(1)),i=Math.random(),c=0,l=void 0;return 1!==o&&f("Sum of 'weights' should be equal 1"),t.some(function(t,n){return c+=t,l=r(e,n),i<c}),l};t.default=c},function(e,t){e.exports=require("babel-polyfill")}])});
@@ -1,18 +0,0 @@
1
- import fs from 'fs-extra';
2
-
3
- // to delete existing built bundle with windows environment
4
- function emptyDist() {
5
- return new Promise((resolve, reject) => {
6
- fs.emptyDir('../../dist', (err) => {
7
- if (err) {
8
- console.error(err);
9
- reject();
10
- } else {
11
- console.log('emptying dist directory job is done');
12
- resolve();
13
- }
14
- });
15
- });
16
- }
17
-
18
- emptyDist();
package/webpack.config.js DELETED
@@ -1,46 +0,0 @@
1
- const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
2
- const DashboardPlugin = require('webpack-dashboard/plugin');
3
- const nodeExternals = require('webpack-node-externals');
4
-
5
- const path = require('path');
6
- const webpack = require('webpack');
7
-
8
- module.exports = {
9
- // devtool: 'source-map',
10
- entry: [
11
- 'babel-polyfill',
12
- 'webpack/hot/dev-server',
13
- './src',
14
- ],
15
- output: {
16
- path: path.resolve('./dist'),
17
- filename: 'index.js',
18
- library: 'weightedPick',
19
- libraryTarget: 'umd',
20
- umdNamedDefine: true,
21
- },
22
- target: 'node',
23
- externals: [nodeExternals()],
24
- resolve: {
25
- modulesDirectories: ['node_modules'],
26
- extensions: ['', '.js'],
27
- },
28
- module: {
29
- loaders: [
30
- {
31
- test: [/\.js?$/],
32
- exclude: [/node_modules/, '/**/*.test.js'],
33
- loader: 'babel',
34
- query: {
35
- presets: ['env'],
36
- },
37
- },
38
- ],
39
- },
40
- plugins: [
41
- new webpack.NoErrorsPlugin(),
42
- new webpack.HotModuleReplacementPlugin(),
43
- new BundleAnalyzerPlugin(),
44
- new DashboardPlugin(),
45
- ],
46
- };
@@ -1,31 +0,0 @@
1
- const webpack = require('webpack');
2
- const webpackSettings = require('./webpack.config');
3
-
4
- const optimizingPlugins = [
5
- new webpack.DefinePlugin({
6
- 'process.env.NODE_ENV': '"production"',
7
- }),
8
- new webpack.optimize.OccurrenceOrderPlugin(),
9
- new webpack.optimize.UglifyJsPlugin({
10
- comments: false,
11
- compress: {
12
- unused: true,
13
- dead_code: true,
14
- warnings: false,
15
- drop_debugger: true,
16
- conditionals: true,
17
- evaluate: true,
18
- drop_console: true,
19
- sequences: true,
20
- booleans: true,
21
- },
22
- }),
23
- new webpack.optimize.DedupePlugin(),
24
- ];
25
-
26
- webpackSettings.plugins = optimizingPlugins;
27
- webpackSettings.entry = webpackSettings.entry.filter((entryName) => {
28
- return (entryName.indexOf('hot/dev-server') === -1);
29
- });
30
-
31
- module.exports = webpackSettings;