Skip to content

Commit 74d2d8a

Browse files
committed
Add Typescript definitions
1 parent d86b8ff commit 74d2d8a

File tree

12 files changed

+564
-0
lines changed

12 files changed

+564
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
/// <reference types="@stdlib/types"/>
22+
23+
/**
24+
* If provided a value, returns an updated corrected sample standard deviation; otherwise, returns the current corrected sample standard deviation.
25+
*
26+
* ## Notes
27+
*
28+
* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations.
29+
*
30+
* @param x - value
31+
* @returns corrected sample standard deviation
32+
*/
33+
type accumulator = ( x?: number ) => number | null;
34+
35+
/**
36+
* Returns an accumulator function which incrementally computes a moving corrected sample standard deviation.
37+
*
38+
* ## Notes
39+
*
40+
* - The `W` parameter defines the number of values over which to compute the moving sum.
41+
* - As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values.
42+
*
43+
* @param W - window size
44+
* @param mean - mean value
45+
* @throws first argument must be a positive integer
46+
* @returns accumulator function
47+
*
48+
* @example
49+
* var accumulator = incrmstdev( 3 );
50+
*
51+
* var s = accumulator();
52+
* // returns null
53+
*
54+
* s = accumulator( 2.0 );
55+
* // returns 0.0
56+
*
57+
* s = accumulator( -5.0 );
58+
* // returns ~4.95
59+
*
60+
* s = accumulator( 3.0 );
61+
* // returns ~4.36
62+
*
63+
* s = accumulator( 5.0 );
64+
* // returns ~5.29
65+
*
66+
* s = accumulator();
67+
* // returns ~5.29
68+
*
69+
* @example
70+
* var accumulator = incrmstdev( 3, 5.0 );
71+
*/
72+
declare function incrmstdev( W: number, mean?: number ): accumulator;
73+
74+
75+
// EXPORTS //
76+
77+
export = incrmstdev;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 incrmstdev = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an accumulator function...
25+
{
26+
incrmstdev( 3 ); // $ExpectType accumulator
27+
incrmstdev( 3, 0.0 ); // $ExpectType accumulator
28+
}
29+
30+
// The compiler throws an error if the function is provided an argument which is not a number...
31+
{
32+
incrmstdev( '5' ); // $ExpectError
33+
incrmstdev( true ); // $ExpectError
34+
incrmstdev( false ); // $ExpectError
35+
incrmstdev( null ); // $ExpectError
36+
incrmstdev( [] ); // $ExpectError
37+
incrmstdev( {} ); // $ExpectError
38+
incrmstdev( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The compiler throws an error if the function is provided an invalid number of arguments...
42+
{
43+
incrmstdev(); // $ExpectError
44+
incrmstdev( 3, 2.5, 3 ); // $ExpectError
45+
}
46+
47+
// The function returns an accumulator function which returns an accumulated result...
48+
{
49+
const acc = incrmstdev( 3 );
50+
51+
acc(); // $ExpectType number | null
52+
acc( 3.14 ); // $ExpectType number | null
53+
}
54+
55+
// The compiler throws an error if the returned accumulator function is provided invalid arguments...
56+
{
57+
const acc = incrmstdev( 3 );
58+
59+
acc( '5' ); // $ExpectError
60+
acc( true ); // $ExpectError
61+
acc( false ); // $ExpectError
62+
acc( null ); // $ExpectError
63+
acc( [] ); // $ExpectError
64+
acc( {} ); // $ExpectError
65+
acc( ( x: number ): number => x ); // $ExpectError
66+
}

lib/node_modules/@stdlib/stats/incr/mstdev/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lib": "./lib",
2121
"test": "./test"
2222
},
23+
"types": "./docs/types",
2324
"scripts": {},
2425
"homepage": "https://github.com/stdlib-js/stdlib",
2526
"repository": {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
/// <reference types="@stdlib/types"/>
22+
23+
/**
24+
* If provided a value, returns an updated sum; otherwise, returns the current sum.
25+
*
26+
* ## Notes
27+
*
28+
* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations.
29+
*
30+
* @param x - value
31+
* @returns sum
32+
*/
33+
type accumulator = ( x?: number ) => number | null;
34+
35+
/**
36+
* Returns an accumulator function which incrementally computes a moving sum.
37+
*
38+
* ## Notes
39+
*
40+
* - The `W` parameter defines the number of values over which to compute the moving sum.
41+
* - As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values.
42+
*
43+
* @param W - window size
44+
* @throws must provide a positive integer
45+
* @returns accumulator function
46+
*
47+
* @example
48+
* var accumulator = incrmsum( 3 );
49+
*
50+
* var sum = accumulator();
51+
* // returns null
52+
*
53+
* sum = accumulator( 2.0 );
54+
* // returns 2.0
55+
*
56+
* sum = accumulator( -5.0 );
57+
* // returns -3.0
58+
*
59+
* sum = accumulator( 3.0 );
60+
* // returns 0.0
61+
*
62+
* sum = accumulator( 5.0 );
63+
* // returns 3.0
64+
*
65+
* sum = accumulator();
66+
* // returns 3.0
67+
*/
68+
declare function incrmsum( W: number ): accumulator;
69+
70+
71+
// EXPORTS //
72+
73+
export = incrmsum;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 incrmsum = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an accumulator function...
25+
{
26+
incrmsum( 3 ); // $ExpectType accumulator
27+
}
28+
29+
// The compiler throws an error if the function is provided an argument which is not a number...
30+
{
31+
incrmsum( '5' ); // $ExpectError
32+
incrmsum( true ); // $ExpectError
33+
incrmsum( false ); // $ExpectError
34+
incrmsum( null ); // $ExpectError
35+
incrmsum( undefined ); // $ExpectError
36+
incrmsum( [] ); // $ExpectError
37+
incrmsum( {} ); // $ExpectError
38+
incrmsum( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The compiler throws an error if the function is provided an invalid number of arguments...
42+
{
43+
incrmsum(); // $ExpectError
44+
incrmsum( 3, 2 ); // $ExpectError
45+
}
46+
47+
// The function returns an accumulator function which returns an accumulated result...
48+
{
49+
const acc = incrmsum( 3 );
50+
51+
acc(); // $ExpectType number | null
52+
acc( 3.14 ); // $ExpectType number | null
53+
}
54+
55+
// The compiler throws an error if the returned accumulator function is provided invalid arguments...
56+
{
57+
const acc = incrmsum( 3 );
58+
59+
acc( '5' ); // $ExpectError
60+
acc( true ); // $ExpectError
61+
acc( false ); // $ExpectError
62+
acc( null ); // $ExpectError
63+
acc( [] ); // $ExpectError
64+
acc( {} ); // $ExpectError
65+
acc( ( x: number ): number => x ); // $ExpectError
66+
}

lib/node_modules/@stdlib/stats/incr/msum/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lib": "./lib",
2121
"test": "./test"
2222
},
23+
"types": "./docs/types",
2324
"scripts": {},
2425
"homepage": "https://github.com/stdlib-js/stdlib",
2526
"repository": {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
/// <reference types="@stdlib/types"/>
22+
23+
/**
24+
* If provided a value, returns an updated sum of absolute values; otherwise, returns the current sum of absolute values.
25+
*
26+
* ## Notes
27+
*
28+
* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations.
29+
*
30+
* @param x - value
31+
* @returns sum of absolute values
32+
*/
33+
type accumulator = ( x?: number ) => number | null;
34+
35+
/**
36+
* Returns an accumulator function which incrementally computes a moving sum of absolute values.
37+
*
38+
* ## Notes
39+
*
40+
* - The `W` parameter defines the number of values over which to compute the moving sum.
41+
* - As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values.
42+
*
43+
* @param W - window size
44+
* @throws must provide a positive integer
45+
* @returns accumulator function
46+
*
47+
* @example
48+
* var accumulator = incrmsumabs( 3 );
49+
*
50+
* var sum = accumulator();
51+
* // returns null
52+
*
53+
* sum = accumulator( 2.0 );
54+
* // returns 2.0
55+
*
56+
* sum = accumulator( -5.0 );
57+
* // returns 7.0
58+
*
59+
* sum = accumulator( 3.0 );
60+
* // returns 10.0
61+
*
62+
* sum = accumulator( 5.0 );
63+
* // returns 13.0
64+
*
65+
* sum = accumulator();
66+
* // returns 13.0
67+
*/
68+
declare function incrmsumabs( W: number ): accumulator;
69+
70+
71+
// EXPORTS //
72+
73+
export = incrmsumabs;

0 commit comments

Comments
 (0)