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