@stdlib/utils-async-every-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.
@@ -1,152 +0,0 @@
1
- /*
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2020 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 everyByAsync = require( './index' );
20
-
21
- const isPositive = ( v: number ): boolean => {
22
- return ( v > 0 );
23
- };
24
-
25
- const done = ( error: Error | null, bool: boolean ) => {
26
- if ( error ) {
27
- throw error;
28
- }
29
- if ( bool === void 0 ) {
30
- throw new Error( '`bool` is not a boolean.' );
31
- }
32
- };
33
-
34
-
35
- // TESTS //
36
-
37
- // The function returns void...
38
- {
39
- everyByAsync( [ 0, 1, 1 ], isPositive, done ); // $ExpectType void
40
- everyByAsync( [ -1, 1, 2 ], isPositive, done ); // $ExpectType void
41
- }
42
-
43
- // The compiler throws an error if the function is provided a first argument which is not a collection...
44
- {
45
- everyByAsync( 2, isPositive, done ); // $ExpectError
46
- everyByAsync( false, isPositive, done ); // $ExpectError
47
- everyByAsync( true, isPositive, done ); // $ExpectError
48
- everyByAsync( {}, isPositive, done ); // $ExpectError
49
- }
50
-
51
- // The compiler throws an error if the function is provided a predicate argument which is not a predicate function...
52
- {
53
- everyByAsync( [ 1, 2, 3 ], 2, done ); // $ExpectError
54
- everyByAsync( [ 1, 2, 3 ], false, done ); // $ExpectError
55
- everyByAsync( [ 1, 2, 3 ], true, done ); // $ExpectError
56
- everyByAsync( [ 1, 2, 3 ], 'abc', done ); // $ExpectError
57
- everyByAsync( [ 1, 2, 3 ], {}, done ); // $ExpectError
58
- everyByAsync( [ 1, 2, 3 ], [], done ); // $ExpectError
59
- }
60
-
61
- // The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature...
62
- {
63
- everyByAsync( [ 1, 2, 3 ], isPositive, 2 ); // $ExpectError
64
- everyByAsync( [ 1, 2, 3 ], isPositive, false ); // $ExpectError
65
- everyByAsync( [ 1, 2, 3 ], isPositive, true ); // $ExpectError
66
- everyByAsync( [ 1, 2, 3 ], isPositive, 'abc' ); // $ExpectError
67
- everyByAsync( [ 1, 2, 3 ], isPositive, {} ); // $ExpectError
68
- everyByAsync( [ 1, 2, 3 ], isPositive, [] ); // $ExpectError
69
- everyByAsync( [ 1, 2, 3 ], isPositive, ( x: number ): number => x ); // $ExpectError
70
- }
71
-
72
- // The compiler throws an error if the function is provided an invalid number of arguments...
73
- {
74
- everyByAsync(); // $ExpectError
75
- everyByAsync( [ 1, 2, 3 ] ); // $ExpectError
76
- everyByAsync( [ 1, 2, 3 ], isPositive ); // $ExpectError
77
- everyByAsync( [ 1, 2, 3 ], {}, isPositive, done, {} ); // $ExpectError
78
- }
79
-
80
- // Attached to main export is a `factory` method which returns a function...
81
- {
82
- everyByAsync.factory( isPositive ); // $ExpectType FactoryFunction
83
- everyByAsync.factory( { 'series': true }, isPositive ); // $ExpectType FactoryFunction
84
- }
85
-
86
- // The compiler throws an error if the `factory` method is provided an options argument which is not an object...
87
- {
88
- everyByAsync.factory( [], isPositive ); // $ExpectError
89
- everyByAsync.factory( 123, isPositive ); // $ExpectError
90
- everyByAsync.factory( 'abc', isPositive ); // $ExpectError
91
- everyByAsync.factory( false, isPositive ); // $ExpectError
92
- everyByAsync.factory( true, isPositive ); // $ExpectError
93
- }
94
-
95
- // The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function...
96
- {
97
- everyByAsync.factory( {} ); // $ExpectError
98
- everyByAsync.factory( true ); // $ExpectError
99
- everyByAsync.factory( false ); // $ExpectError
100
- everyByAsync.factory( {}, 123 ); // $ExpectError
101
- everyByAsync.factory( {}, 'abc' ); // $ExpectError
102
- }
103
-
104
- // The compiler throws an error if the function returned by the `factory` method is provided invalid arguments...
105
- {
106
- const fcn1 = everyByAsync.factory( isPositive );
107
- fcn1( 12, done ); // $ExpectError
108
- fcn1( true, done ); // $ExpectError
109
- fcn1( false, done ); // $ExpectError
110
- fcn1( {}, done ); // $ExpectError
111
-
112
- fcn1( [ 1, 2, 3 ], 12 ); // $ExpectError
113
- fcn1( [ 1, 2, 3 ], true ); // $ExpectError
114
- fcn1( [ 1, 2, 3 ], false ); // $ExpectError
115
- fcn1( [ 1, 2, 3 ], '5' ); // $ExpectError
116
- fcn1( [ 1, 2, 3 ], {} ); // $ExpectError
117
- fcn1( [ 1, 2, 3 ], [] ); // $ExpectError
118
- fcn1( [ 1, 2, 3 ], ( x: number ): number => x ); // $ExpectError
119
- }
120
-
121
- // The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments...
122
- {
123
- const fcn1 = everyByAsync.factory( isPositive );
124
- fcn1(); // $ExpectError
125
- fcn1( [ 1, 2, 3 ] ); // $ExpectError
126
- fcn1( [ 1, 2, 3 ], done, {} ); // $ExpectError
127
- }
128
-
129
- // The compiler throws an error if the `factory` method is provided a `limit` option which is not a number...
130
- {
131
- everyByAsync.factory( { 'limit': '12' }, isPositive ); // $ExpectError
132
- everyByAsync.factory( { 'limit': true }, isPositive ); // $ExpectError
133
- everyByAsync.factory( { 'limit': false }, isPositive ); // $ExpectError
134
- everyByAsync.factory( { 'limit': {} }, isPositive ); // $ExpectError
135
- everyByAsync.factory( { 'limit': [] }, isPositive ); // $ExpectError
136
- everyByAsync.factory( { 'limit': ( x: number ): number => x }, isPositive ); // $ExpectError
137
- }
138
-
139
- // The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean...
140
- {
141
- everyByAsync.factory( { 'series': '12' }, isPositive ); // $ExpectError
142
- everyByAsync.factory( { 'series': 12 }, isPositive ); // $ExpectError
143
- everyByAsync.factory( { 'series': {} }, isPositive ); // $ExpectError
144
- everyByAsync.factory( { 'series': [] }, isPositive ); // $ExpectError
145
- everyByAsync.factory( { 'series': ( x: number ): number => x }, isPositive ); // $ExpectError
146
- }
147
-
148
- // The compiler throws an error if the `factory` method is provided an invalid number of arguments...
149
- {
150
- everyByAsync.factory(); // $ExpectError
151
- everyByAsync.factory( {}, isPositive, {} ); // $ExpectError
152
- }