Skip to content

Commit fe60b0b

Browse files
committed
Add Typescript definitions
1 parent 5a2e827 commit fe60b0b

File tree

6 files changed

+343
-0
lines changed

6 files changed

+343
-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 `isStringArray` with methods for testing for primitive and object arrays, respectively.
23+
*/
24+
interface IsStringArray {
25+
/**
26+
* Tests if a value is an array of strings.
27+
*
28+
* @param value - value to test
29+
* @returns boolean indicating whether value is an array of strings
30+
*
31+
* @example
32+
* var bool = isStringArray( [ 'abc', 'def' ] );
33+
* // returns true
34+
*
35+
* @example
36+
* var bool = isStringArray( [ 'abc', 123 ] );
37+
* // returns false
38+
*/
39+
( value: any ): boolean;
40+
41+
/**
42+
* Tests if a value is an array containing only string primitives.
43+
*
44+
* @param value - value to test
45+
* @returns boolean indicating whether value is an array containing only string primitives
46+
*
47+
* @example
48+
* var bool = isStringArray.primitives( [ 'abc', 'def' ] );
49+
* // returns true
50+
*
51+
* @example
52+
* var bool = isStringArray.primitives( [ 'abc', new String( 'def' ) ] );
53+
* // returns false
54+
*/
55+
primitives( value: any ): boolean;
56+
57+
/**
58+
* Tests if a value is an array containing only `String` objects.
59+
*
60+
* @param value - value to test
61+
* @returns boolean indicating whether value is an array containing only `String` objects
62+
*
63+
* @example
64+
* var bool = isStringArray.objects( [ new String( 'abc' ), new String( 'def' ) ] );
65+
* // returns true
66+
*
67+
* @example
68+
* var bool = isStringArray.objects( [ new String( 'abc' ), 'def' ] );
69+
* // returns false
70+
*/
71+
objects( value: any ): boolean;
72+
}
73+
74+
/**
75+
* Tests if a value is an array of strings.
76+
*
77+
* @param value - value to test
78+
* @returns boolean indicating whether value is an array of strings
79+
*
80+
* @example
81+
* var bool = isStringArray( [ 'abc', 'def' ] );
82+
* // returns true
83+
*
84+
* @example
85+
* var bool = isStringArray( [ 'abc', 123 ] );
86+
* // returns false
87+
*
88+
* @example
89+
* var bool = isStringArray.primitives( [ 'abc', 'def' ] );
90+
* // returns true
91+
*
92+
* @example
93+
* var bool = isStringArray.objects( [ new String( 'abc' ), new String( 'def' ) ] );
94+
* // returns true
95+
*/
96+
declare var isStringArray: IsStringArray;
97+
98+
99+
// EXPORTS //
100+
101+
export = isStringArray;
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 isStringArray = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isStringArray( [ 'abc' ] ); // $ExpectType boolean
27+
isStringArray( [ 2 ] ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isStringArray(); // $ExpectError
33+
isStringArray( [ 'abc' ], 10.23 ); // $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+
isStringArray.primitives( [ new String( 'abc' ) ] ); // $ExpectType boolean
40+
isStringArray.primitives( [ 'abc' ] ); // $ExpectType boolean
41+
}
42+
43+
// The compiler throws an error if the `primitives` method is provided an unsupported number of arguments...
44+
{
45+
isStringArray.primitives(); // $ExpectError
46+
isStringArray.primitives( [ 'abc' ], 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+
isStringArray.objects( [ new String( 'abc' ) ] ); // $ExpectType boolean
54+
isStringArray.objects( [ 'abc' ] ); // $ExpectType boolean
55+
}
56+
57+
// The compiler throws an error if the `objects method is provided an unsupported number of arguments...
58+
{
59+
isStringArray.objects(); // $ExpectError
60+
isStringArray.objects( [ 'abc' ], 123 ); // $ExpectError
61+
}

lib/node_modules/@stdlib/assert/is-string-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": {
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 `isSymbolArray` with methods for testing for primitive and object arrays, respectively.
23+
*/
24+
interface IsSymbolArray {
25+
/**
26+
* Tests if a value is an array-like object containing only symbols.
27+
*
28+
* ## Notes
29+
*
30+
* - In pre-ES2015 environments, the function always returns `false`.
31+
*
32+
* @param value - value to test
33+
* @returns boolean indicating whether value is an array of strings
34+
*
35+
* @example
36+
* var bool = isSymbolArray( [ Symbol( 'abc' ), Symbol( 'def' ) ] );
37+
* // returns true
38+
*
39+
* @example
40+
* var bool = isSymbolArray( [ Symbol( 'abc' ), 'def' ] );
41+
* // returns false
42+
*/
43+
( value: any ): boolean;
44+
45+
/**
46+
* Tests if a value is an array-like object containing only `symbol` primitives.
47+
*
48+
* ## Notes
49+
*
50+
* - In pre-ES2015 environments, the function always returns `false`.
51+
*
52+
* @param value - value to test
53+
* @returns boolean indicating whether value is an array containing only string primitives
54+
*
55+
* @example
56+
* var bool = isSymbolArray.primitives( [ Symbol( 'abc' ), Symbol( 'def' ) ] );
57+
* // returns true
58+
*
59+
* @example
60+
* var bool = isSymbolArray.primitives( [ Symbol( 'abc' ), Object( Symbol( 'def' ) ) ] );
61+
* // returns false
62+
*/
63+
primitives( value: any ): boolean;
64+
65+
/**
66+
* Tests if a value is an array-like object containing only `Symbol` objects.
67+
*
68+
*
69+
* ## Notes
70+
*
71+
* - In pre-ES2015 environments, the function always returns `false`.
72+
*
73+
* @param value - value to test
74+
* @returns boolean indicating whether a value is an array-like object containing only `Symbol` objects
75+
*
76+
* @example
77+
* var bool = isSymbolArray.objects( [ Object( Symbol( 'abc' ) ), Object( Symbol( 'def' ) ) ] );
78+
* // returns true
79+
*
80+
* @example
81+
* var bool = isSymbolArray.objects( [ Symbol( 'abc' ), Symbol( 'def' ) ] );
82+
* // returns false
83+
*/
84+
objects( value: any ): boolean;
85+
}
86+
87+
/**
88+
* Tests if a value is an array-like object containing only symbols.
89+
*
90+
* ## Notes
91+
*
92+
* - In pre-ES2015 environments, the function always returns `false`.
93+
*
94+
* @param value - value to test
95+
* @returns boolean indicating whether value is an array of strings
96+
*
97+
* @example
98+
* var bool = isSymbolArray( [ Symbol( 'abc' ), Symbol( 'def' ) ] );
99+
* // returns true
100+
*
101+
* @example
102+
* var bool = isSymbolArray( [ Symbol( 'abc' ), 'def' ] );
103+
* // returns false
104+
*
105+
* @example
106+
* var bool = isSymbolArray.primitives( [ Symbol( 'abc' ), Symbol( 'def' ) ] );
107+
* // returns true
108+
*
109+
* @example
110+
* var bool = isSymbolArray.objects( [ Object( Symbol( 'abc' ) ), Object( Symbol( 'def' ) ) ] );
111+
* // returns true
112+
*/
113+
declare var isSymbolArray: IsSymbolArray;
114+
115+
116+
// EXPORTS //
117+
118+
export = isSymbolArray;
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 isSymbolArray = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isSymbolArray( [ Symbol( 'abc' ) ] ); // $ExpectType boolean
27+
isSymbolArray( [ 2 ] ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isSymbolArray(); // $ExpectError
33+
isSymbolArray( [ Symbol( 'abc' ) ], 10.23 ); // $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+
isSymbolArray.primitives( [ Object( Symbol( 'abc' ) ) ] ); // $ExpectType boolean
40+
isSymbolArray.primitives( [ Symbol( 'abc' ) ] ); // $ExpectType boolean
41+
}
42+
43+
// The compiler throws an error if the `primitives` method is provided an unsupported number of arguments...
44+
{
45+
isSymbolArray.primitives(); // $ExpectError
46+
isSymbolArray.primitives( [ Symbol( 'abc' ) ], 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+
isSymbolArray.objects( [ Object( Symbol( 'abc' ) ) ] ); // $ExpectType boolean
54+
isSymbolArray.objects( [ Symbol( 'abc' ) ] ); // $ExpectType boolean
55+
}
56+
57+
// The compiler throws an error if the `objects method is provided an unsupported number of arguments...
58+
{
59+
isSymbolArray.objects(); // $ExpectError
60+
isSymbolArray.objects( [ Symbol( 'abc' ) ], 123 ); // $ExpectError
61+
}

lib/node_modules/@stdlib/assert/is-symbol-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)