@stdlib/utils-async-some-by-right 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,172 +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 someByRightAsync = 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
- someByRightAsync( [ 0, 1, 1 ], 2, isPositive, done ); // $ExpectType void
40
- someByRightAsync( [ -1, -1, 2 ], 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
- someByRightAsync( 2, 2, isPositive, done ); // $ExpectError
46
- someByRightAsync( false, 2, isPositive, done ); // $ExpectError
47
- someByRightAsync( true, 2, isPositive, done ); // $ExpectError
48
- someByRightAsync( {}, 2, isPositive, done ); // $ExpectError
49
- }
50
-
51
- // The compiler throws an error if the function is provided a second argument which is not a number...
52
- {
53
- someByRightAsync( [ 0, 1, 1 ], 'abc', isPositive, done ); // $ExpectError
54
- someByRightAsync( [ 0, 1, 1 ], true, isPositive, done ); // $ExpectError
55
- someByRightAsync( [ 0, 1, 1 ], false, isPositive, done ); // $ExpectError
56
- someByRightAsync( [ 0, 1, 1 ], [], isPositive, done ); // $ExpectError
57
- someByRightAsync( [ 0, 1, 1 ], {}, isPositive, done ); // $ExpectError
58
- someByRightAsync( [ 0, 1, 1 ], null, isPositive, done ); // $ExpectError
59
- someByRightAsync( [ 0, 1, 1 ], ( x: number ): number => x, isPositive, done ); // $ExpectError
60
- }
61
-
62
- // The compiler throws an error if the function is provided a predicate argument which is not a predicate function...
63
- {
64
- someByRightAsync( [ 1, 2, 3 ], 2, 2, done ); // $ExpectError
65
- someByRightAsync( [ 1, 2, 3 ], 2, false, done ); // $ExpectError
66
- someByRightAsync( [ 1, 2, 3 ], 2, true, done ); // $ExpectError
67
- someByRightAsync( [ 1, 2, 3 ], 2, 'abc', done ); // $ExpectError
68
- someByRightAsync( [ 1, 2, 3 ], 2, {}, done ); // $ExpectError
69
- someByRightAsync( [ 1, 2, 3 ], 2, [], done ); // $ExpectError
70
- }
71
-
72
- // The compiler throws an error if the function is provided a done callback argument which is not a function having a supported signature...
73
- {
74
- someByRightAsync( [ 1, 2, 3 ], 2, isPositive, 2 ); // $ExpectError
75
- someByRightAsync( [ 1, 2, 3 ], 2, isPositive, false ); // $ExpectError
76
- someByRightAsync( [ 1, 2, 3 ], 2, isPositive, true ); // $ExpectError
77
- someByRightAsync( [ 1, 2, 3 ], 2, isPositive, 'abc' ); // $ExpectError
78
- someByRightAsync( [ 1, 2, 3 ], 2, isPositive, {} ); // $ExpectError
79
- someByRightAsync( [ 1, 2, 3 ], 2, isPositive, [] ); // $ExpectError
80
- someByRightAsync( [ 1, 2, 3 ], 2, isPositive, ( x: number ): number => x ); // $ExpectError
81
- }
82
-
83
- // The compiler throws an error if the function is provided an invalid number of arguments...
84
- {
85
- someByRightAsync(); // $ExpectError
86
- someByRightAsync( [ 1, 2, 3 ] ); // $ExpectError
87
- someByRightAsync( [ 1, 2, 3 ], 2 ); // $ExpectError
88
- someByRightAsync( [ 1, 2, 3 ], 2, isPositive ); // $ExpectError
89
- someByRightAsync( [ 1, 2, 3 ], 2, {}, isPositive, done, {} ); // $ExpectError
90
- }
91
-
92
- // Attached to main export is a `factory` method which returns a function...
93
- {
94
- someByRightAsync.factory( isPositive ); // $ExpectType FactoryFunction
95
- someByRightAsync.factory( { 'series': true }, isPositive ); // $ExpectType FactoryFunction
96
- }
97
-
98
- // The compiler throws an error if the `factory` method is provided an options argument which is not an object...
99
- {
100
- someByRightAsync.factory( [], isPositive ); // $ExpectError
101
- someByRightAsync.factory( 123, isPositive ); // $ExpectError
102
- someByRightAsync.factory( 'abc', isPositive ); // $ExpectError
103
- someByRightAsync.factory( false, isPositive ); // $ExpectError
104
- someByRightAsync.factory( true, isPositive ); // $ExpectError
105
- }
106
-
107
- // The compiler throws an error if the `factory` method is provided a last argument which is not a predicate function...
108
- {
109
- someByRightAsync.factory( {} ); // $ExpectError
110
- someByRightAsync.factory( true ); // $ExpectError
111
- someByRightAsync.factory( false ); // $ExpectError
112
- someByRightAsync.factory( {}, 123 ); // $ExpectError
113
- someByRightAsync.factory( {}, 'abc' ); // $ExpectError
114
- }
115
-
116
- // The compiler throws an error if the function returned by the `factory` method is provided invalid arguments...
117
- {
118
- const fcn1 = someByRightAsync.factory( isPositive );
119
- fcn1( 12, 2, done ); // $ExpectError
120
- fcn1( true, 2, done ); // $ExpectError
121
- fcn1( false, 2, done ); // $ExpectError
122
- fcn1( {}, 2, done ); // $ExpectError
123
-
124
- fcn1( [ 1, 2, 3 ], true, done ); // $ExpectError
125
- fcn1( [ 1, 2, 3 ], false, done ); // $ExpectError
126
- fcn1( [ 1, 2, 3 ], '5', done ); // $ExpectError
127
- fcn1( [ 1, 2, 3 ], {}, done ); // $ExpectError
128
- fcn1( [ 1, 2, 3 ], [], done ); // $ExpectError
129
- fcn1( [ 1, 2, 3 ], ( x: number ): number => x, done ); // $ExpectError
130
-
131
- fcn1( [ 1, 2, 3 ], 2, 12 ); // $ExpectError
132
- fcn1( [ 1, 2, 3 ], 2, true ); // $ExpectError
133
- fcn1( [ 1, 2, 3 ], 2, false ); // $ExpectError
134
- fcn1( [ 1, 2, 3 ], 2, '5' ); // $ExpectError
135
- fcn1( [ 1, 2, 3 ], 2, {} ); // $ExpectError
136
- fcn1( [ 1, 2, 3 ], 2, [] ); // $ExpectError
137
- fcn1( [ 1, 2, 3 ], 2, ( x: number ): number => x ); // $ExpectError
138
- }
139
-
140
- // The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments...
141
- {
142
- const fcn1 = someByRightAsync.factory( isPositive );
143
- fcn1(); // $ExpectError
144
- fcn1( [ 1, 2, 3 ] ); // $ExpectError
145
- fcn1( [ 1, 2, 3 ], 2 ); // $ExpectError
146
- fcn1( [ 1, 2, 3 ], 2, done, {} ); // $ExpectError
147
- }
148
-
149
- // The compiler throws an error if the `factory` method is provided a `limit` option which is not a number...
150
- {
151
- someByRightAsync.factory( { 'limit': '12' }, isPositive ); // $ExpectError
152
- someByRightAsync.factory( { 'limit': true }, isPositive ); // $ExpectError
153
- someByRightAsync.factory( { 'limit': false }, isPositive ); // $ExpectError
154
- someByRightAsync.factory( { 'limit': {} }, isPositive ); // $ExpectError
155
- someByRightAsync.factory( { 'limit': [] }, isPositive ); // $ExpectError
156
- someByRightAsync.factory( { 'limit': ( x: number ): number => x }, isPositive ); // $ExpectError
157
- }
158
-
159
- // The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean...
160
- {
161
- someByRightAsync.factory( { 'series': '12' }, isPositive ); // $ExpectError
162
- someByRightAsync.factory( { 'series': 12 }, isPositive ); // $ExpectError
163
- someByRightAsync.factory( { 'series': {} }, isPositive ); // $ExpectError
164
- someByRightAsync.factory( { 'series': [] }, isPositive ); // $ExpectError
165
- someByRightAsync.factory( { 'series': ( x: number ): number => x }, isPositive ); // $ExpectError
166
- }
167
-
168
- // The compiler throws an error if the `factory` method is provided an invalid number of arguments...
169
- {
170
- someByRightAsync.factory(); // $ExpectError
171
- someByRightAsync.factory( {}, isPositive, {} ); // $ExpectError
172
- }