Skip to content

Commit 425e175

Browse files
committed
Add Typescript definitions
1 parent 301f40e commit 425e175

File tree

6 files changed

+168
-0
lines changed

6 files changed

+168
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 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+
* Returns the next larger ndarray data type of the same kind.
23+
*
24+
* @param dtype - ndarray data type
25+
* @returns next larger data type(s) or null
26+
*
27+
* @example
28+
* var dt = nextDataType( 'float32' );
29+
* // returns 'float64'
30+
*/
31+
declare function nextDataType( dtype?: string ): any;
32+
33+
34+
// EXPORTS //
35+
36+
export = nextDataType;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 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 nextDataType = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an object, string, integer, or null...
25+
{
26+
nextDataType(); // $ExpectType any
27+
nextDataType( 'float32' ); // $ExpectType any
28+
nextDataType( 'float' ); // $ExpectType any
29+
}
30+
31+
// The function does not compile if provided a value other than a string...
32+
{
33+
nextDataType( 123 ); // $ExpectError
34+
nextDataType( true ); // $ExpectError
35+
nextDataType( false ); // $ExpectError
36+
nextDataType( null ); // $ExpectError
37+
nextDataType( {} ); // $ExpectError
38+
nextDataType( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The function does not compile if provided more than one argument...
42+
{
43+
nextDataType( 'float32', 123 ); // $ExpectError
44+
}

lib/node_modules/@stdlib/ndarray/next-dtype/package.json

+1
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": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 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+
* Returns a list of ndarray data types to which a provided ndarray data type can be safely cast.
23+
*
24+
* ## Notes
25+
*
26+
* - If not provided an ndarray data type, the function returns a casting table.
27+
*
28+
* - If provided an unrecognized ndarray data type, the function returns `null`.
29+
*
30+
* @param dtype - ndarray data type
31+
* @returns list of ndarray data types or null
32+
*
33+
* @example
34+
* var list = safeCasts( 'float32' );
35+
* // returns [...]
36+
*/
37+
declare function safeCasts( dtype?: string ): any;
38+
39+
40+
// EXPORTS //
41+
42+
export = safeCasts;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 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 safeCasts = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an object, array of strings, or null...
25+
{
26+
safeCasts(); // $ExpectType any
27+
safeCasts( 'float32' ); // $ExpectType any
28+
safeCasts( 'float' ); // $ExpectType any
29+
}
30+
31+
// The function does not compile if provided a value other than a string...
32+
{
33+
safeCasts( 123 ); // $ExpectError
34+
safeCasts( true ); // $ExpectError
35+
safeCasts( false ); // $ExpectError
36+
safeCasts( null ); // $ExpectError
37+
safeCasts( {} ); // $ExpectError
38+
safeCasts( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The function does not compile if provided more than one argument...
42+
{
43+
safeCasts( 'float32', 123 ); // $ExpectError
44+
}

lib/node_modules/@stdlib/ndarray/safe-casts/package.json

+1
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)