Skip to content

Commit 9e7e85b

Browse files
committed
Add type declarations and fix require hack
1 parent 0fffb06 commit 9e7e85b

File tree

3 files changed

+131
-1
lines changed

3 files changed

+131
-1
lines changed

lib/node_modules/@stdlib/iter/every/docs/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ interface IteratorResult {
4747
*
4848
* @example
4949
*
50-
* var array2iterator = require( '@stdlib/array/to-iterator' );
50+
* var array2iterator = require( `@stdlib/array/to-iterator` );
5151
*
5252
* var it = array2iterator( [ 1, 1, 1, 1, 0 ] );
5353
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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+
// TypeScript Version: 2.0
20+
21+
interface Iterator {
22+
/**
23+
* Returns an iterator protocol-compliant object containing the next iterated value (if one exists) and a boolean flag indicating whether the iterator is finished.
24+
*
25+
* @returns iterator protocol-compliant object
26+
*/
27+
next(): IteratorResult;
28+
}
29+
30+
interface IteratorResult {
31+
/**
32+
* Iterated value (if one exists).
33+
*/
34+
value?: any;
35+
36+
/**
37+
* Boolean flag indicating whether the iterator is finished.
38+
*/
39+
done: boolean;
40+
}
41+
42+
/**
43+
* Tests whether all iterated values are falsy.
44+
*
45+
* @param iterator - input iterator
46+
* @returns boolean indicating whether all iterated values are falsy
47+
*
48+
* @example
49+
*
50+
* var array2iterator = require( `@stdlib/array/to-iterator` );
51+
*
52+
* var it = array2iterator( [ 0, 0, 0, 0, 1 ] );
53+
*
54+
* var bool = iterNone( it );
55+
* // returns false
56+
*/
57+
declare function iterNone( iterator: Iterator ): boolean;
58+
59+
60+
// EXPORTS //
61+
62+
export = iterNone;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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 iterNone = require( './index' );
20+
21+
/**
22+
* Returns an iterator protocol-compliant object.
23+
*
24+
* @returns iterator protocol-compliant object
25+
*/
26+
function iterator() {
27+
return {
28+
'next': next
29+
};
30+
31+
/**
32+
* Implements the iterator protocol `next` method.
33+
*
34+
* @returns iterator protocol-compliant object
35+
*/
36+
function next() {
37+
return {
38+
'value': true,
39+
'done': false
40+
};
41+
}
42+
}
43+
44+
45+
// TESTS //
46+
47+
// The function returns a boolean...
48+
{
49+
iterNone( iterator() ); // $ExpectType boolean
50+
}
51+
52+
// The compiler throws an error if the function is provided a value other than an iterator protocol-compliant object...
53+
{
54+
iterNone( '5' ); // $ExpectError
55+
iterNone( 5 ); // $ExpectError
56+
iterNone( true ); // $ExpectError
57+
iterNone( false ); // $ExpectError
58+
iterNone( null ); // $ExpectError
59+
iterNone( undefined ); // $ExpectError
60+
iterNone( [] ); // $ExpectError
61+
iterNone( {} ); // $ExpectError
62+
iterNone( ( x ) => x ); // $ExpectError
63+
}
64+
65+
// The compiler throws an error if the function is provided insufficient arguments...
66+
{
67+
iterNone(); // $ExpectError
68+
}

0 commit comments

Comments
 (0)