Skip to content

Commit ebc001c

Browse files
committed
Add Typescript definitions
1 parent 03e011d commit ebc001c

File tree

6 files changed

+177
-0
lines changed

6 files changed

+177
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
* Tests if an object has a specified method name, either own or inherited.
23+
*
24+
* ## Notes
25+
*
26+
* - Value arguments other than `null` or `undefined` are coerced to objects.
27+
* - Non-symbol property arguments are coerced to strings.
28+
*
29+
* @param value - value to test
30+
* @param property - property to test
31+
* @returns boolean indicating if an object has a specified method name
32+
*
33+
* @example
34+
* var beep = {
35+
* 'boop': true
36+
* };
37+
*
38+
* var bool = isMethodIn( beep, 'toString' );
39+
* // returns true
40+
*
41+
* bool = isMethodIn( beep, 'boop' );
42+
* // returns false
43+
*/
44+
declare function isMethodIn( value: any, property: any ): boolean;
45+
46+
47+
// EXPORTS //
48+
49+
export = isMethodIn;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 isMethodIn = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
const beep = {
27+
'boop': true
28+
};
29+
isMethodIn( beep, 'boop' ); // $ExpectType boolean
30+
isMethodIn( beep, 'toString' ); // $ExpectType boolean
31+
}
32+
33+
// The compiler throws an error if the function is provided an unsupported number of arguments...
34+
{
35+
isMethodIn(); // $ExpectError
36+
isMethodIn( {} ); // $ExpectError
37+
isMethodIn( {}, 'beep', 123 ); // $ExpectError
38+
}

lib/node_modules/@stdlib/assert/is-method-in/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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
* Tests if an object has a specified method name.
23+
*
24+
* ## Notes
25+
*
26+
* - Value arguments other than `null` or `undefined` are coerced to objects.
27+
* - Property arguments are coerced to strings.
28+
* - The function only searches own properties.
29+
*
30+
* @param value - value to test
31+
* @param property - property to test
32+
* @returns boolean indicating if an object has a specified method name
33+
*
34+
* @example
35+
* var beep = {
36+
* 'boop': isMethod
37+
* };
38+
*
39+
* var bool = isMethod( beep, 'boop' );
40+
* // returns true
41+
*
42+
* var bool = isMethod( beep, 'toString' );
43+
* // returns false
44+
*/
45+
declare function isMethod( value: any, property: any ): boolean;
46+
47+
48+
// EXPORTS //
49+
50+
export = isMethod;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 isMethod = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
const beep = {
27+
'boop': isMethod
28+
};
29+
isMethod( beep, 'boop' ); // $ExpectType boolean
30+
isMethod( beep, 'toString' ); // $ExpectType boolean
31+
}
32+
33+
// The compiler throws an error if the function is provided an unsupported number of arguments...
34+
{
35+
isMethod(); // $ExpectError
36+
isMethod( {} ); // $ExpectError
37+
isMethod( {}, 'beep', 123 ); // $ExpectError
38+
}

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