Skip to content

Commit 62c2c7a

Browse files
committed
Add TypeScript definition file
1 parent 309b94a commit 62c2c7a

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
// MAIN //
44+
45+
/**
46+
* Tests whether at least one iterated value is truthy.
47+
*
48+
* @param iterator - input iterator
49+
* @returns boolean indicating whether at least one iterated value is truthy
50+
*
51+
* @example
52+
*
53+
* var array2iterator = require( '@stdlib/array/to-iterator' );
54+
*
55+
* var it = array2iterator( [ 0, 0, 0, 0, 1 ] );
56+
*
57+
* var bool = iterAny( it );
58+
* // returns true
59+
*/
60+
declare function iterAny( iterator: Iterator ): boolean;
61+
62+
63+
// EXPORTS //
64+
65+
export = iterAny;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 iterAny = require( './index' );
20+
21+
22+
// FUNCTIONS //
23+
24+
/**
25+
* Returns an iterator protocol-compliant object.
26+
*
27+
* @returns iterator protocol-compliant object
28+
*/
29+
function iterator() {
30+
return {
31+
'next': next
32+
};
33+
34+
/**
35+
* Implements the iterator protocol `next` method.
36+
*
37+
* @returns iterator protocol-compliant object
38+
*/
39+
function next() {
40+
return {
41+
'value': true,
42+
'done': false
43+
};
44+
}
45+
}
46+
47+
48+
// TESTS //
49+
50+
iterAny( iterator() ); // $ExpectType boolean
51+
iterAny( null ); // $ExpectError
52+
iterAny( [] ); // $ExpectError
53+
iterAny( {} ); // $ExpectError
54+
iterAny(); // $ExpectError

lib/node_modules/@stdlib/iter/any/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"test": "./test"
2323
},
2424
"scripts": {},
25+
"types": "./docs/types",
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {
2728
"type": "git",

0 commit comments

Comments
 (0)