@stdlib/utils-async-group-by 0.0.8 → 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 +38 -23
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +357 -41
- package/lib/factory.js +4 -4
- package/lib/index.js +3 -3
- package/lib/limit.js +0 -1
- package/lib/{group_by.js → main.js} +0 -1
- package/lib/validate.js +5 -4
- package/package.json +21 -18
- package/docs/repl.txt +0 -232
- package/docs/types/test.ts +0 -201
package/lib/validate.js
CHANGED
|
@@ -25,6 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
|
25
25
|
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
|
|
26
26
|
var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive;
|
|
27
27
|
var indexOf = require( '@stdlib/utils-index-of' );
|
|
28
|
+
var format = require( '@stdlib/string-format' );
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
// VARIABLES //
|
|
@@ -61,7 +62,7 @@ var returns = [ 'values', 'indices', '*' ];
|
|
|
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, 'thisArg' ) ) {
|
|
67
68
|
opts.thisArg = options.thisArg;
|
|
@@ -69,19 +70,19 @@ function validate( opts, options ) {
|
|
|
69
70
|
if ( hasOwnProp( options, 'series' ) ) {
|
|
70
71
|
opts.series = options.series;
|
|
71
72
|
if ( !isBoolean( opts.series ) ) {
|
|
72
|
-
return new TypeError( 'invalid option. `
|
|
73
|
+
return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) );
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
if ( hasOwnProp( options, 'limit' ) ) {
|
|
76
77
|
opts.limit = options.limit;
|
|
77
78
|
if ( !isPositiveInteger( opts.limit ) ) {
|
|
78
|
-
return new TypeError( 'invalid option. `
|
|
79
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) );
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
if ( hasOwnProp( options, 'returns' ) ) {
|
|
82
83
|
opts.returns = options.returns;
|
|
83
84
|
if ( indexOf( returns, opts.returns ) === -1 ) {
|
|
84
|
-
return new TypeError( 'invalid option. `
|
|
85
|
+
return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'returns', returns.join( '", "' ), opts.returns ) );
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/utils-async-group-by",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Group values according to an indicator function.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -37,25 +37,28 @@
|
|
|
37
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@stdlib/assert-has-own-property": "^0.
|
|
41
|
-
"@stdlib/assert-is-boolean": "^0.0
|
|
42
|
-
"@stdlib/assert-is-collection": "^0.0
|
|
43
|
-
"@stdlib/assert-is-function": "^0.0
|
|
44
|
-
"@stdlib/assert-is-plain-object": "^0.0
|
|
45
|
-
"@stdlib/assert-is-positive-integer": "^0.0
|
|
46
|
-
"@stdlib/constants-float64-pinf": "^0.0
|
|
47
|
-
"@stdlib/
|
|
48
|
-
"@stdlib/
|
|
49
|
-
"@stdlib/utils-
|
|
50
|
-
"
|
|
40
|
+
"@stdlib/assert-has-own-property": "^0.1.1",
|
|
41
|
+
"@stdlib/assert-is-boolean": "^0.2.0",
|
|
42
|
+
"@stdlib/assert-is-collection": "^0.2.0",
|
|
43
|
+
"@stdlib/assert-is-function": "^0.2.0",
|
|
44
|
+
"@stdlib/assert-is-plain-object": "^0.2.0",
|
|
45
|
+
"@stdlib/assert-is-positive-integer": "^0.2.0",
|
|
46
|
+
"@stdlib/constants-float64-pinf": "^0.2.0",
|
|
47
|
+
"@stdlib/string-format": "^0.2.0",
|
|
48
|
+
"@stdlib/types": "^0.3.1",
|
|
49
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0",
|
|
50
|
+
"@stdlib/utils-index-of": "^0.2.0",
|
|
51
|
+
"debug": "^2.6.9",
|
|
52
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.1.1"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
|
-
"@stdlib/
|
|
54
|
-
"@stdlib/
|
|
55
|
-
"@stdlib/utils-noop": "^0.0.x",
|
|
55
|
+
"@stdlib/fs-read-file": "^0.1.1",
|
|
56
|
+
"@stdlib/utils-noop": "^0.2.0",
|
|
56
57
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
57
58
|
"istanbul": "^0.4.1",
|
|
58
|
-
"tap-
|
|
59
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",
|
|
60
|
+
"@stdlib/bench-harness": "^0.1.2",
|
|
61
|
+
"@stdlib/bench": "^0.3.1"
|
|
59
62
|
},
|
|
60
63
|
"engines": {
|
|
61
64
|
"node": ">=0.10.0",
|
|
@@ -94,7 +97,7 @@
|
|
|
94
97
|
"array-like"
|
|
95
98
|
],
|
|
96
99
|
"funding": {
|
|
97
|
-
"type": "
|
|
98
|
-
"url": "https://
|
|
100
|
+
"type": "opencollective",
|
|
101
|
+
"url": "https://opencollective.com/stdlib"
|
|
99
102
|
}
|
|
100
103
|
}
|
package/docs/repl.txt
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
{{alias}}( collection, [options,] indicator, done )
|
|
3
|
-
Groups values according to an indicator function.
|
|
4
|
-
|
|
5
|
-
When invoked, the indicator function is provided a maximum of four
|
|
6
|
-
arguments:
|
|
7
|
-
|
|
8
|
-
- `value`: collection value
|
|
9
|
-
- `index`: collection index
|
|
10
|
-
- `collection`: the input collection
|
|
11
|
-
- `next`: a callback to be invoked after processing a collection `value`
|
|
12
|
-
|
|
13
|
-
The actual number of provided arguments depends on function length. If the
|
|
14
|
-
indicator function accepts two arguments, the indicator function is
|
|
15
|
-
provided:
|
|
16
|
-
|
|
17
|
-
- `value`
|
|
18
|
-
- `next`
|
|
19
|
-
|
|
20
|
-
If the indicator function accepts three arguments, the indicator function is
|
|
21
|
-
provided:
|
|
22
|
-
|
|
23
|
-
- `value`
|
|
24
|
-
- `index`
|
|
25
|
-
- `next`
|
|
26
|
-
|
|
27
|
-
For every other indicator function signature, the indicator function is
|
|
28
|
-
provided all four arguments.
|
|
29
|
-
|
|
30
|
-
The `next` callback takes two arguments:
|
|
31
|
-
|
|
32
|
-
- `error`: error argument
|
|
33
|
-
- `group`: value group
|
|
34
|
-
|
|
35
|
-
If an indicator function calls the `next` callback with a truthy `error`
|
|
36
|
-
argument, the function suspends execution and immediately calls the `done`
|
|
37
|
-
callback for subsequent `error` handling.
|
|
38
|
-
|
|
39
|
-
If provided an empty collection, the function calls the `done` callback with
|
|
40
|
-
an empty object as the second argument.
|
|
41
|
-
|
|
42
|
-
The `group` returned by an indicator function should be a value which can be
|
|
43
|
-
serialized as an object key.
|
|
44
|
-
|
|
45
|
-
Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony,
|
|
46
|
-
wrap the `done` callback in a function which either executes at the end of
|
|
47
|
-
the current stack (e.g., `nextTick`) or during a subsequent turn of the
|
|
48
|
-
event loop (e.g., `setImmediate`, `setTimeout`).
|
|
49
|
-
|
|
50
|
-
The function does not support dynamic collection resizing.
|
|
51
|
-
|
|
52
|
-
The function does not skip `undefined` elements.
|
|
53
|
-
|
|
54
|
-
Parameters
|
|
55
|
-
----------
|
|
56
|
-
collection: Array|TypedArray|Object
|
|
57
|
-
Input collection over which to iterate. If provided an object, the
|
|
58
|
-
object must be array-like (excluding strings and functions).
|
|
59
|
-
|
|
60
|
-
options: Object (optional)
|
|
61
|
-
Function options.
|
|
62
|
-
|
|
63
|
-
options.limit: integer (optional)
|
|
64
|
-
Maximum number of pending invocations. Default: Infinity.
|
|
65
|
-
|
|
66
|
-
options.series: boolean (optional)
|
|
67
|
-
Boolean indicating whether to process each collection element
|
|
68
|
-
sequentially. Default: false.
|
|
69
|
-
|
|
70
|
-
options.returns: string (optional)
|
|
71
|
-
If `values`, values are returned; if `indices`, indices are returned; if
|
|
72
|
-
`*`, both indices and values are returned. Default: 'values'.
|
|
73
|
-
|
|
74
|
-
options.thisArg: any (optional)
|
|
75
|
-
Execution context.
|
|
76
|
-
|
|
77
|
-
indicator: Function
|
|
78
|
-
Indicator function specifying which group an element in the input
|
|
79
|
-
collection belongs to.
|
|
80
|
-
|
|
81
|
-
done: Function
|
|
82
|
-
A callback invoked either upon processing all collection elements or
|
|
83
|
-
upon encountering an error.
|
|
84
|
-
|
|
85
|
-
Examples
|
|
86
|
-
--------
|
|
87
|
-
// Basic usage:
|
|
88
|
-
> function indicator( value, index, next ) {
|
|
89
|
-
... setTimeout( onTimeout, value );
|
|
90
|
-
... function onTimeout() {
|
|
91
|
-
... console.log( value );
|
|
92
|
-
... next( null, ( index%2 === 0 ) );
|
|
93
|
-
... }
|
|
94
|
-
... };
|
|
95
|
-
> function done( error, result ) {
|
|
96
|
-
... if ( error ) {
|
|
97
|
-
... throw error;
|
|
98
|
-
... }
|
|
99
|
-
... console.log( result );
|
|
100
|
-
... };
|
|
101
|
-
> var arr = [ 3000, 2500, 1000 ];
|
|
102
|
-
> {{alias}}( arr, indicator, done )
|
|
103
|
-
1000
|
|
104
|
-
2500
|
|
105
|
-
3000
|
|
106
|
-
{ "true": [ 1000, 3000 ], "false": [ 2500 ] }
|
|
107
|
-
|
|
108
|
-
// Output group results as indices:
|
|
109
|
-
> var opts = { 'returns': 'indices' };
|
|
110
|
-
> {{alias}}( arr, opts, indicator, done )
|
|
111
|
-
1000
|
|
112
|
-
2500
|
|
113
|
-
3000
|
|
114
|
-
{ "true": [ 2, 0 ], "false": [ 1 ] }
|
|
115
|
-
|
|
116
|
-
// Output group results as index-value pairs:
|
|
117
|
-
> opts = { 'returns': '*' };
|
|
118
|
-
> {{alias}}( arr, opts, indicator, done )
|
|
119
|
-
1000
|
|
120
|
-
2500
|
|
121
|
-
3000
|
|
122
|
-
{ "true": [ [ 2, 1000 ], [ 0, 3000 ] ], "false": [ [ 1, 2500 ] ] }
|
|
123
|
-
|
|
124
|
-
// Limit number of concurrent invocations:
|
|
125
|
-
> function indicator( value, index, next ) {
|
|
126
|
-
... setTimeout( onTimeout, value );
|
|
127
|
-
... function onTimeout() {
|
|
128
|
-
... console.log( value );
|
|
129
|
-
... next( null, ( index%2 === 0 ) );
|
|
130
|
-
... }
|
|
131
|
-
... };
|
|
132
|
-
> function done( error, result ) {
|
|
133
|
-
... if ( error ) {
|
|
134
|
-
... throw error;
|
|
135
|
-
... }
|
|
136
|
-
... console.log( result );
|
|
137
|
-
... };
|
|
138
|
-
> var opts = { 'limit': 2 };
|
|
139
|
-
> var arr = [ 3000, 2500, 1000 ];
|
|
140
|
-
> {{alias}}( arr, opts, indicator, done )
|
|
141
|
-
2500
|
|
142
|
-
3000
|
|
143
|
-
1000
|
|
144
|
-
{ "true": [ 3000, 1000 ], "false": [ 2500 ] }
|
|
145
|
-
|
|
146
|
-
// Process sequentially:
|
|
147
|
-
> function indicator( value, index, next ) {
|
|
148
|
-
... setTimeout( onTimeout, value );
|
|
149
|
-
... function onTimeout() {
|
|
150
|
-
... console.log( value );
|
|
151
|
-
... next( null, ( index%2 === 0 ) );
|
|
152
|
-
... }
|
|
153
|
-
... };
|
|
154
|
-
> function done( error, result ) {
|
|
155
|
-
... if ( error ) {
|
|
156
|
-
... throw error;
|
|
157
|
-
... }
|
|
158
|
-
... console.log( result );
|
|
159
|
-
... };
|
|
160
|
-
> var opts = { 'series': true };
|
|
161
|
-
> var arr = [ 3000, 2500, 1000 ];
|
|
162
|
-
> {{alias}}( arr, opts, indicator, done )
|
|
163
|
-
3000
|
|
164
|
-
2500
|
|
165
|
-
1000
|
|
166
|
-
{ "true": [ 3000, 1000 ], "false": [ 2500 ] }
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
{{alias}}.factory( [options,] indicator )
|
|
170
|
-
Returns a function which groups values according to an indicator function.
|
|
171
|
-
|
|
172
|
-
Parameters
|
|
173
|
-
----------
|
|
174
|
-
options: Object (optional)
|
|
175
|
-
Function options.
|
|
176
|
-
|
|
177
|
-
options.limit: integer (optional)
|
|
178
|
-
Maximum number of pending invocations. Default: Infinity.
|
|
179
|
-
|
|
180
|
-
options.series: boolean (optional)
|
|
181
|
-
Boolean indicating whether to process each collection element
|
|
182
|
-
sequentially. Default: false.
|
|
183
|
-
|
|
184
|
-
options.returns: string (optional)
|
|
185
|
-
If `values`, values are returned; if `indices`, indices are returned; if
|
|
186
|
-
`*`, both indices and values are returned. Default: 'values'.
|
|
187
|
-
|
|
188
|
-
options.thisArg: any (optional)
|
|
189
|
-
Execution context.
|
|
190
|
-
|
|
191
|
-
indicator: Function
|
|
192
|
-
Indicator function specifying which group an element in the input
|
|
193
|
-
collection belongs to.
|
|
194
|
-
|
|
195
|
-
Returns
|
|
196
|
-
-------
|
|
197
|
-
out: Function
|
|
198
|
-
A group-by function.
|
|
199
|
-
|
|
200
|
-
Examples
|
|
201
|
-
--------
|
|
202
|
-
> function indicator( value, index, next ) {
|
|
203
|
-
... setTimeout( onTimeout, value );
|
|
204
|
-
... function onTimeout() {
|
|
205
|
-
... console.log( value );
|
|
206
|
-
... next( null, ( index%2 === 0 ) );
|
|
207
|
-
... }
|
|
208
|
-
... };
|
|
209
|
-
> var opts = { 'series': true };
|
|
210
|
-
> var f = {{alias}}.factory( opts, indicator );
|
|
211
|
-
> function done( error, result ) {
|
|
212
|
-
... if ( error ) {
|
|
213
|
-
... throw error;
|
|
214
|
-
... }
|
|
215
|
-
... console.log( result );
|
|
216
|
-
... };
|
|
217
|
-
> var arr = [ 3000, 2500, 1000 ];
|
|
218
|
-
> f( arr, done )
|
|
219
|
-
3000
|
|
220
|
-
2500
|
|
221
|
-
1000
|
|
222
|
-
{ "true": [ 3000, 1000 ], "false": [ 2500 ] }
|
|
223
|
-
> arr = [ 2000, 1500, 1000 ];
|
|
224
|
-
> f( arr, done )
|
|
225
|
-
2000
|
|
226
|
-
1500
|
|
227
|
-
1000
|
|
228
|
-
{ "true": [ 2000, 1000 ], "false": [ 1500 ] }
|
|
229
|
-
|
|
230
|
-
See Also
|
|
231
|
-
--------
|
|
232
|
-
|
package/docs/types/test.ts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2021 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 groupByAsync = require( './index' );
|
|
20
|
-
|
|
21
|
-
const indicator = ( value: number, next: Function ) => {
|
|
22
|
-
next( null, ( value > 2000 ) );
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const done = ( error: Error | null, result: any ) => {
|
|
26
|
-
if ( error ) {
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
if ( result === void 0 ) {
|
|
30
|
-
throw new Error( '`result` is missing.' );
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// TESTS //
|
|
36
|
-
|
|
37
|
-
// The function returns void...
|
|
38
|
-
{
|
|
39
|
-
groupByAsync( [ 3000, 2500, 1000 ], indicator, done ); // $ExpectType void
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// The compiler throws an error if the function is provided a first argument which is not a collection...
|
|
43
|
-
{
|
|
44
|
-
groupByAsync( 2, indicator, done ); // $ExpectError
|
|
45
|
-
groupByAsync( false, indicator, done ); // $ExpectError
|
|
46
|
-
groupByAsync( true, indicator, done ); // $ExpectError
|
|
47
|
-
groupByAsync( {}, indicator, done ); // $ExpectError
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// The compiler throws an error if the function is provided an indicator argument which is not an indicator function...
|
|
51
|
-
{
|
|
52
|
-
groupByAsync( [ 3000, 2500, 1000 ], 2, done ); // $ExpectError
|
|
53
|
-
groupByAsync( [ 3000, 2500, 1000 ], false, done ); // $ExpectError
|
|
54
|
-
groupByAsync( [ 3000, 2500, 1000 ], true, done ); // $ExpectError
|
|
55
|
-
groupByAsync( [ 3000, 2500, 1000 ], 'abc', done ); // $ExpectError
|
|
56
|
-
groupByAsync( [ 3000, 2500, 1000 ], {}, done ); // $ExpectError
|
|
57
|
-
groupByAsync( [ 3000, 2500, 1000 ], [], done ); // $ExpectError
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature...
|
|
61
|
-
{
|
|
62
|
-
groupByAsync( [ 3000, 2500, 1000 ], indicator, 2 ); // $ExpectError
|
|
63
|
-
groupByAsync( [ 3000, 2500, 1000 ], indicator, false ); // $ExpectError
|
|
64
|
-
groupByAsync( [ 3000, 2500, 1000 ], indicator, true ); // $ExpectError
|
|
65
|
-
groupByAsync( [ 3000, 2500, 1000 ], indicator, 'abc' ); // $ExpectError
|
|
66
|
-
groupByAsync( [ 3000, 2500, 1000 ], indicator, {} ); // $ExpectError
|
|
67
|
-
groupByAsync( [ 3000, 2500, 1000 ], indicator, [] ); // $ExpectError
|
|
68
|
-
groupByAsync( [ 3000, 2500, 1000 ], indicator, ( x: number ): number => x ); // $ExpectError
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// The compiler throws an error if the function is provided an options argument which is not an object...
|
|
72
|
-
{
|
|
73
|
-
groupByAsync( [ 3000, 2500, 1000 ], [], indicator, done ); // $ExpectError
|
|
74
|
-
groupByAsync( [ 3000, 2500, 1000 ], 123, indicator, done ); // $ExpectError
|
|
75
|
-
groupByAsync( [ 3000, 2500, 1000 ], 'abc', indicator, done ); // $ExpectError
|
|
76
|
-
groupByAsync( [ 3000, 2500, 1000 ], false, indicator, done ); // $ExpectError
|
|
77
|
-
groupByAsync( [ 3000, 2500, 1000 ], true, indicator, done ); // $ExpectError
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// The compiler throws an error if the function is provided a `limit` option which is not a number...
|
|
81
|
-
{
|
|
82
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'limit': '12' }, indicator, done ); // $ExpectError
|
|
83
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'limit': true }, indicator, done ); // $ExpectError
|
|
84
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'limit': false }, indicator, done ); // $ExpectError
|
|
85
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'limit': {} }, indicator, done ); // $ExpectError
|
|
86
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'limit': [] }, indicator, done ); // $ExpectError
|
|
87
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'limit': ( x: number ): number => x }, indicator, done ); // $ExpectError
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// The compiler throws an error if the function is provided a `series` option which is not a boolean...
|
|
91
|
-
{
|
|
92
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'series': '12' }, indicator, done ); // $ExpectError
|
|
93
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'series': 12 }, indicator, done ); // $ExpectError
|
|
94
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'series': {} }, indicator, done ); // $ExpectError
|
|
95
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'series': [] }, indicator, done ); // $ExpectError
|
|
96
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'series': ( x: number ): number => x }, indicator, done ); // $ExpectError
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// The compiler throws an error if the function is provided a `returns` option which is not `values`, `indices`, or `*`...
|
|
100
|
-
{
|
|
101
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'returns': 'abc' }, indicator, done ); // $ExpectError
|
|
102
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'returns': 12 }, indicator, done ); // $ExpectError
|
|
103
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'returns': true }, indicator, done ); // $ExpectError
|
|
104
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'returns': false }, indicator, done ); // $ExpectError
|
|
105
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'returns': {} }, indicator, done ); // $ExpectError
|
|
106
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'returns': [] }, indicator, done ); // $ExpectError
|
|
107
|
-
groupByAsync( [ 3000, 2500, 1000 ], { 'returns': ( x: number ): number => x }, indicator, done ); // $ExpectError
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// The compiler throws an error if the function is provided an invalid number of arguments...
|
|
111
|
-
{
|
|
112
|
-
groupByAsync(); // $ExpectError
|
|
113
|
-
groupByAsync( [ 3000, 2500, 1000 ] ); // $ExpectError
|
|
114
|
-
groupByAsync( [ 3000, 2500, 1000 ], indicator ); // $ExpectError
|
|
115
|
-
groupByAsync( [ 3000, 2500, 1000 ], {}, indicator, done, {} ); // $ExpectError
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Attached to main export is a `factory` method which returns a function...
|
|
119
|
-
{
|
|
120
|
-
groupByAsync.factory( indicator ); // $ExpectType FactoryFunction
|
|
121
|
-
groupByAsync.factory( { 'series': true }, indicator ); // $ExpectType FactoryFunction
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// The compiler throws an error if the `factory` method is provided an options argument which is not an object...
|
|
125
|
-
{
|
|
126
|
-
groupByAsync.factory( [], indicator ); // $ExpectError
|
|
127
|
-
groupByAsync.factory( 123, indicator ); // $ExpectError
|
|
128
|
-
groupByAsync.factory( 'abc', indicator ); // $ExpectError
|
|
129
|
-
groupByAsync.factory( false, indicator ); // $ExpectError
|
|
130
|
-
groupByAsync.factory( true, indicator ); // $ExpectError
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// The compiler throws an error if the `factory` method is provided a last argument which is not an indicator function...
|
|
134
|
-
{
|
|
135
|
-
groupByAsync.factory( {} ); // $ExpectError
|
|
136
|
-
groupByAsync.factory( true ); // $ExpectError
|
|
137
|
-
groupByAsync.factory( false ); // $ExpectError
|
|
138
|
-
groupByAsync.factory( {}, 123 ); // $ExpectError
|
|
139
|
-
groupByAsync.factory( {}, 'abc' ); // $ExpectError
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments...
|
|
143
|
-
{
|
|
144
|
-
const fcn1 = groupByAsync.factory( indicator );
|
|
145
|
-
fcn1( 12, done ); // $ExpectError
|
|
146
|
-
fcn1( true, done ); // $ExpectError
|
|
147
|
-
fcn1( false, done ); // $ExpectError
|
|
148
|
-
fcn1( {}, done ); // $ExpectError
|
|
149
|
-
|
|
150
|
-
fcn1( [ 3000, 2500, 1000 ], 12 ); // $ExpectError
|
|
151
|
-
fcn1( [ 3000, 2500, 1000 ], true ); // $ExpectError
|
|
152
|
-
fcn1( [ 3000, 2500, 1000 ], false ); // $ExpectError
|
|
153
|
-
fcn1( [ 3000, 2500, 1000 ], '5' ); // $ExpectError
|
|
154
|
-
fcn1( [ 3000, 2500, 1000 ], {} ); // $ExpectError
|
|
155
|
-
fcn1( [ 3000, 2500, 1000 ], [] ); // $ExpectError
|
|
156
|
-
fcn1( [ 3000, 2500, 1000 ], ( x: number ): number => x ); // $ExpectError
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments...
|
|
160
|
-
{
|
|
161
|
-
const fcn1 = groupByAsync.factory( indicator );
|
|
162
|
-
fcn1(); // $ExpectError
|
|
163
|
-
fcn1( [ 3000, 2500, 1000 ] ); // $ExpectError
|
|
164
|
-
fcn1( [ 3000, 2500, 1000 ], done, {} ); // $ExpectError
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number...
|
|
168
|
-
{
|
|
169
|
-
groupByAsync.factory( { 'limit': '12' }, indicator ); // $ExpectError
|
|
170
|
-
groupByAsync.factory( { 'limit': true }, indicator ); // $ExpectError
|
|
171
|
-
groupByAsync.factory( { 'limit': false }, indicator ); // $ExpectError
|
|
172
|
-
groupByAsync.factory( { 'limit': {} }, indicator ); // $ExpectError
|
|
173
|
-
groupByAsync.factory( { 'limit': [] }, indicator ); // $ExpectError
|
|
174
|
-
groupByAsync.factory( { 'limit': ( x: number ): number => x }, indicator ); // $ExpectError
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean...
|
|
178
|
-
{
|
|
179
|
-
groupByAsync.factory( { 'series': '12' }, indicator ); // $ExpectError
|
|
180
|
-
groupByAsync.factory( { 'series': 12 }, indicator ); // $ExpectError
|
|
181
|
-
groupByAsync.factory( { 'series': {} }, indicator ); // $ExpectError
|
|
182
|
-
groupByAsync.factory( { 'series': [] }, indicator ); // $ExpectError
|
|
183
|
-
groupByAsync.factory( { 'series': ( x: number ): number => x }, indicator ); // $ExpectError
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// The compiler throws an error if the `factory` method is provided a `returns` option which is not `values`, `indices`, or `*`...
|
|
187
|
-
{
|
|
188
|
-
groupByAsync.factory( { 'returns': 'abc' }, indicator ); // $ExpectError
|
|
189
|
-
groupByAsync.factory( { 'returns': 12 }, indicator ); // $ExpectError
|
|
190
|
-
groupByAsync.factory( { 'returns': true }, indicator ); // $ExpectError
|
|
191
|
-
groupByAsync.factory( { 'returns': false }, indicator ); // $ExpectError
|
|
192
|
-
groupByAsync.factory( { 'returns': {} }, indicator ); // $ExpectError
|
|
193
|
-
groupByAsync.factory( { 'returns': [] }, indicator ); // $ExpectError
|
|
194
|
-
groupByAsync.factory( { 'returns': ( x: number ): number => x }, indicator ); // $ExpectError
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// The compiler throws an error if the `factory` method is provided an invalid number of arguments...
|
|
198
|
-
{
|
|
199
|
-
groupByAsync.factory(); // $ExpectError
|
|
200
|
-
groupByAsync.factory( {}, indicator, {} ); // $ExpectError
|
|
201
|
-
}
|