Skip to content

Commit c9e5b7d

Browse files
committed
Add Typescript definition
1 parent fdd797d commit c9e5b7d

File tree

3 files changed

+163
-0
lines changed

3 files changed

+163
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
/**
22+
* Interface defining `isBooleanArray` with methods for testing for primitives and objects, respectively.
23+
*/
24+
interface IsBooleanArray {
25+
/**
26+
* Tests if a value is an array-like object of booleans.
27+
*
28+
* @param value - value to test
29+
* @returns boolean indicating whether value is an array-like object of booleans
30+
*
31+
* @example
32+
* var bool = isBooleanArray( [ true, false, true ] );
33+
* // returns true
34+
*
35+
* @example
36+
* var bool = isBooleanArray( [ true, 'abc', false ] );
37+
* // returns false
38+
*/
39+
( value: any ): boolean;
40+
41+
/**
42+
* Tests if a value is an array-like object containing only boolean primitives.
43+
*
44+
* @param value - value to test
45+
* @returns boolean indicating whether value is an array-like object containing only boolean primitives
46+
*
47+
* @example
48+
* var bool = isBooleanArray.primitives( [ true, false ] );
49+
* // returns true
50+
*
51+
* @example
52+
* var bool = isBooleanArray.primitives( [ false, new Boolean( true ) ] );
53+
* // returns false
54+
*/
55+
primitives( value: any ): boolean;
56+
57+
/**
58+
* Tests if a value is an array-like object containing only Boolean objects.
59+
*
60+
* @param value - value to test
61+
* @returns boolean indicating whether value is an array-like object containing only Boolean objects
62+
*
63+
* @example
64+
* var bool = isBooleanArray.objects( [ new Boolean( false ), new Boolean( true ) ] );
65+
* // returns true
66+
*
67+
* @example
68+
* var bool = isBooleanArray.objects( [ new Boolean( false ), true ] );
69+
* // returns false
70+
*/
71+
objects( value: any ): boolean;
72+
}
73+
74+
/**
75+
* Tests if a value is an array-like object of booleans.
76+
*
77+
* @param value - value to test
78+
* @returns boolean indicating whether value is an array-like object of booleans
79+
*
80+
* @example
81+
* var bool = isBooleanArray( [ true, false, true ] );
82+
* // returns true
83+
*
84+
* @example
85+
* var bool = isBooleanArray( [ true, 'abc', false ] );
86+
* // returns false
87+
*
88+
* @example
89+
* var bool = isBooleanArray.primitives( [ true, false ] );
90+
* // returns true
91+
*
92+
* @example
93+
* var bool = isBooleanArray.objects( [ new Boolean( false ), new Boolean( true ) ] );
94+
* // returns true
95+
*/
96+
declare var isBooleanArray: IsBooleanArray;
97+
98+
99+
// EXPORTS //
100+
101+
export = isBooleanArray;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 isBooleanArray = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isBooleanArray( [ 'beep' ] ); // $ExpectType boolean
27+
isBooleanArray( [ true, false, true ] ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isBooleanArray(); // $ExpectError
33+
isBooleanArray( [ true, false ], 123 ); // $ExpectError
34+
}
35+
36+
// Attached to main export is a `primitives` method which returns a boolean...
37+
{
38+
// tslint:disable-next-line:no-construct
39+
isBooleanArray.primitives( [ new Boolean( true ) ] ); // $ExpectType boolean
40+
isBooleanArray.primitives( [ true ] ); // $ExpectType boolean
41+
}
42+
43+
// The compiler throws an error if the `primitives` method is provided an unsupported number of arguments...
44+
{
45+
isBooleanArray.primitives(); // $ExpectError
46+
isBooleanArray.primitives( [ true ], 123 ); // $ExpectError
47+
}
48+
49+
50+
// Attached to main export is an `objects` method which returns a boolean...
51+
{
52+
// tslint:disable-next-line:no-construct
53+
isBooleanArray.objects( [ new Boolean( true ) ] ); // $ExpectType boolean
54+
isBooleanArray.objects( [ true ] ); // $ExpectType boolean
55+
}
56+
57+
// The compiler throws an error if the `objects` method is provided an unsupported number of arguments...
58+
{
59+
isBooleanArray.objects(); // $ExpectError
60+
isBooleanArray.objects( [ true ], 123 ); // $ExpectError
61+
}

lib/node_modules/@stdlib/assert/is-boolean-array/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {

0 commit comments

Comments
 (0)