@stdlib/random-streams-invgamma 0.0.7 → 0.2.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 +0 -304
- package/NOTICE +1 -1
- package/README.md +34 -87
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +18 -18
- package/lib/factory.js +12 -3
- package/lib/index.js +4 -4
- package/lib/main.js +5 -4
- package/lib/object_mode.js +4 -3
- package/lib/validate.js +9 -8
- package/package.json +24 -51
- package/bin/cli +0 -194
- package/docs/repl.txt +0 -262
- package/docs/types/test.ts +0 -135
- package/docs/usage.txt +0 -15
- package/etc/cli_opts.json +0 -24
package/docs/types/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
// TypeScript Version:
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
20
|
|
|
21
21
|
/// <reference types="node"/>
|
|
22
22
|
/// <reference types="@stdlib/types"/>
|
|
@@ -96,7 +96,7 @@ declare class RandomStream extends Readable {
|
|
|
96
96
|
* @returns stream instance
|
|
97
97
|
*
|
|
98
98
|
* @example
|
|
99
|
-
* var inspectStream = require(
|
|
99
|
+
* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );
|
|
100
100
|
*
|
|
101
101
|
* function log( chunk ) {
|
|
102
102
|
* console.log( chunk.toString() );
|
|
@@ -115,37 +115,37 @@ declare class RandomStream extends Readable {
|
|
|
115
115
|
/**
|
|
116
116
|
* Destruction state.
|
|
117
117
|
*/
|
|
118
|
-
private readonly _destroyed: boolean;
|
|
118
|
+
private readonly _destroyed: boolean;
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
121
|
* Flag indicating whether a stream is operating in object mode.
|
|
122
122
|
*/
|
|
123
|
-
private readonly _objectMode: boolean;
|
|
123
|
+
private readonly _objectMode: boolean;
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
126
|
* Data separator.
|
|
127
127
|
*/
|
|
128
|
-
private readonly _sep: string;
|
|
128
|
+
private readonly _sep: string;
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
131
|
* Total number of iterations.
|
|
132
132
|
*/
|
|
133
|
-
private readonly _iter: number;
|
|
133
|
+
private readonly _iter: number;
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* Number of iterations after which to emit the underlying PRNG state.
|
|
137
137
|
*/
|
|
138
|
-
private readonly _siter: number;
|
|
138
|
+
private readonly _siter: number;
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* Iteration counter.
|
|
142
142
|
*/
|
|
143
|
-
private _i: number;
|
|
143
|
+
private _i: number;
|
|
144
144
|
|
|
145
145
|
/**
|
|
146
146
|
* Pseudorandom number generator for generating inverse gamma distributed pseudorandom numbers.
|
|
147
147
|
*/
|
|
148
|
-
private readonly _prng: random.PRNG;
|
|
148
|
+
private readonly _prng: random.PRNG;
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
151
|
* Underlying PRNG.
|
|
@@ -182,7 +182,7 @@ declare class RandomStream extends Readable {
|
|
|
182
182
|
*
|
|
183
183
|
* @param size - number (of bytes) to read
|
|
184
184
|
*/
|
|
185
|
-
_read( size: number ): void;
|
|
185
|
+
_read( size: number ): void;
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
188
|
* Gracefully destroys a stream, providing backward compatibility.
|
|
@@ -217,7 +217,7 @@ interface Constructor {
|
|
|
217
217
|
* @returns stream instance
|
|
218
218
|
*
|
|
219
219
|
* @example
|
|
220
|
-
* var inspectStream = require(
|
|
220
|
+
* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );
|
|
221
221
|
*
|
|
222
222
|
* function log( chunk ) {
|
|
223
223
|
* console.log( chunk.toString() );
|
|
@@ -246,7 +246,7 @@ interface Constructor {
|
|
|
246
246
|
* @returns stream instance
|
|
247
247
|
*
|
|
248
248
|
* @example
|
|
249
|
-
* var inspectStream = require(
|
|
249
|
+
* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );
|
|
250
250
|
*
|
|
251
251
|
* function log( chunk ) {
|
|
252
252
|
* console.log( chunk.toString() );
|
|
@@ -287,7 +287,7 @@ interface Constructor {
|
|
|
287
287
|
* streams.push( createStream() );
|
|
288
288
|
* }
|
|
289
289
|
*/
|
|
290
|
-
factory( alpha: number, beta: number, options?: Options ): ( ...args: Array<any> ) => RandomStream;
|
|
290
|
+
factory( alpha: number, beta: number, options?: Options ): ( ...args: Array<any> ) => RandomStream;
|
|
291
291
|
|
|
292
292
|
/**
|
|
293
293
|
* Returns a function for creating readable streams which generate pseudorandom numbers drawn from an inverse gamma distribution.
|
|
@@ -312,7 +312,7 @@ interface Constructor {
|
|
|
312
312
|
* streams.push( createStream( 2.0, 5.0 ) );
|
|
313
313
|
* }
|
|
314
314
|
*/
|
|
315
|
-
factory( options?: Options ): ( alpha: number, beta: number ) => RandomStream;
|
|
315
|
+
factory( options?: Options ): ( alpha: number, beta: number ) => RandomStream;
|
|
316
316
|
|
|
317
317
|
/**
|
|
318
318
|
* Returns an "objectMode" readable stream for generating a stream of pseudorandom numbers drawn from an inverse gamma distribution.
|
|
@@ -327,7 +327,7 @@ interface Constructor {
|
|
|
327
327
|
* @returns stream instance
|
|
328
328
|
*
|
|
329
329
|
* @example
|
|
330
|
-
* var inspectStream = require(
|
|
330
|
+
* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );
|
|
331
331
|
*
|
|
332
332
|
* function log( v ) {
|
|
333
333
|
* console.log( v );
|
|
@@ -357,7 +357,7 @@ interface Constructor {
|
|
|
357
357
|
* @returns stream instance
|
|
358
358
|
*
|
|
359
359
|
* @example
|
|
360
|
-
* var inspectStream = require(
|
|
360
|
+
* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );
|
|
361
361
|
*
|
|
362
362
|
* function log( chunk ) {
|
|
363
363
|
* console.log( chunk.toString() );
|
|
@@ -372,7 +372,7 @@ interface Constructor {
|
|
|
372
372
|
* stream.pipe( inspectStream( log ) );
|
|
373
373
|
*
|
|
374
374
|
* @example
|
|
375
|
-
* var inspectStream = require(
|
|
375
|
+
* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );
|
|
376
376
|
*
|
|
377
377
|
* function log( chunk ) {
|
|
378
378
|
* console.log( chunk.toString() );
|
|
@@ -388,7 +388,7 @@ interface Constructor {
|
|
|
388
388
|
* stream.pipe( inspectStream( log ) );
|
|
389
389
|
*
|
|
390
390
|
* @example
|
|
391
|
-
* var inspectStream = require(
|
|
391
|
+
* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );
|
|
392
392
|
*
|
|
393
393
|
* function log( v ) {
|
|
394
394
|
* console.log( v );
|
package/lib/factory.js
CHANGED
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
23
|
+
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
|
|
24
|
+
var assign = require( '@stdlib/object-assign' );
|
|
25
|
+
var format = require( '@stdlib/string-format' );
|
|
24
26
|
var RandomStream = require( './main.js' );
|
|
25
27
|
|
|
26
28
|
|
|
@@ -42,6 +44,7 @@ var RandomStream = require( './main.js' );
|
|
|
42
44
|
* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
|
|
43
45
|
* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
|
|
44
46
|
* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state
|
|
47
|
+
* @throws {TypeError} options argument must be an object
|
|
45
48
|
* @returns {Function} stream factory
|
|
46
49
|
*
|
|
47
50
|
* @example
|
|
@@ -68,9 +71,15 @@ function factory( alpha, beta, options ) {
|
|
|
68
71
|
|
|
69
72
|
nargs = arguments.length;
|
|
70
73
|
if ( nargs === 1 ) {
|
|
71
|
-
|
|
74
|
+
if ( !isPlainObject( alpha ) ) {
|
|
75
|
+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', alpha ) );
|
|
76
|
+
}
|
|
77
|
+
opts = assign( {}, alpha );
|
|
72
78
|
} else if ( nargs > 2 ) {
|
|
73
|
-
|
|
79
|
+
if ( !isPlainObject( options ) ) {
|
|
80
|
+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
81
|
+
}
|
|
82
|
+
opts = assign( {}, options );
|
|
74
83
|
} else {
|
|
75
84
|
opts = {};
|
|
76
85
|
}
|
package/lib/index.js
CHANGED
|
@@ -79,17 +79,17 @@
|
|
|
79
79
|
// MODULES //
|
|
80
80
|
|
|
81
81
|
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
82
|
-
var
|
|
82
|
+
var main = require( './main.js' );
|
|
83
83
|
var objectMode = require( './object_mode.js' );
|
|
84
84
|
var factory = require( './factory.js' );
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
// MAIN //
|
|
88
88
|
|
|
89
|
-
setReadOnly(
|
|
90
|
-
setReadOnly(
|
|
89
|
+
setReadOnly( main, 'objectMode', objectMode );
|
|
90
|
+
setReadOnly( main, 'factory', factory );
|
|
91
91
|
|
|
92
92
|
|
|
93
93
|
// EXPORTS //
|
|
94
94
|
|
|
95
|
-
module.exports =
|
|
95
|
+
module.exports = main;
|
package/lib/main.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
var Readable = require( 'readable-stream' ).Readable;
|
|
24
24
|
var isPositiveNumber = require( '@stdlib/assert-is-positive-number' ).isPrimitive;
|
|
25
25
|
var isError = require( '@stdlib/assert-is-error' );
|
|
26
|
-
var
|
|
26
|
+
var assign = require( '@stdlib/object-assign' );
|
|
27
27
|
var inherit = require( '@stdlib/utils-inherit' );
|
|
28
28
|
var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );
|
|
29
29
|
var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
@@ -32,6 +32,7 @@ var setReadWriteAccessor = require( '@stdlib/utils-define-read-write-accessor' )
|
|
|
32
32
|
var rinvgamma = require( '@stdlib/random-base-invgamma' ).factory;
|
|
33
33
|
var string2buffer = require( '@stdlib/buffer-from-string' );
|
|
34
34
|
var nextTick = require( '@stdlib/utils-next-tick' );
|
|
35
|
+
var format = require( '@stdlib/string-format' );
|
|
35
36
|
var DEFAULTS = require( './defaults.json' );
|
|
36
37
|
var validate = require( './validate.js' );
|
|
37
38
|
var debug = require( './debug.js' );
|
|
@@ -233,12 +234,12 @@ function RandomStream( alpha, beta, options ) {
|
|
|
233
234
|
return new RandomStream( alpha, beta );
|
|
234
235
|
}
|
|
235
236
|
if ( !isPositiveNumber( alpha ) ) {
|
|
236
|
-
throw new TypeError( 'invalid argument. First argument must be a positive number. Value:
|
|
237
|
+
throw new TypeError( format( 'invalid argument. First argument must be a positive number. Value: `%s`.', alpha ) );
|
|
237
238
|
}
|
|
238
239
|
if ( !isPositiveNumber( beta ) ) {
|
|
239
|
-
throw new TypeError( 'invalid argument. Second argument must be a positive number. Value:
|
|
240
|
+
throw new TypeError( format( 'invalid argument. Second argument must be a positive number. Value: `%s`.', beta ) );
|
|
240
241
|
}
|
|
241
|
-
opts =
|
|
242
|
+
opts = assign( {}, DEFAULTS );
|
|
242
243
|
if ( arguments.length > 2 ) {
|
|
243
244
|
err = validate( opts, options );
|
|
244
245
|
if ( err ) {
|
package/lib/object_mode.js
CHANGED
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
23
|
var isObject = require( '@stdlib/assert-is-plain-object' );
|
|
24
|
-
var
|
|
24
|
+
var assign = require( '@stdlib/object-assign' );
|
|
25
|
+
var format = require( '@stdlib/string-format' );
|
|
25
26
|
var RandomStream = require( './main.js' );
|
|
26
27
|
|
|
27
28
|
|
|
@@ -68,9 +69,9 @@ function objectMode( alpha, beta, options ) {
|
|
|
68
69
|
if ( arguments.length > 2 ) {
|
|
69
70
|
opts = options;
|
|
70
71
|
if ( !isObject( opts ) ) {
|
|
71
|
-
throw new TypeError( 'invalid argument. Options must be an object. Value:
|
|
72
|
+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );
|
|
72
73
|
}
|
|
73
|
-
opts =
|
|
74
|
+
opts = assign( {}, options );
|
|
74
75
|
} else {
|
|
75
76
|
opts = {};
|
|
76
77
|
}
|
package/lib/validate.js
CHANGED
|
@@ -27,6 +27,7 @@ var isNonNegative = require( '@stdlib/assert-is-nonnegative-number' ).isPrimitiv
|
|
|
27
27
|
var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
|
|
28
28
|
var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive;
|
|
29
29
|
var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;
|
|
30
|
+
var format = require( '@stdlib/string-format' );
|
|
30
31
|
|
|
31
32
|
|
|
32
33
|
// MAIN //
|
|
@@ -54,49 +55,49 @@ var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).is
|
|
|
54
55
|
* var options = {
|
|
55
56
|
* 'objectMode': true
|
|
56
57
|
* };
|
|
57
|
-
* var err= validate( opts, options );
|
|
58
|
+
* var err = validate( opts, options );
|
|
58
59
|
* if ( err ) {
|
|
59
60
|
* throw err;
|
|
60
61
|
* }
|
|
61
62
|
*/
|
|
62
63
|
function validate( opts, options ) {
|
|
63
64
|
if ( !isObject( options ) ) {
|
|
64
|
-
return new TypeError( 'invalid argument. Options must be an object. Value:
|
|
65
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
65
66
|
}
|
|
66
67
|
if ( hasOwnProp( options, 'sep' ) ) {
|
|
67
68
|
opts.sep = options.sep;
|
|
68
69
|
if ( !isString( opts.sep ) ) {
|
|
69
|
-
return new TypeError( 'invalid option. `
|
|
70
|
+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
if ( hasOwnProp( options, 'objectMode' ) ) {
|
|
73
74
|
opts.objectMode = options.objectMode;
|
|
74
75
|
if ( !isBoolean( opts.objectMode ) ) {
|
|
75
|
-
return new TypeError( 'invalid option. `
|
|
76
|
+
return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'objectMode', opts.objectMode ) );
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
if ( hasOwnProp( options, 'encoding' ) ) {
|
|
79
80
|
opts.encoding = options.encoding;
|
|
80
81
|
if ( !isString( opts.encoding ) && opts.encoding !== null ) {
|
|
81
|
-
return new TypeError( 'invalid option. `
|
|
82
|
+
return new TypeError( format( 'invalid option. `%s` option must be a string or null. Option: `%s`.', 'encoding', opts.encoding ) );
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
if ( hasOwnProp( options, 'highWaterMark' ) ) {
|
|
85
86
|
opts.highWaterMark = options.highWaterMark;
|
|
86
87
|
if ( !isNonNegative( opts.highWaterMark ) ) {
|
|
87
|
-
return new TypeError( 'invalid option. `
|
|
88
|
+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative number. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) );
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
if ( hasOwnProp( options, 'iter' ) ) {
|
|
91
92
|
opts.iter = options.iter;
|
|
92
93
|
if ( !isNonNegativeInteger( opts.iter ) ) {
|
|
93
|
-
return new TypeError( 'invalid option. `
|
|
94
|
+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', opts.iter ) );
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
if ( hasOwnProp( options, 'siter' ) ) {
|
|
97
98
|
opts.siter = options.siter;
|
|
98
99
|
if ( !isPositiveInteger( opts.siter ) ) {
|
|
99
|
-
return new TypeError( 'invalid option. `
|
|
100
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'siter', opts.siter ) );
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
// Pass through options...
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/random-streams-invgamma",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Create a readable stream for generating pseudorandom numbers drawn from an inverse gamma distribution.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
|
-
"bin": {
|
|
17
|
-
"random-invgamma": "./bin/cli"
|
|
18
|
-
},
|
|
19
16
|
"main": "./lib",
|
|
20
17
|
"directories": {
|
|
21
18
|
"benchmark": "./benchmark",
|
|
@@ -40,58 +37,34 @@
|
|
|
40
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
41
38
|
},
|
|
42
39
|
"dependencies": {
|
|
43
|
-
"@stdlib/
|
|
44
|
-
"@stdlib/
|
|
45
|
-
"@stdlib/assert-
|
|
46
|
-
"@stdlib/assert-is-
|
|
47
|
-
"@stdlib/assert-is-
|
|
48
|
-
"@stdlib/assert-is-
|
|
49
|
-
"@stdlib/assert-is-
|
|
50
|
-
"@stdlib/assert-is-
|
|
51
|
-
"@stdlib/assert-is-
|
|
52
|
-
"@stdlib/
|
|
53
|
-
"@stdlib/
|
|
54
|
-
"@stdlib/
|
|
55
|
-
"@stdlib/
|
|
56
|
-
"@stdlib/
|
|
57
|
-
"@stdlib/
|
|
58
|
-
"@stdlib/
|
|
59
|
-
"@stdlib/
|
|
60
|
-
"@stdlib/
|
|
61
|
-
"@stdlib/
|
|
62
|
-
"@stdlib/process-cwd": "^0.0.x",
|
|
63
|
-
"@stdlib/random-base-invgamma": "^0.0.x",
|
|
64
|
-
"@stdlib/streams-node-stdout": "^0.0.x",
|
|
65
|
-
"@stdlib/types": "^0.0.x",
|
|
66
|
-
"@stdlib/utils-copy": "^0.0.x",
|
|
67
|
-
"@stdlib/utils-define-nonenumerable-property": "^0.0.x",
|
|
68
|
-
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x",
|
|
69
|
-
"@stdlib/utils-define-read-only-accessor": "^0.0.x",
|
|
70
|
-
"@stdlib/utils-define-read-write-accessor": "^0.0.x",
|
|
71
|
-
"@stdlib/utils-inherit": "^0.0.x",
|
|
72
|
-
"@stdlib/utils-next-tick": "^0.0.x",
|
|
40
|
+
"@stdlib/assert-has-own-property": "^0.2.0",
|
|
41
|
+
"@stdlib/assert-is-boolean": "^0.2.0",
|
|
42
|
+
"@stdlib/assert-is-error": "^0.2.0",
|
|
43
|
+
"@stdlib/assert-is-nonnegative-integer": "^0.2.0",
|
|
44
|
+
"@stdlib/assert-is-nonnegative-number": "^0.2.0",
|
|
45
|
+
"@stdlib/assert-is-plain-object": "^0.2.0",
|
|
46
|
+
"@stdlib/assert-is-positive-integer": "^0.2.0",
|
|
47
|
+
"@stdlib/assert-is-positive-number": "^0.2.0",
|
|
48
|
+
"@stdlib/assert-is-string": "^0.2.0",
|
|
49
|
+
"@stdlib/buffer-from-string": "^0.2.0",
|
|
50
|
+
"@stdlib/object-assign": "^0.2.0",
|
|
51
|
+
"@stdlib/random-base-invgamma": "^0.2.0",
|
|
52
|
+
"@stdlib/string-format": "^0.2.0",
|
|
53
|
+
"@stdlib/utils-define-nonenumerable-property": "^0.2.0",
|
|
54
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0",
|
|
55
|
+
"@stdlib/utils-define-read-only-accessor": "^0.2.0",
|
|
56
|
+
"@stdlib/utils-define-read-write-accessor": "^0.2.0",
|
|
57
|
+
"@stdlib/utils-inherit": "^0.2.0",
|
|
58
|
+
"@stdlib/utils-next-tick": "^0.2.0",
|
|
73
59
|
"debug": "^2.6.9",
|
|
74
60
|
"readable-stream": "^2.1.4"
|
|
75
61
|
},
|
|
76
62
|
"devDependencies": {
|
|
77
|
-
"@stdlib/
|
|
78
|
-
"@stdlib/assert-is-buffer": "^0.0.x",
|
|
79
|
-
"@stdlib/assert-is-uint32array": "^0.0.x",
|
|
80
|
-
"@stdlib/assert-is-windows": "^0.0.x",
|
|
81
|
-
"@stdlib/bench": "^0.0.x",
|
|
82
|
-
"@stdlib/constants-uint32-max": "^0.0.x",
|
|
83
|
-
"@stdlib/fs-exists": "^0.0.x",
|
|
84
|
-
"@stdlib/fs-unlink": "^0.0.x",
|
|
85
|
-
"@stdlib/math-base-assert-is-nan": "^0.0.x",
|
|
86
|
-
"@stdlib/process-exec-path": "^0.0.x",
|
|
87
|
-
"@stdlib/random-base-minstd": "^0.0.x",
|
|
88
|
-
"@stdlib/streams-node-inspect-sink": "^0.0.x",
|
|
89
|
-
"@stdlib/string-replace": "^0.0.x",
|
|
90
|
-
"@stdlib/time-now": "^0.0.x",
|
|
63
|
+
"@stdlib/streams-node-inspect-sink": "^0.2.0",
|
|
91
64
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
92
65
|
"proxyquire": "^2.0.0",
|
|
93
66
|
"istanbul": "^0.4.1",
|
|
94
|
-
"tap-
|
|
67
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git"
|
|
95
68
|
},
|
|
96
69
|
"engines": {
|
|
97
70
|
"node": ">=0.10.0",
|
|
@@ -130,7 +103,7 @@
|
|
|
130
103
|
"seedable"
|
|
131
104
|
],
|
|
132
105
|
"funding": {
|
|
133
|
-
"type": "
|
|
134
|
-
"url": "https://
|
|
106
|
+
"type": "opencollective",
|
|
107
|
+
"url": "https://opencollective.com/stdlib"
|
|
135
108
|
}
|
|
136
109
|
}
|
package/bin/cli
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @license Apache-2.0
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2018 The Stdlib Authors.
|
|
7
|
-
*
|
|
8
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
-
* you may not use this file except in compliance with the License.
|
|
10
|
-
* You may obtain a copy of the License at
|
|
11
|
-
*
|
|
12
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
-
* See the License for the specific language governing permissions and
|
|
18
|
-
* limitations under the License.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
'use strict';
|
|
22
|
-
|
|
23
|
-
// MODULES //
|
|
24
|
-
|
|
25
|
-
var proc = require( 'process' );
|
|
26
|
-
var resolve = require( 'path' ).resolve;
|
|
27
|
-
var readFileSync = require( '@stdlib/fs-read-file' ).sync;
|
|
28
|
-
var writeFileSync = require( '@stdlib/fs-write-file' ).sync;
|
|
29
|
-
var CLI = require( '@stdlib/cli-ctor' );
|
|
30
|
-
var stdout = require( '@stdlib/streams-node-stdout' );
|
|
31
|
-
var cwd = require( '@stdlib/process-cwd' );
|
|
32
|
-
var Uint8Array = require( '@stdlib/array-uint8' );
|
|
33
|
-
var Uint32Array = require( '@stdlib/array-uint32' );
|
|
34
|
-
var isUint8Array = require( '@stdlib/assert-is-uint8array' );
|
|
35
|
-
var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
|
|
36
|
-
var gcopy = require( '@stdlib/blas-base-gcopy' );
|
|
37
|
-
var array2buffer = require( '@stdlib/buffer-from-array' );
|
|
38
|
-
var randomStream = require( './../lib' );
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// FUNCTIONS //
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Callback invoked once a source stream ends.
|
|
45
|
-
*
|
|
46
|
-
* @private
|
|
47
|
-
*/
|
|
48
|
-
function onEnd() {
|
|
49
|
-
// Append a trailing newline in accordance with standard POSIX behavior:
|
|
50
|
-
console.log( '' ); // eslint-disable-line no-console
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Attempts to load a PRNG state.
|
|
55
|
-
*
|
|
56
|
-
* @private
|
|
57
|
-
* @param {string} filepath - absolute path to file containing PRNG state
|
|
58
|
-
* @returns {(Uint32Array|Error)} PRNG state or an error
|
|
59
|
-
*/
|
|
60
|
-
function loadState( filepath ) {
|
|
61
|
-
var state;
|
|
62
|
-
var len;
|
|
63
|
-
|
|
64
|
-
state = readFileSync( filepath );
|
|
65
|
-
if ( state instanceof Error ) {
|
|
66
|
-
return state;
|
|
67
|
-
}
|
|
68
|
-
len = state.length;
|
|
69
|
-
|
|
70
|
-
// For older Node.js environments, convert the `Buffer` to a `Uint8Array`...
|
|
71
|
-
if ( !isUint8Array( state ) ) {
|
|
72
|
-
state = gcopy( len, state, 1, new Uint8Array( len ), 1 );
|
|
73
|
-
}
|
|
74
|
-
// Create a PRNG state array "view":
|
|
75
|
-
len /= Uint32Array.BYTES_PER_ELEMENT;
|
|
76
|
-
if ( !isInteger( len ) ) {
|
|
77
|
-
return new RangeError( 'invalid option. `state` has an invalid length.' );
|
|
78
|
-
}
|
|
79
|
-
return new Uint32Array( state.buffer, state.byteOffset, len );
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// MAIN //
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Main execution sequence.
|
|
87
|
-
*
|
|
88
|
-
* @private
|
|
89
|
-
* @returns {void}
|
|
90
|
-
*/
|
|
91
|
-
function main() {
|
|
92
|
-
var stream;
|
|
93
|
-
var flags;
|
|
94
|
-
var opts;
|
|
95
|
-
var args;
|
|
96
|
-
var cli;
|
|
97
|
-
var err;
|
|
98
|
-
var dir;
|
|
99
|
-
var i;
|
|
100
|
-
|
|
101
|
-
// Create a command-line interface:
|
|
102
|
-
cli = new CLI({
|
|
103
|
-
'pkg': require( './../package.json' ),
|
|
104
|
-
'options': require( './../etc/cli_opts.json' ),
|
|
105
|
-
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
|
|
106
|
-
'encoding': 'utf8'
|
|
107
|
-
})
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// Get any provided command-line options:
|
|
111
|
-
flags = cli.flags();
|
|
112
|
-
if ( flags.help || flags.version ) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Get the current working directory:
|
|
117
|
-
dir = cwd();
|
|
118
|
-
|
|
119
|
-
// Get any provided command-line arguments:
|
|
120
|
-
args = cli.args();
|
|
121
|
-
if ( args.length < 2 ) {
|
|
122
|
-
err = new Error( 'insufficient arguments. Must provide distribution parameters.' );
|
|
123
|
-
return onError( err );
|
|
124
|
-
}
|
|
125
|
-
args[ 0 ] = parseFloat( args[ 0 ] );
|
|
126
|
-
args[ 1 ] = parseFloat( args[ 1 ] );
|
|
127
|
-
|
|
128
|
-
opts = {};
|
|
129
|
-
if ( flags.iter ) {
|
|
130
|
-
opts.iter = parseInt( flags.iter, 10 );
|
|
131
|
-
}
|
|
132
|
-
if ( flags.sep ) {
|
|
133
|
-
opts.sep = flags.sep;
|
|
134
|
-
}
|
|
135
|
-
if ( flags.state ) {
|
|
136
|
-
opts.state = loadState( resolve( dir, flags.state ) );
|
|
137
|
-
if ( opts.state instanceof Error ) {
|
|
138
|
-
return onError( opts.state );
|
|
139
|
-
}
|
|
140
|
-
} else if ( flags.seed ) {
|
|
141
|
-
opts.seed = flags.seed.split( ',' );
|
|
142
|
-
for ( i = 0; i < opts.seed.length; i++ ) {
|
|
143
|
-
opts.seed[ i ] = parseInt( opts.seed[ i ], 10 );
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if ( flags.snapshot ) {
|
|
147
|
-
proc.on( 'exit', onExit );
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Create a source stream and pipe to `stdout`:
|
|
151
|
-
stream = randomStream( args[ 0 ], args[ 1 ], opts );
|
|
152
|
-
stream.on( 'end', onEnd );
|
|
153
|
-
|
|
154
|
-
stream.pipe( stdout );
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Callback invoked upon exiting the process.
|
|
158
|
-
*
|
|
159
|
-
* @private
|
|
160
|
-
* @param {integer} code - exit code
|
|
161
|
-
*/
|
|
162
|
-
function onExit( code ) {
|
|
163
|
-
var state;
|
|
164
|
-
var err;
|
|
165
|
-
|
|
166
|
-
// Get the current PRNG state:
|
|
167
|
-
state = stream.state;
|
|
168
|
-
|
|
169
|
-
// Create a byte array "view":
|
|
170
|
-
state = new Uint8Array( state.buffer, state.byteOffset, stream.byteLength ); // eslint-disable-line max-len
|
|
171
|
-
|
|
172
|
-
// Convert the byte array to a `Buffer` (with support for older Node.js environments):
|
|
173
|
-
state = array2buffer( state );
|
|
174
|
-
|
|
175
|
-
// Attempt to write the state to file:
|
|
176
|
-
err = writeFileSync( resolve( dir, flags.snapshot ), state );
|
|
177
|
-
if ( err ) {
|
|
178
|
-
onError( err, code || 1 );
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Callback invoked upon encountering an error.
|
|
184
|
-
*
|
|
185
|
-
* @private
|
|
186
|
-
* @param {Error} error - error
|
|
187
|
-
* @param {integer} [code] - exit code
|
|
188
|
-
*/
|
|
189
|
-
function onError( error, code ) {
|
|
190
|
-
cli.error( error, code || 1 );
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
main();
|