@ohos-ports/stdlib-simulate 0.4.1-beta.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 +177 -0
- package/NOTICE +1 -0
- package/README.md +188 -0
- package/SECURITY.md +5 -0
- package/docs/types/index.d.ts +43 -0
- package/iter/README.md +142 -0
- package/iter/awgn/README.md +240 -0
- package/iter/awgn/docs/repl.txt +85 -0
- package/iter/awgn/docs/types/index.d.ts +155 -0
- package/iter/awgn/docs/types/test.ts +150 -0
- package/iter/awgn/lib/defaults.js +38 -0
- package/iter/awgn/lib/index.js +55 -0
- package/iter/awgn/lib/main.js +278 -0
- package/iter/awgn/package.json +68 -0
- package/iter/awln/README.md +238 -0
- package/iter/awln/docs/repl.txt +85 -0
- package/iter/awln/docs/types/index.d.ts +155 -0
- package/iter/awln/docs/types/test.ts +150 -0
- package/iter/awln/lib/defaults.js +38 -0
- package/iter/awln/lib/index.js +55 -0
- package/iter/awln/lib/main.js +299 -0
- package/iter/awln/package.json +72 -0
- package/iter/awun/README.md +238 -0
- package/iter/awun/docs/repl.txt +85 -0
- package/iter/awun/docs/types/index.d.ts +155 -0
- package/iter/awun/docs/types/test.ts +150 -0
- package/iter/awun/lib/defaults.js +38 -0
- package/iter/awun/lib/index.js +55 -0
- package/iter/awun/lib/main.js +305 -0
- package/iter/awun/package.json +68 -0
- package/iter/bartlett-hann-pulse/README.md +331 -0
- package/iter/bartlett-hann-pulse/docs/img/equation_bartlett_hann_pulse_waveform.svg +191 -0
- package/iter/bartlett-hann-pulse/docs/repl.txt +54 -0
- package/iter/bartlett-hann-pulse/docs/types/index.d.ts +105 -0
- package/iter/bartlett-hann-pulse/docs/types/test.ts +89 -0
- package/iter/bartlett-hann-pulse/lib/index.js +54 -0
- package/iter/bartlett-hann-pulse/lib/main.js +192 -0
- package/iter/bartlett-hann-pulse/lib/validate.js +97 -0
- package/iter/bartlett-hann-pulse/package.json +76 -0
- package/iter/bartlett-pulse/README.md +328 -0
- package/iter/bartlett-pulse/docs/img/equation_bartlett_pulse_waveform.svg +128 -0
- package/iter/bartlett-pulse/docs/repl.txt +54 -0
- package/iter/bartlett-pulse/docs/types/index.d.ts +105 -0
- package/iter/bartlett-pulse/docs/types/test.ts +89 -0
- package/iter/bartlett-pulse/lib/index.js +54 -0
- package/iter/bartlett-pulse/lib/main.js +169 -0
- package/iter/bartlett-pulse/lib/validate.js +97 -0
- package/iter/bartlett-pulse/package.json +72 -0
- package/iter/cosine-wave/README.md +292 -0
- package/iter/cosine-wave/docs/img/equation_cosine_waveform.svg +55 -0
- package/iter/cosine-wave/docs/repl.txt +51 -0
- package/iter/cosine-wave/docs/types/index.d.ts +96 -0
- package/iter/cosine-wave/docs/types/test.ts +78 -0
- package/iter/cosine-wave/lib/index.js +54 -0
- package/iter/cosine-wave/lib/main.js +156 -0
- package/iter/cosine-wave/lib/validate.js +90 -0
- package/iter/cosine-wave/package.json +70 -0
- package/iter/dirac-comb/README.md +278 -0
- package/iter/dirac-comb/docs/img/equation_dirac_comb.svg +44 -0
- package/iter/dirac-comb/docs/repl.txt +48 -0
- package/iter/dirac-comb/docs/types/index.d.ts +89 -0
- package/iter/dirac-comb/docs/types/test.ts +78 -0
- package/iter/dirac-comb/lib/index.js +54 -0
- package/iter/dirac-comb/lib/main.js +152 -0
- package/iter/dirac-comb/lib/validate.js +82 -0
- package/iter/dirac-comb/package.json +72 -0
- package/iter/docs/types/index.d.ts +678 -0
- package/iter/docs/types/test.ts +29 -0
- package/iter/flat-top-pulse/README.md +330 -0
- package/iter/flat-top-pulse/docs/img/equation_flat_top_pulse_waveform.svg +177 -0
- package/iter/flat-top-pulse/docs/repl.txt +54 -0
- package/iter/flat-top-pulse/docs/types/index.d.ts +105 -0
- package/iter/flat-top-pulse/docs/types/test.ts +89 -0
- package/iter/flat-top-pulse/lib/index.js +54 -0
- package/iter/flat-top-pulse/lib/main.js +193 -0
- package/iter/flat-top-pulse/lib/validate.js +97 -0
- package/iter/flat-top-pulse/package.json +71 -0
- package/iter/hann-pulse/README.md +328 -0
- package/iter/hann-pulse/docs/img/equation_hann_pulse_waveform.svg +129 -0
- package/iter/hann-pulse/docs/repl.txt +54 -0
- package/iter/hann-pulse/docs/types/index.d.ts +105 -0
- package/iter/hann-pulse/docs/types/test.ts +89 -0
- package/iter/hann-pulse/lib/index.js +54 -0
- package/iter/hann-pulse/lib/main.js +171 -0
- package/iter/hann-pulse/lib/validate.js +97 -0
- package/iter/hann-pulse/package.json +72 -0
- package/iter/lanczos-pulse/README.md +325 -0
- package/iter/lanczos-pulse/docs/img/equation_lanczos_pulse_waveform.svg +122 -0
- package/iter/lanczos-pulse/docs/repl.txt +54 -0
- package/iter/lanczos-pulse/docs/types/index.d.ts +105 -0
- package/iter/lanczos-pulse/docs/types/test.ts +89 -0
- package/iter/lanczos-pulse/lib/index.js +54 -0
- package/iter/lanczos-pulse/lib/main.js +169 -0
- package/iter/lanczos-pulse/lib/validate.js +97 -0
- package/iter/lanczos-pulse/package.json +70 -0
- package/iter/lib/index.js +186 -0
- package/iter/package.json +63 -0
- package/iter/periodic-sinc/README.md +301 -0
- package/iter/periodic-sinc/docs/img/equation_periodic_sinc.svg +146 -0
- package/iter/periodic-sinc/docs/img/equation_periodic_sinc_in_terms_of_period.svg +164 -0
- package/iter/periodic-sinc/docs/img/equation_periodic_sinc_in_terms_of_sinc_function.svg +65 -0
- package/iter/periodic-sinc/docs/img/equation_periodic_sinc_substitution_even.svg +34 -0
- package/iter/periodic-sinc/docs/img/equation_periodic_sinc_substitution_odd.svg +34 -0
- package/iter/periodic-sinc/docs/repl.txt +54 -0
- package/iter/periodic-sinc/docs/types/index.d.ts +98 -0
- package/iter/periodic-sinc/docs/types/test.ts +102 -0
- package/iter/periodic-sinc/lib/index.js +50 -0
- package/iter/periodic-sinc/lib/main.js +241 -0
- package/iter/periodic-sinc/lib/validate.js +90 -0
- package/iter/periodic-sinc/package.json +70 -0
- package/iter/pulse/README.md +322 -0
- package/iter/pulse/docs/img/equation_pulse_waveform.svg +115 -0
- package/iter/pulse/docs/repl.txt +58 -0
- package/iter/pulse/docs/types/index.d.ts +109 -0
- package/iter/pulse/docs/types/test.ts +100 -0
- package/iter/pulse/lib/index.js +54 -0
- package/iter/pulse/lib/main.js +165 -0
- package/iter/pulse/lib/validate.js +105 -0
- package/iter/pulse/package.json +69 -0
- package/iter/sawtooth-wave/README.md +289 -0
- package/iter/sawtooth-wave/docs/img/equation_sawtooth_waveform.svg +73 -0
- package/iter/sawtooth-wave/docs/repl.txt +51 -0
- package/iter/sawtooth-wave/docs/types/index.d.ts +96 -0
- package/iter/sawtooth-wave/docs/types/test.ts +78 -0
- package/iter/sawtooth-wave/lib/index.js +54 -0
- package/iter/sawtooth-wave/lib/main.js +161 -0
- package/iter/sawtooth-wave/lib/validate.js +90 -0
- package/iter/sawtooth-wave/package.json +67 -0
- package/iter/sine-wave/README.md +292 -0
- package/iter/sine-wave/docs/img/equation_sine_waveform.svg +55 -0
- package/iter/sine-wave/docs/repl.txt +51 -0
- package/iter/sine-wave/docs/types/index.d.ts +96 -0
- package/iter/sine-wave/docs/types/test.ts +78 -0
- package/iter/sine-wave/lib/index.js +54 -0
- package/iter/sine-wave/lib/main.js +156 -0
- package/iter/sine-wave/lib/validate.js +90 -0
- package/iter/sine-wave/package.json +70 -0
- package/iter/square-wave/README.md +291 -0
- package/iter/square-wave/docs/img/equation_square_waveform.svg +115 -0
- package/iter/square-wave/docs/repl.txt +55 -0
- package/iter/square-wave/docs/types/index.d.ts +105 -0
- package/iter/square-wave/docs/types/test.ts +89 -0
- package/iter/square-wave/lib/index.js +54 -0
- package/iter/square-wave/lib/main.js +156 -0
- package/iter/square-wave/lib/validate.js +99 -0
- package/iter/square-wave/package.json +67 -0
- package/iter/triangle-wave/README.md +289 -0
- package/iter/triangle-wave/docs/img/equation_triangle_waveform.svg +75 -0
- package/iter/triangle-wave/docs/repl.txt +51 -0
- package/iter/triangle-wave/docs/types/index.d.ts +96 -0
- package/iter/triangle-wave/docs/types/test.ts +78 -0
- package/iter/triangle-wave/lib/index.js +54 -0
- package/iter/triangle-wave/lib/main.js +160 -0
- package/iter/triangle-wave/lib/validate.js +90 -0
- package/iter/triangle-wave/package.json +66 -0
- package/lib/index.js +51 -0
- package/package.json +72 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import iterPulse = require( './index' );
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// TESTS //
|
|
23
|
+
|
|
24
|
+
// The function returns an iterator...
|
|
25
|
+
{
|
|
26
|
+
iterPulse(); // $ExpectType Iterator
|
|
27
|
+
iterPulse( {} ); // $ExpectType Iterator
|
|
28
|
+
iterPulse( { 'iter': 10 } ); // $ExpectType Iterator
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// The compiler throws an error if the function is provided a first argument which is not an options object...
|
|
32
|
+
{
|
|
33
|
+
iterPulse( null ); // $ExpectError
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The compiler throws an error if the function is provided a `duration` option which is not a number...
|
|
37
|
+
{
|
|
38
|
+
iterPulse( { 'duration': '5' } ); // $ExpectError
|
|
39
|
+
iterPulse( { 'duration': true } ); // $ExpectError
|
|
40
|
+
iterPulse( { 'duration': false } ); // $ExpectError
|
|
41
|
+
iterPulse( { 'duration': null } ); // $ExpectError
|
|
42
|
+
iterPulse( { 'duration': [] } ); // $ExpectError
|
|
43
|
+
iterPulse( { 'duration': {} } ); // $ExpectError
|
|
44
|
+
iterPulse( { 'duration': ( x: number ): number => x } ); // $ExpectError
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The compiler throws an error if the function is provided a `period` option which is not a number...
|
|
48
|
+
{
|
|
49
|
+
iterPulse( { 'period': '5' } ); // $ExpectError
|
|
50
|
+
iterPulse( { 'period': true } ); // $ExpectError
|
|
51
|
+
iterPulse( { 'period': false } ); // $ExpectError
|
|
52
|
+
iterPulse( { 'period': null } ); // $ExpectError
|
|
53
|
+
iterPulse( { 'period': [] } ); // $ExpectError
|
|
54
|
+
iterPulse( { 'period': {} } ); // $ExpectError
|
|
55
|
+
iterPulse( { 'period': ( x: number ): number => x } ); // $ExpectError
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// The compiler throws an error if the function is provided a `min` option which is not a number...
|
|
59
|
+
{
|
|
60
|
+
iterPulse( { 'min': '5' } ); // $ExpectError
|
|
61
|
+
iterPulse( { 'min': true } ); // $ExpectError
|
|
62
|
+
iterPulse( { 'min': false } ); // $ExpectError
|
|
63
|
+
iterPulse( { 'min': null } ); // $ExpectError
|
|
64
|
+
iterPulse( { 'min': [] } ); // $ExpectError
|
|
65
|
+
iterPulse( { 'min': {} } ); // $ExpectError
|
|
66
|
+
iterPulse( { 'min': ( x: number ): number => x } ); // $ExpectError
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The compiler throws an error if the function is provided a `max` option which is not a number...
|
|
70
|
+
{
|
|
71
|
+
iterPulse( { 'max': '5' } ); // $ExpectError
|
|
72
|
+
iterPulse( { 'max': true } ); // $ExpectError
|
|
73
|
+
iterPulse( { 'max': false } ); // $ExpectError
|
|
74
|
+
iterPulse( { 'max': null } ); // $ExpectError
|
|
75
|
+
iterPulse( { 'max': [] } ); // $ExpectError
|
|
76
|
+
iterPulse( { 'max': {} } ); // $ExpectError
|
|
77
|
+
iterPulse( { 'max': ( x: number ): number => x } ); // $ExpectError
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// The compiler throws an error if the function is provided an `offset` option which is not a number...
|
|
81
|
+
{
|
|
82
|
+
iterPulse( { 'offset': '5' } ); // $ExpectError
|
|
83
|
+
iterPulse( { 'offset': true } ); // $ExpectError
|
|
84
|
+
iterPulse( { 'offset': false } ); // $ExpectError
|
|
85
|
+
iterPulse( { 'offset': null } ); // $ExpectError
|
|
86
|
+
iterPulse( { 'offset': [] } ); // $ExpectError
|
|
87
|
+
iterPulse( { 'offset': {} } ); // $ExpectError
|
|
88
|
+
iterPulse( { 'offset': ( x: number ): number => x } ); // $ExpectError
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The compiler throws an error if the function is provided an `iter` option which is not a number...
|
|
92
|
+
{
|
|
93
|
+
iterPulse( { 'iter': '5' } ); // $ExpectError
|
|
94
|
+
iterPulse( { 'iter': true } ); // $ExpectError
|
|
95
|
+
iterPulse( { 'iter': false } ); // $ExpectError
|
|
96
|
+
iterPulse( { 'iter': null } ); // $ExpectError
|
|
97
|
+
iterPulse( { 'iter': [] } ); // $ExpectError
|
|
98
|
+
iterPulse( { 'iter': {} } ); // $ExpectError
|
|
99
|
+
iterPulse( { 'iter': ( x: number ): number => x } ); // $ExpectError
|
|
100
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create an iterator which generates a pulse waveform.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/simulate/iter/pulse
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var iterPulse = require( '@stdlib/simulate/iter/pulse' );
|
|
28
|
+
*
|
|
29
|
+
* var opts = {
|
|
30
|
+
* 'period': 4
|
|
31
|
+
* };
|
|
32
|
+
*
|
|
33
|
+
* var iter = iterPulse( opts );
|
|
34
|
+
*
|
|
35
|
+
* var v = iter.next().value;
|
|
36
|
+
* // returns 1.0
|
|
37
|
+
*
|
|
38
|
+
* v = iter.next().value;
|
|
39
|
+
* // returns 1.0
|
|
40
|
+
*
|
|
41
|
+
* v = iter.next().value;
|
|
42
|
+
* // returns 0.0
|
|
43
|
+
*
|
|
44
|
+
* // ...
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
// MODULES //
|
|
48
|
+
|
|
49
|
+
var main = require( './main.js' );
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// EXPORTS //
|
|
53
|
+
|
|
54
|
+
module.exports = main;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
|
|
24
|
+
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
|
|
25
|
+
var format = require( '@stdlib/string/format' );
|
|
26
|
+
var floor = require( '@stdlib/math/base/special/floor' );
|
|
27
|
+
var validate = require( './validate.js' );
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// MAIN //
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns an iterator which generates a pulse waveform.
|
|
34
|
+
*
|
|
35
|
+
* @param {Options} [options] - function options
|
|
36
|
+
* @param {PositiveInteger} [options.period=10] - number of iterations before a waveform repeats
|
|
37
|
+
* @param {PositiveInteger} [options.duration=floor(options.period/2)] - number of consecutive iterations of maximum amplitude during one period
|
|
38
|
+
* @param {number} [options.min=0.0] - minimum amplitude
|
|
39
|
+
* @param {number} [options.max=1.0] - maximum amplitude
|
|
40
|
+
* @param {integer} [options.offset=0] - phase offset (in units of iterations; zero-based)
|
|
41
|
+
* @param {NonNegativeInteger} [options.iter=1e308] - number of iterations
|
|
42
|
+
* @throws {TypeError} options argument must be an object
|
|
43
|
+
* @throws {TypeError} must provide valid options
|
|
44
|
+
* @throws {RangeError} pulse duration must be less than the period
|
|
45
|
+
* @returns {Iterator} iterator
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* var opts = {
|
|
49
|
+
* 'period': 4
|
|
50
|
+
* };
|
|
51
|
+
*
|
|
52
|
+
* var iter = iterPulse( opts );
|
|
53
|
+
*
|
|
54
|
+
* var v = iter.next().value;
|
|
55
|
+
* // returns 1.0
|
|
56
|
+
*
|
|
57
|
+
* v = iter.next().value;
|
|
58
|
+
* // returns 1.0
|
|
59
|
+
*
|
|
60
|
+
* v = iter.next().value;
|
|
61
|
+
* // returns 0.0
|
|
62
|
+
*
|
|
63
|
+
* // ...
|
|
64
|
+
*/
|
|
65
|
+
function iterPulse( options ) {
|
|
66
|
+
var opts;
|
|
67
|
+
var iter;
|
|
68
|
+
var FLG;
|
|
69
|
+
var err;
|
|
70
|
+
var t;
|
|
71
|
+
var i;
|
|
72
|
+
|
|
73
|
+
opts = {
|
|
74
|
+
'duration': -1,
|
|
75
|
+
'period': 10,
|
|
76
|
+
'min': 0.0,
|
|
77
|
+
'max': 1.0,
|
|
78
|
+
'offset': 0,
|
|
79
|
+
'iter': 1e308
|
|
80
|
+
};
|
|
81
|
+
if ( arguments.length ) {
|
|
82
|
+
err = validate( opts, options );
|
|
83
|
+
if ( err ) {
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if ( opts.duration === -1 ) {
|
|
88
|
+
opts.duration = floor( opts.period/2 );
|
|
89
|
+
}
|
|
90
|
+
if ( opts.duration >= opts.period ) {
|
|
91
|
+
throw new RangeError( format( 'invalid option. `%s` option must be less than the period. Option: `%s`.', 'duration', opts.duration ) );
|
|
92
|
+
}
|
|
93
|
+
t = ( opts.period-opts.offset ) % opts.period;
|
|
94
|
+
if ( t < 0 ) {
|
|
95
|
+
t += opts.period;
|
|
96
|
+
}
|
|
97
|
+
t -= 1;
|
|
98
|
+
i = 0;
|
|
99
|
+
|
|
100
|
+
// Create an iterator protocol-compliant object:
|
|
101
|
+
iter = {};
|
|
102
|
+
setReadOnly( iter, 'next', next );
|
|
103
|
+
setReadOnly( iter, 'return', end );
|
|
104
|
+
|
|
105
|
+
// If an environment supports `Symbol.iterator`, make the iterator iterable:
|
|
106
|
+
if ( iteratorSymbol ) {
|
|
107
|
+
setReadOnly( iter, iteratorSymbol, factory );
|
|
108
|
+
}
|
|
109
|
+
return iter;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Returns an iterator protocol-compliant object containing the next iterated value.
|
|
113
|
+
*
|
|
114
|
+
* @private
|
|
115
|
+
* @returns {Object} iterator protocol-compliant object
|
|
116
|
+
*/
|
|
117
|
+
function next() {
|
|
118
|
+
i += 1;
|
|
119
|
+
if ( FLG || i > opts.iter ) {
|
|
120
|
+
return {
|
|
121
|
+
'done': true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
t = (t+1) % opts.period;
|
|
125
|
+
return {
|
|
126
|
+
'value': ( t < opts.duration ) ? opts.max : opts.min,
|
|
127
|
+
'done': false
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Finishes an iterator.
|
|
133
|
+
*
|
|
134
|
+
* @private
|
|
135
|
+
* @param {*} [value] - value to return
|
|
136
|
+
* @returns {Object} iterator protocol-compliant object
|
|
137
|
+
*/
|
|
138
|
+
function end( value ) {
|
|
139
|
+
FLG = true;
|
|
140
|
+
if ( arguments.length ) {
|
|
141
|
+
return {
|
|
142
|
+
'value': value,
|
|
143
|
+
'done': true
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
'done': true
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Returns a new iterator.
|
|
153
|
+
*
|
|
154
|
+
* @private
|
|
155
|
+
* @returns {Iterator} iterator
|
|
156
|
+
*/
|
|
157
|
+
function factory() {
|
|
158
|
+
return iterPulse( opts );
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
// EXPORTS //
|
|
164
|
+
|
|
165
|
+
module.exports = iterPulse;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
|
|
24
|
+
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
|
|
25
|
+
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
|
|
26
|
+
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
|
|
27
|
+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
|
|
28
|
+
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
|
|
29
|
+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
|
|
30
|
+
var format = require( '@stdlib/string/format' );
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// MAIN //
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Validates function options.
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
* @param {Object} opts - destination object
|
|
40
|
+
* @param {Options} options - function options
|
|
41
|
+
* @param {PositiveInteger} [options.period] - number of iterations before a waveform repeats
|
|
42
|
+
* @param {PositiveInteger} [options.duration] - number of consecutive iterations of maximum amplitude during one period
|
|
43
|
+
* @param {number} [options.min] - minimum amplitude
|
|
44
|
+
* @param {number} [options.max] - maximum amplitude
|
|
45
|
+
* @param {integer} [options.offset] - phase offset (in units of iterations)
|
|
46
|
+
* @param {NonNegativeInteger} [options.iter] - number of iterations
|
|
47
|
+
* @returns {(Error|null)} null or an error object
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var opts = {};
|
|
51
|
+
* var options = {
|
|
52
|
+
* 'iter': 100
|
|
53
|
+
* };
|
|
54
|
+
* var err = validate( opts, options );
|
|
55
|
+
* if ( err ) {
|
|
56
|
+
* throw err;
|
|
57
|
+
* }
|
|
58
|
+
*/
|
|
59
|
+
function validate( opts, options ) {
|
|
60
|
+
if ( !isPlainObject( options ) ) {
|
|
61
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
62
|
+
}
|
|
63
|
+
if ( hasOwnProp( options, 'duration' ) ) {
|
|
64
|
+
opts.duration = options.duration;
|
|
65
|
+
if ( !isPositiveInteger( options.duration ) ) {
|
|
66
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'duration', options.duration ) );
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if ( hasOwnProp( options, 'period' ) ) {
|
|
70
|
+
opts.period = options.period;
|
|
71
|
+
if ( !isPositiveInteger( options.period ) ) {
|
|
72
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'period', options.period ) );
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if ( hasOwnProp( options, 'min' ) ) {
|
|
76
|
+
opts.min = options.min;
|
|
77
|
+
if ( !isNumber( options.min ) || isnan( options.min ) ) {
|
|
78
|
+
return new TypeError( format( 'invalid option. `%s` option must be a number. Option: `%s`.', 'min', options.min ) );
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if ( hasOwnProp( options, 'max' ) ) {
|
|
82
|
+
opts.max = options.max;
|
|
83
|
+
if ( !isNumber( options.max ) || isnan( options.max ) ) {
|
|
84
|
+
return new TypeError( format( 'invalid option. `%s` option must be a number. Option: `%s`.', 'max', options.max ) );
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if ( hasOwnProp( options, 'offset' ) ) {
|
|
88
|
+
opts.offset = options.offset;
|
|
89
|
+
if ( !isInteger( options.offset ) ) {
|
|
90
|
+
return new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'offset', options.offset ) );
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if ( hasOwnProp( options, 'iter' ) ) {
|
|
94
|
+
opts.iter = options.iter;
|
|
95
|
+
if ( !isNonNegativeInteger( options.iter ) ) {
|
|
96
|
+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', options.iter ) );
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
// EXPORTS //
|
|
104
|
+
|
|
105
|
+
module.exports = validate;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/simulate/iter/pulse",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Create an iterator which generates a pulse waveform.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"benchmark": "./benchmark",
|
|
19
|
+
"doc": "./docs",
|
|
20
|
+
"example": "./examples",
|
|
21
|
+
"lib": "./lib",
|
|
22
|
+
"test": "./test"
|
|
23
|
+
},
|
|
24
|
+
"types": "./docs/types",
|
|
25
|
+
"scripts": {},
|
|
26
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {},
|
|
35
|
+
"devDependencies": {},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=0.10.0",
|
|
38
|
+
"npm": ">2.7.0"
|
|
39
|
+
},
|
|
40
|
+
"os": [
|
|
41
|
+
"aix",
|
|
42
|
+
"darwin",
|
|
43
|
+
"freebsd",
|
|
44
|
+
"linux",
|
|
45
|
+
"macos",
|
|
46
|
+
"openbsd",
|
|
47
|
+
"sunos",
|
|
48
|
+
"win32",
|
|
49
|
+
"windows"
|
|
50
|
+
],
|
|
51
|
+
"keywords": [
|
|
52
|
+
"stdlib",
|
|
53
|
+
"simulate",
|
|
54
|
+
"simulation",
|
|
55
|
+
"square",
|
|
56
|
+
"rectangular",
|
|
57
|
+
"pulse",
|
|
58
|
+
"wave",
|
|
59
|
+
"train",
|
|
60
|
+
"signal",
|
|
61
|
+
"processing",
|
|
62
|
+
"waveform",
|
|
63
|
+
"periodic",
|
|
64
|
+
"iterator",
|
|
65
|
+
"iterate",
|
|
66
|
+
"iteration",
|
|
67
|
+
"iter"
|
|
68
|
+
]
|
|
69
|
+
}
|