Skip to content

Commit ba7ca74

Browse files
committed
Add Typescript definitions
1 parent 47582c5 commit ba7ca74

File tree

9 files changed

+380
-0
lines changed

9 files changed

+380
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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, the accumulator function returns an updated accumulated value. If not provided a value, the accumulator function returns the current accumulated value.
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 accumulated value or null
32+
*/
33+
type accumulator = ( x?: number ) => number | null;
34+
35+
/**
36+
* Returns an accumulator function which incrementally computes the coefficient of variation (CV).
37+
*
38+
* @param mean - mean value
39+
* @returns accumulator function
40+
*
41+
* @example
42+
* var accumulator = incrcv();
43+
*
44+
* var cv = accumulator();
45+
* // returns null
46+
*
47+
* cv = accumulator( 2.0 );
48+
* // returns 0.0
49+
*
50+
* cv = accumulator( 1.0 );
51+
* // returns ~0.47
52+
*
53+
* cv = accumulator();
54+
* // returns ~0.47
55+
*
56+
* @example
57+
* var accumulator = incrcv( 3.14 );
58+
*/
59+
declare function incrcv( mean?: number ): accumulator;
60+
61+
62+
// EXPORTS //
63+
64+
export = incrcv;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 incrcv = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an accumulator function...
25+
{
26+
incrcv(); // $ExpectType accumulator
27+
incrcv( 0.0 ); // $ExpectType accumulator
28+
}
29+
30+
// The compiler throws an error if the function is provided invalid arguments...
31+
{
32+
incrcv( '5' ); // $ExpectError
33+
incrcv( true ); // $ExpectError
34+
incrcv( false ); // $ExpectError
35+
incrcv( null ); // $ExpectError
36+
incrcv( [] ); // $ExpectError
37+
incrcv( {} ); // $ExpectError
38+
incrcv( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The function returns an accumulator function which returns an accumulated result...
42+
{
43+
const acc = incrcv();
44+
45+
acc(); // $ExpectType number | null
46+
acc( 3.14 ); // $ExpectType number | null
47+
}
48+
49+
// The compiler throws an error if the returned accumulator function is provided invalid arguments...
50+
{
51+
const acc = incrcv();
52+
53+
acc( '5' ); // $ExpectError
54+
acc( true ); // $ExpectError
55+
acc( false ); // $ExpectError
56+
acc( null ); // $ExpectError
57+
acc( [] ); // $ExpectError
58+
acc( {} ); // $ExpectError
59+
acc( ( x: number ): number => x ); // $ExpectError
60+
}

lib/node_modules/@stdlib/stats/incr/cv/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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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, the accumulator function returns an updated corrected sample skewness. If not provided a value, the accumulator function returns the current corrected sample skewness.
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 skewness or null
32+
*/
33+
type accumulator = ( x?: number ) => number | null;
34+
35+
/**
36+
* Returns an accumulator function which incrementally computes a corrected sample skewness.
37+
*
38+
* ## Notes
39+
*
40+
* - If provided a value, the accumulator function returns an updated corrected sample skewness. If not provided a value, the accumulator function returns the current corrected sample skewness.
41+
* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations.
42+
*
43+
* @returns accumulator function
44+
*
45+
* @example
46+
* var accumulator = incrskewness();
47+
*
48+
* var skewness = accumulator();
49+
* // returns null
50+
*
51+
* skewness = accumulator( 2.0 );
52+
* // returns null
53+
*
54+
* skewness = accumulator( -5.0 );
55+
* // returns null
56+
*
57+
* skewness = accumulator( -10.0 );
58+
* // returns ~0.492
59+
*
60+
* skewness = accumulator();
61+
* // returns ~0.492
62+
*/
63+
declare function incrskewness(): accumulator;
64+
65+
66+
// EXPORTS //
67+
68+
export = incrskewness;
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 incrskewness = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an accumulator function...
25+
{
26+
incrskewness(); // $ExpectType accumulator
27+
}
28+
29+
// The compiler throws an error if the function is provided invalid arguments...
30+
{
31+
incrskewness( '5' ); // $ExpectError
32+
incrskewness( true ); // $ExpectError
33+
incrskewness( false ); // $ExpectError
34+
incrskewness( null ); // $ExpectError
35+
incrskewness( [] ); // $ExpectError
36+
incrskewness( {} ); // $ExpectError
37+
incrskewness( ( x: number ): number => x ); // $ExpectError
38+
}
39+
40+
// The function returns an accumulator function which returns an accumulated result...
41+
{
42+
const acc = incrskewness();
43+
44+
acc(); // $ExpectType number | null
45+
acc( 2 ); // $ExpectType number | null
46+
acc( -5 ); // $ExpectType number | null
47+
acc( 10 ); // $ExpectType number | null
48+
}
49+
50+
// The compiler throws an error if the returned accumulator function is provided invalid arguments...
51+
{
52+
const acc = incrskewness();
53+
54+
acc( '5' ); // $ExpectError
55+
acc( true ); // $ExpectError
56+
acc( false ); // $ExpectError
57+
acc( null ); // $ExpectError
58+
acc( [] ); // $ExpectError
59+
acc( {} ); // $ExpectError
60+
acc( ( x: number ): number => x ); // $ExpectError
61+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"lib": "./lib",
2020
"test": "./test"
2121
},
22+
"types": "./docs/types",
2223
"scripts": {},
2324
"homepage": "https://github.com/stdlib-js/stdlib",
2425
"repository": {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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, the accumulator function returns an updated accumulated value. If not provided a value, the accumulator function returns the current accumulated value.
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 accumulated value or null
32+
*/
33+
type accumulator = ( x?: number ) => number | null;
34+
35+
/**
36+
* Returns an accumulator function which incrementally computes a variance-to-mean ratio (VMR).
37+
*
38+
* @param mean - mean value
39+
* @returns accumulator function
40+
*
41+
* @example
42+
* var accumulator = incrvmr();
43+
*
44+
* var D = accumulator();
45+
* // returns null
46+
*
47+
* D = accumulator( 2.0 );
48+
* // returns 0.0
49+
*
50+
* D = accumulator( 1.0 );
51+
* // returns ~0.33
52+
*
53+
* D = accumulator();
54+
* // returns ~0.33
55+
*
56+
* @example
57+
* var accumulator = incrvmr( 3.14 );
58+
*/
59+
declare function incrvmr( mean?: number ): accumulator;
60+
61+
62+
// EXPORTS //
63+
64+
export = incrvmr;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 incrvmr = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an accumulator function...
25+
{
26+
incrvmr(); // $ExpectType accumulator
27+
incrvmr( 0.0 ); // $ExpectType accumulator
28+
}
29+
30+
// The compiler throws an error if the function is provided invalid arguments...
31+
{
32+
incrvmr( '5' ); // $ExpectError
33+
incrvmr( true ); // $ExpectError
34+
incrvmr( false ); // $ExpectError
35+
incrvmr( null ); // $ExpectError
36+
incrvmr( [] ); // $ExpectError
37+
incrvmr( {} ); // $ExpectError
38+
incrvmr( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The function returns an accumulator function which returns an accumulated result...
42+
{
43+
const acc = incrvmr();
44+
45+
acc(); // $ExpectType number | null
46+
acc( 3.14 ); // $ExpectType number | null
47+
}
48+
49+
// The compiler throws an error if the returned accumulator function is provided invalid arguments...
50+
{
51+
const acc = incrvmr();
52+
53+
acc( '5' ); // $ExpectError
54+
acc( true ); // $ExpectError
55+
acc( false ); // $ExpectError
56+
acc( null ); // $ExpectError
57+
acc( [] ); // $ExpectError
58+
acc( {} ); // $ExpectError
59+
acc( ( x: number ): number => x ); // $ExpectError
60+
}

0 commit comments

Comments
 (0)