@stdlib/utils-map 0.0.1 → 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 +46 -16
- 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 +34 -34
- package/lib/array.js +6 -6
- package/lib/assign.js +5 -4
- package/lib/main.js +3 -2
- package/lib/ndarray.js +6 -6
- package/package.json +35 -32
- package/docs/repl.txt +0 -106
- package/docs/types/test.ts +0 -270
package/docs/types/test.ts
DELETED
|
@@ -1,270 +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 array = require( '@stdlib/ndarray-array' );
|
|
20
|
-
import map = require( './index' );
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Callback function.
|
|
24
|
-
*
|
|
25
|
-
* @param v - argument
|
|
26
|
-
* @returns result
|
|
27
|
-
*/
|
|
28
|
-
function clbk( v: any ): any {
|
|
29
|
-
return v;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// TESTS //
|
|
34
|
-
|
|
35
|
-
// The function returns a collection when provided a collection...
|
|
36
|
-
{
|
|
37
|
-
const arr = [ 1, 2, 3, 4, 5, 6 ];
|
|
38
|
-
|
|
39
|
-
map( arr, clbk ); // $ExpectType Collection
|
|
40
|
-
map( arr, clbk, {} ); // $ExpectType Collection
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// The function returns an ndarray when provided an ndarray...
|
|
44
|
-
{
|
|
45
|
-
const arr = array( [ 1, 2, 3, 4, 5, 6 ] );
|
|
46
|
-
|
|
47
|
-
map( arr, clbk ); // $ExpectType ndarray
|
|
48
|
-
map( arr, clbk, {} ); // $ExpectType ndarray
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// The compiler throws an error if the function is provided a first argument other than a collection or ndarray...
|
|
52
|
-
{
|
|
53
|
-
map( 5, clbk ); // $ExpectError
|
|
54
|
-
map( true, clbk ); // $ExpectError
|
|
55
|
-
map( false, clbk ); // $ExpectError
|
|
56
|
-
map( null, clbk, {} ); // $ExpectError
|
|
57
|
-
map( {}, clbk ); // $ExpectError
|
|
58
|
-
|
|
59
|
-
map( 5, clbk, {} ); // $ExpectError
|
|
60
|
-
map( true, clbk, {} ); // $ExpectError
|
|
61
|
-
map( false, clbk, {} ); // $ExpectError
|
|
62
|
-
map( null, clbk, {} ); // $ExpectError
|
|
63
|
-
map( {}, clbk, {} ); // $ExpectError
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// The compiler throws an error if the function is provided a second argument other than a function with a supported signature...
|
|
67
|
-
{
|
|
68
|
-
const arr1 = [ 1, 2, 3, 4, 5, 6 ];
|
|
69
|
-
|
|
70
|
-
map( arr1, '5' ); // $ExpectError
|
|
71
|
-
map( arr1, true ); // $ExpectError
|
|
72
|
-
map( arr1, false ); // $ExpectError
|
|
73
|
-
map( arr1, 123 ); // $ExpectError
|
|
74
|
-
map( arr1, null ); // $ExpectError
|
|
75
|
-
map( arr1, {} ); // $ExpectError
|
|
76
|
-
map( arr1, [] ); // $ExpectError
|
|
77
|
-
|
|
78
|
-
map( arr1, '5', {} ); // $ExpectError
|
|
79
|
-
map( arr1, true, {} ); // $ExpectError
|
|
80
|
-
map( arr1, false, {} ); // $ExpectError
|
|
81
|
-
map( arr1, 123, {} ); // $ExpectError
|
|
82
|
-
map( arr1, null, {} ); // $ExpectError
|
|
83
|
-
map( arr1, {}, {} ); // $ExpectError
|
|
84
|
-
map( arr1, [], {} ); // $ExpectError
|
|
85
|
-
|
|
86
|
-
map( arr1, ( x: number, y: number, z: number ): number => x + y + z ); // $ExpectError
|
|
87
|
-
map( arr1, ( x: number, y: number, z: number ): number => x + y + z, {} ); // $ExpectError
|
|
88
|
-
|
|
89
|
-
const arr2 = array( [ 1, 2, 3, 4, 5, 6 ] );
|
|
90
|
-
|
|
91
|
-
map( arr2, '5' ); // $ExpectError
|
|
92
|
-
map( arr2, true ); // $ExpectError
|
|
93
|
-
map( arr2, false ); // $ExpectError
|
|
94
|
-
map( arr2, 123 ); // $ExpectError
|
|
95
|
-
map( arr2, null ); // $ExpectError
|
|
96
|
-
map( arr2, {} ); // $ExpectError
|
|
97
|
-
map( arr2, [] ); // $ExpectError
|
|
98
|
-
|
|
99
|
-
map( arr2, '5', {} ); // $ExpectError
|
|
100
|
-
map( arr2, true, {} ); // $ExpectError
|
|
101
|
-
map( arr2, false, {} ); // $ExpectError
|
|
102
|
-
map( arr2, 123, {} ); // $ExpectError
|
|
103
|
-
map( arr2, null, {} ); // $ExpectError
|
|
104
|
-
map( arr2, {}, {} ); // $ExpectError
|
|
105
|
-
map( arr2, [], {} ); // $ExpectError
|
|
106
|
-
|
|
107
|
-
map( arr2, ( x: number, y: number, z: number ): number => x + y + z ); // $ExpectError
|
|
108
|
-
map( arr2, ( x: number, y: number, z: number ): number => x + y + z, {} ); // $ExpectError
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// The compiler throws an error if the function is provided an unsupported number of arguments...
|
|
112
|
-
{
|
|
113
|
-
const arr1 = [ 1, 2, 3, 4, 5, 6 ];
|
|
114
|
-
|
|
115
|
-
map(); // $ExpectError
|
|
116
|
-
map( arr1 ); // $ExpectError
|
|
117
|
-
map( arr1, clbk, {}, 4 ); // $ExpectError
|
|
118
|
-
|
|
119
|
-
const arr2 = array( [ 1, 2, 3, 4, 5, 6 ] );
|
|
120
|
-
|
|
121
|
-
map(); // $ExpectError
|
|
122
|
-
map( arr2 ); // $ExpectError
|
|
123
|
-
map( arr2, clbk, {}, 4 ); // $ExpectError
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Attached to the main export is an `assign` method which returns a collection when provided a collection...
|
|
127
|
-
{
|
|
128
|
-
const arr = [ 1, 2, 3, 4, 5, 6 ];
|
|
129
|
-
const out = [ 0, 0, 0, 0, 0, 0 ];
|
|
130
|
-
|
|
131
|
-
map.assign( arr, out, clbk ); // $ExpectType Collection
|
|
132
|
-
map.assign( arr, out, clbk, {} ); // $ExpectType Collection
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// The `assign` method returns an ndarray when provided an ndarray...
|
|
136
|
-
{
|
|
137
|
-
const arr = array( [ 1, 2, 3, 4, 5, 6 ] );
|
|
138
|
-
const out = array( [ 0, 0, 0, 0, 0, 0 ] );
|
|
139
|
-
|
|
140
|
-
map.assign( arr, out, clbk ); // $ExpectType ndarray
|
|
141
|
-
map.assign( arr, out, clbk, {} ); // $ExpectType ndarray
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// The compiler throws an error if the `assign` method is provided a first argument other than a collection or ndarray...
|
|
145
|
-
{
|
|
146
|
-
const out1 = [ 0, 0, 0, 0, 0, 0 ];
|
|
147
|
-
|
|
148
|
-
map.assign( 5, out1, clbk ); // $ExpectError
|
|
149
|
-
map.assign( true, out1, clbk ); // $ExpectError
|
|
150
|
-
map.assign( false, out1, clbk ); // $ExpectError
|
|
151
|
-
map.assign( null, out1, clbk, {} ); // $ExpectError
|
|
152
|
-
map.assign( {}, out1, clbk ); // $ExpectError
|
|
153
|
-
|
|
154
|
-
map.assign( 5, out1, clbk, {} ); // $ExpectError
|
|
155
|
-
map.assign( true, out1, clbk, {} ); // $ExpectError
|
|
156
|
-
map.assign( false, out1, clbk, {} ); // $ExpectError
|
|
157
|
-
map.assign( null, out1, clbk, {} ); // $ExpectError
|
|
158
|
-
map.assign( {}, out1, clbk, {} ); // $ExpectError
|
|
159
|
-
|
|
160
|
-
const out2 = array( [ 0, 0, 0, 0, 0, 0 ] );
|
|
161
|
-
|
|
162
|
-
map.assign( 5, out2, clbk ); // $ExpectError
|
|
163
|
-
map.assign( true, out2, clbk ); // $ExpectError
|
|
164
|
-
map.assign( false, out2, clbk ); // $ExpectError
|
|
165
|
-
map.assign( null, out2, clbk, {} ); // $ExpectError
|
|
166
|
-
map.assign( {}, out2, clbk ); // $ExpectError
|
|
167
|
-
|
|
168
|
-
map.assign( 5, out2, clbk, {} ); // $ExpectError
|
|
169
|
-
map.assign( true, out2, clbk, {} ); // $ExpectError
|
|
170
|
-
map.assign( false, out2, clbk, {} ); // $ExpectError
|
|
171
|
-
map.assign( null, out2, clbk, {} ); // $ExpectError
|
|
172
|
-
map.assign( {}, out2, clbk, {} ); // $ExpectError
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// The compiler throws an error if the `assign` method is provided a second argument other than a collection or ndarray...
|
|
176
|
-
{
|
|
177
|
-
const arr1 = [ 0, 0, 0, 0, 0, 0 ];
|
|
178
|
-
|
|
179
|
-
map.assign( arr1, 5, clbk ); // $ExpectError
|
|
180
|
-
map.assign( arr1, true, clbk ); // $ExpectError
|
|
181
|
-
map.assign( arr1, false, clbk ); // $ExpectError
|
|
182
|
-
map.assign( arr1, null, clbk, {} ); // $ExpectError
|
|
183
|
-
map.assign( arr1, {}, clbk ); // $ExpectError
|
|
184
|
-
|
|
185
|
-
map.assign( arr1, 5, clbk, {} ); // $ExpectError
|
|
186
|
-
map.assign( arr1, true, clbk, {} ); // $ExpectError
|
|
187
|
-
map.assign( arr1, false, clbk, {} ); // $ExpectError
|
|
188
|
-
map.assign( arr1, null, clbk, {} ); // $ExpectError
|
|
189
|
-
map.assign( arr1, {}, clbk, {} ); // $ExpectError
|
|
190
|
-
|
|
191
|
-
const arr2 = array( [ 0, 0, 0, 0, 0, 0 ] );
|
|
192
|
-
|
|
193
|
-
map.assign( arr2, 5, clbk ); // $ExpectError
|
|
194
|
-
map.assign( arr2, true, clbk ); // $ExpectError
|
|
195
|
-
map.assign( arr2, false, clbk ); // $ExpectError
|
|
196
|
-
map.assign( arr2, null, clbk, {} ); // $ExpectError
|
|
197
|
-
map.assign( arr2, {}, clbk ); // $ExpectError
|
|
198
|
-
|
|
199
|
-
map.assign( arr2, 5, clbk, {} ); // $ExpectError
|
|
200
|
-
map.assign( arr2, true, clbk, {} ); // $ExpectError
|
|
201
|
-
map.assign( arr2, false, clbk, {} ); // $ExpectError
|
|
202
|
-
map.assign( arr2, null, clbk, {} ); // $ExpectError
|
|
203
|
-
map.assign( arr2, {}, clbk, {} ); // $ExpectError
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// The compiler throws an error if the `assign` method is provided a third argument other than a function with a supported signature...
|
|
207
|
-
{
|
|
208
|
-
const arr1 = [ 1, 2, 3, 4, 5, 6 ];
|
|
209
|
-
const out1 = [ 0, 0, 0, 0, 0, 0 ];
|
|
210
|
-
|
|
211
|
-
map.assign( arr1, out1, '5' ); // $ExpectError
|
|
212
|
-
map.assign( arr1, out1, true ); // $ExpectError
|
|
213
|
-
map.assign( arr1, out1, false ); // $ExpectError
|
|
214
|
-
map.assign( arr1, out1, 123 ); // $ExpectError
|
|
215
|
-
map.assign( arr1, out1, null ); // $ExpectError
|
|
216
|
-
map.assign( arr1, out1, {} ); // $ExpectError
|
|
217
|
-
map.assign( arr1, out1, [] ); // $ExpectError
|
|
218
|
-
|
|
219
|
-
map.assign( arr1, out1, '5', {} ); // $ExpectError
|
|
220
|
-
map.assign( arr1, out1, true, {} ); // $ExpectError
|
|
221
|
-
map.assign( arr1, out1, false, {} ); // $ExpectError
|
|
222
|
-
map.assign( arr1, out1, 123, {} ); // $ExpectError
|
|
223
|
-
map.assign( arr1, out1, null, {} ); // $ExpectError
|
|
224
|
-
map.assign( arr1, out1, {}, {} ); // $ExpectError
|
|
225
|
-
map.assign( arr1, out1, [], {} ); // $ExpectError
|
|
226
|
-
|
|
227
|
-
map.assign( arr1, out1, ( x: number, y: number, z: number ): number => x + y + z ); // $ExpectError
|
|
228
|
-
map.assign( arr1, out1, ( x: number, y: number, z: number ): number => x + y + z, {} ); // $ExpectError
|
|
229
|
-
|
|
230
|
-
const arr2 = array( [ 1, 2, 3, 4, 5, 6 ] );
|
|
231
|
-
const out2 = array( [ 0, 0, 0, 0, 0, 0 ] );
|
|
232
|
-
|
|
233
|
-
map.assign( arr2, out2, '5' ); // $ExpectError
|
|
234
|
-
map.assign( arr2, out2, true ); // $ExpectError
|
|
235
|
-
map.assign( arr2, out2, false ); // $ExpectError
|
|
236
|
-
map.assign( arr2, out2, 123 ); // $ExpectError
|
|
237
|
-
map.assign( arr2, out2, null ); // $ExpectError
|
|
238
|
-
map.assign( arr2, out2, {} ); // $ExpectError
|
|
239
|
-
map.assign( arr2, out2, [] ); // $ExpectError
|
|
240
|
-
|
|
241
|
-
map.assign( arr2, out2, '5', {} ); // $ExpectError
|
|
242
|
-
map.assign( arr2, out2, true, {} ); // $ExpectError
|
|
243
|
-
map.assign( arr2, out2, false, {} ); // $ExpectError
|
|
244
|
-
map.assign( arr2, out2, 123, {} ); // $ExpectError
|
|
245
|
-
map.assign( arr2, out2, null, {} ); // $ExpectError
|
|
246
|
-
map.assign( arr2, out2, {}, {} ); // $ExpectError
|
|
247
|
-
map.assign( arr2, out2, [], {} ); // $ExpectError
|
|
248
|
-
|
|
249
|
-
map.assign( arr2, out2, ( x: number, y: number, z: number ): number => x + y + z ); // $ExpectError
|
|
250
|
-
map.assign( arr2, out2, ( x: number, y: number, z: number ): number => x + y + z, {} ); // $ExpectError
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// The compiler throws an error if the `assign` method is provided an unsupported number of arguments...
|
|
254
|
-
{
|
|
255
|
-
const arr1 = [ 1, 2, 3, 4, 5, 6 ];
|
|
256
|
-
const out1 = [ 0, 0, 0, 0, 0, 0 ];
|
|
257
|
-
|
|
258
|
-
map.assign(); // $ExpectError
|
|
259
|
-
map.assign( arr1 ); // $ExpectError
|
|
260
|
-
map.assign( arr1, out1 ); // $ExpectError
|
|
261
|
-
map.assign( arr1, out1, clbk, {}, 4 ); // $ExpectError
|
|
262
|
-
|
|
263
|
-
const arr2 = array( [ 1, 2, 3, 4, 5, 6 ] );
|
|
264
|
-
const out2 = array( [ 0, 0, 0, 0, 0, 0 ] );
|
|
265
|
-
|
|
266
|
-
map.assign(); // $ExpectError
|
|
267
|
-
map.assign( arr2 ); // $ExpectError
|
|
268
|
-
map.assign( arr2, out2 ); // $ExpectError
|
|
269
|
-
map.assign( arr2, out2, clbk, {}, 4 ); // $ExpectError
|
|
270
|
-
}
|