Skip to content

Commit f8a007b

Browse files
committed
Add Typescript definitions
1 parent fcbe5a9 commit f8a007b

9 files changed

Lines changed: 313 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
* Returns the number of hours in a month.
23+
*
24+
* ## Notes
25+
*
26+
* - By default, the function returns the number of hours in the current month of the current year (according to local time). To determine the number of hours for a particular month and year, provide `month` and `year` arguments.
27+
* - A `month` may be either a month's integer value, three letter abbreviation, or full name (case insensitive).
28+
* - The function's return value is a generalization and does **not** take into account inaccuracies due to daylight savings conventions, crossing timezones, or other complications with time and dates.
29+
*
30+
* @param [month] - month
31+
* @param [year] - year
32+
* @throws must provide a recognized month
33+
* @throws an integer month argument must be on the interval `[1,12]`
34+
* @returns hours in a month
35+
*
36+
* @example
37+
* var num = hoursInMonth();
38+
* // returns <number>
39+
*
40+
* @example
41+
* var num = hoursInMonth( 2 );
42+
* // returns <number>
43+
*
44+
* @example
45+
* var num = hoursInMonth( 2, 2016 );
46+
* // returns 696
47+
*
48+
* @example
49+
* var num = hoursInMonth( 2, 2017 );
50+
* // returns 672
51+
*/
52+
declare function hoursInMonth( month?: string | number | Date, year?: number ): number; // tslint-disable-line max-line-length
53+
54+
55+
// EXPORTS //
56+
57+
export = hoursInMonth;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 hoursInMonth = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
hoursInMonth( 1, 1990 ); // $ExpectType number
27+
hoursInMonth( 'Jan', 1990 ); // $ExpectType number
28+
hoursInMonth(); // $ExpectType number
29+
hoursInMonth( new Date() ) ; // $ExpectType number
30+
}
31+
32+
// The function does not compile if provided arguments of invalid types...
33+
{
34+
hoursInMonth( [], 2016 ); // $ExpectError
35+
hoursInMonth( {}, 2016 ); // $ExpectError
36+
hoursInMonth( false, 2016 ); // $ExpectError
37+
hoursInMonth( true, 2016 ); // $ExpectError
38+
hoursInMonth( ( x: number ): number => x, 2016 ); // $ExpectError
39+
40+
hoursInMonth( 2, true ); // $ExpectError
41+
hoursInMonth( 2, false ); // $ExpectError
42+
hoursInMonth( 2, ( x: number ): number => x ); // $ExpectError
43+
hoursInMonth( 2, [] ); // $ExpectError
44+
hoursInMonth( 2, {} ); // $ExpectError
45+
hoursInMonth( 2, 'beep' ); // $ExpectError
46+
}
47+
48+
// The function does not compile if provided more than two arguments...
49+
{
50+
hoursInMonth( 1, 15, 1990 ); // $ExpectError
51+
}

lib/node_modules/@stdlib/time/hours-in-month/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"lib": "./lib",
2525
"test": "./test"
2626
},
27+
"types": "./docs/types",
2728
"scripts": {},
2829
"homepage": "https://github.com/stdlib-js/stdlib",
2930
"repository": {
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+
* Returns the number of hours in a year according to the Gregorian calendar.
23+
*
24+
* ## Notes
25+
*
26+
* - By default, the function returns the number of hours in the current year (according to local time). To determine the number of hours for a particular year, provide either a year or a `Date` object.
27+
* - The function's return value is a generalization and does **not** take into account inaccuracies due to daylight savings conventions, crossing timezones, or other complications with time and dates.
28+
*
29+
* @param value - year or `Date` object
30+
* @returns number of hours in a year
31+
*
32+
* @example
33+
* var num = hoursInYear();
34+
* // returns <number>
35+
*
36+
* @example
37+
* var num = hoursInYear( 2016 );
38+
* // returns 8784
39+
*
40+
* @example
41+
* var num = hoursInYear( 2017 );
42+
* // returns 8760
43+
*/
44+
declare function hoursInYear( value?: number | Date ): number;
45+
46+
47+
// EXPORTS //
48+
49+
export = hoursInYear;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 hoursInYear = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
hoursInYear( new Date() ) ; // $ExpectType number
27+
hoursInYear( 1990 ); // $ExpectType number
28+
hoursInYear(); // $ExpectType number
29+
}
30+
31+
// The function does not compile if provided an argument of invalid type...
32+
{
33+
hoursInYear( [] ); // $ExpectError
34+
hoursInYear( {} ); // $ExpectError
35+
hoursInYear( false ); // $ExpectError
36+
hoursInYear( true ); // $ExpectError
37+
hoursInYear( ( x: number ): number => x ); // $ExpectError
38+
hoursInYear( 'beep' ); // $ExpectError
39+
}
40+
41+
// The function does not compile if provided more than one argument...
42+
{
43+
hoursInYear( 1990, 9 ); // $ExpectError
44+
hoursInYear( 1990, 1, 19 ); // $ExpectError
45+
}

lib/node_modules/@stdlib/time/hours-in-year/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"lib": "./lib",
2525
"test": "./test"
2626
},
27+
"types": "./docs/types",
2728
"scripts": {},
2829
"homepage": "https://github.com/stdlib-js/stdlib",
2930
"repository": {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
* Returns the number of seconds in a month.
23+
*
24+
* ## Notes
25+
*
26+
* - By default, the function returns the number of seconds in the current month of the current year (according to local time). To determine the number of seconds for a particular month and year, provide `month` and `year` arguments.
27+
* - A `month` may be either a month's integer value, three letter abbreviation, or full name (case insensitive).
28+
* - The function's return value is a generalization and does **not** take into account inaccuracies due to daylight savings conventions, crossing timezones, or other complications with time and dates.
29+
*
30+
* @param [month] - month
31+
* @param [year] - year
32+
* @throws must provide a recognized month
33+
* @throws an integer month argument must be on the interval `[1,12]`
34+
* @returns seconds in a month
35+
*
36+
* @example
37+
* var num = secondsInMonth();
38+
* // returns <number>
39+
*
40+
* @example
41+
* var num = secondsInMonth( 2 );
42+
* // returns <number>
43+
*
44+
* @example
45+
* var num = secondsInMonth( 2, 2016 );
46+
* // returns 2505600
47+
*
48+
* @example
49+
* var num = secondsInMonth( 2, 2017 );
50+
* // returns 2419200
51+
*/
52+
declare function secondsInMonth( month?: string | number | Date, year?: number ): number; // tslint-disable-line max-line-length
53+
54+
55+
// EXPORTS //
56+
57+
export = secondsInMonth;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 secondsInMonth = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
secondsInMonth( 1, 1990 ); // $ExpectType number
27+
secondsInMonth( 'Jan', 1990 ); // $ExpectType number
28+
secondsInMonth(); // $ExpectType number
29+
secondsInMonth( new Date() ) ; // $ExpectType number
30+
}
31+
32+
// The function does not compile if provided arguments of invalid types...
33+
{
34+
secondsInMonth( [], 2016 ); // $ExpectError
35+
secondsInMonth( {}, 2016 ); // $ExpectError
36+
secondsInMonth( false, 2016 ); // $ExpectError
37+
secondsInMonth( true, 2016 ); // $ExpectError
38+
secondsInMonth( ( x: number ): number => x, 2016 ); // $ExpectError
39+
40+
secondsInMonth( 2, true ); // $ExpectError
41+
secondsInMonth( 2, false ); // $ExpectError
42+
secondsInMonth( 2, ( x: number ): number => x ); // $ExpectError
43+
secondsInMonth( 2, [] ); // $ExpectError
44+
secondsInMonth( 2, {} ); // $ExpectError
45+
secondsInMonth( 2, 'beep' ); // $ExpectError
46+
}
47+
48+
// The function does not compile if provided more than two arguments...
49+
{
50+
secondsInMonth( 1, 15, 1990 ); // $ExpectError
51+
}

lib/node_modules/@stdlib/time/seconds-in-month/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"lib": "./lib",
2525
"test": "./test"
2626
},
27+
"types": "./docs/types",
2728
"scripts": {},
2829
"homepage": "https://github.com/stdlib-js/stdlib",
2930
"repository": {

0 commit comments

Comments
 (0)