Skip to content

Commit 42a7d27

Browse files
committed
Add Typescript definitions
1 parent 84516fd commit 42a7d27

File tree

6 files changed

+199
-0
lines changed

6 files changed

+199
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
/// <reference types="@stdlib/types"/>
22+
23+
import { ArrayLike } from '@stdlib/types/array';
24+
25+
/**
26+
* Returns array iteration order.
27+
*
28+
* ## Notes
29+
*
30+
* - Return value key:
31+
*
32+
* - `0`: unordered (i.e., strides of mixed sign; e.g., `[ 9, -3, 1 ]`)
33+
* - `1`: ordered left-to-right (i.e., all nonnegative strides)
34+
* - `-1`: ordered right-to-left (i.e., all negative strides)
35+
*
36+
* @param strides - stride array
37+
* @returns iteration order
38+
*
39+
* @example
40+
* var o = iterationOrder( [ 2, 1 ] );
41+
* // returns 1
42+
*
43+
* o = iterationOrder( [ -2, 1 ] );
44+
* // returns 0
45+
*
46+
* o = iterationOrder( [ -2, -1 ] );
47+
* // returns -1
48+
*/
49+
declare function iterationOrder( strides: ArrayLike<number> ): number;
50+
51+
52+
// EXPORTS //
53+
54+
export = iterationOrder;
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 iterationOrder = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
iterationOrder( [ 2, 1 ] ); // $ExpectType number
27+
}
28+
29+
// The function does not compile if provided a value other than an array-like object containing numbers...
30+
{
31+
iterationOrder( true ); // $ExpectError
32+
iterationOrder( false ); // $ExpectError
33+
iterationOrder( null ); // $ExpectError
34+
iterationOrder( undefined ); // $ExpectError
35+
iterationOrder( '5' ); // $ExpectError
36+
iterationOrder( [ '1', '2' ] ); // $ExpectError
37+
iterationOrder( {} ); // $ExpectError
38+
iterationOrder( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The function does not compile if provided insufficient arguments...
42+
{
43+
iterationOrder(); // $ExpectError
44+
}

lib/node_modules/@stdlib/ndarray/base/iteration-order/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,43 @@
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+
* Wraps an index on the interval `[0,max]`.
23+
*
24+
* @param idx - index
25+
* @param max - maximum index
26+
* @returns index
27+
*
28+
* @example
29+
* var idx = wrapIndex( -1, 10 );
30+
* // returns 10
31+
*
32+
* idx = wrapIndex( 13, 10 );
33+
* // returns 2
34+
*
35+
* idx = wrapIndex( 6, 10 );
36+
* // returns 6
37+
*/
38+
declare function wrapIndex( idx: number, max: number ): number;
39+
40+
41+
// EXPORTS //
42+
43+
export = wrapIndex;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 wrapIndex = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
wrapIndex( 15, 10 ); // $ExpectType number
27+
}
28+
29+
// The function does not compile if provided values other than two numbers...
30+
{
31+
wrapIndex( true, 3 ); // $ExpectError
32+
wrapIndex( false, 2 ); // $ExpectError
33+
wrapIndex( '5', 1 ); // $ExpectError
34+
wrapIndex( [], 1 ); // $ExpectError
35+
wrapIndex( {}, 2 ); // $ExpectError
36+
wrapIndex( ( x: number ): number => x, 2 ); // $ExpectError
37+
38+
wrapIndex( 9, true ); // $ExpectError
39+
wrapIndex( 9, false ); // $ExpectError
40+
wrapIndex( 5, '5' ); // $ExpectError
41+
wrapIndex( 8, [] ); // $ExpectError
42+
wrapIndex( 9, {} ); // $ExpectError
43+
wrapIndex( 8, ( x: number ): number => x ); // $ExpectError
44+
45+
wrapIndex( [], true ); // $ExpectError
46+
wrapIndex( {}, false ); // $ExpectError
47+
wrapIndex( false, '5' ); // $ExpectError
48+
wrapIndex( {}, [] ); // $ExpectError
49+
wrapIndex( '5', ( x: number ): number => x ); // $ExpectError
50+
}
51+
52+
// The function does not compile if provided insufficient arguments...
53+
{
54+
wrapIndex(); // $ExpectError
55+
wrapIndex( 3 ); // $ExpectError
56+
}

lib/node_modules/@stdlib/ndarray/base/wrap-index/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)