Skip to content

Commit bf9a6e1

Browse files
committed
Add Typescript definition
1 parent 3facf3a commit bf9a6e1

3 files changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 global object.
23+
*
24+
* ## Notes
25+
*
26+
* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.
27+
*
28+
* @param codegen - boolean indicating whether to use code generation to resolve the global object
29+
* @returns global object
30+
*
31+
* @example
32+
* var g = getGlobal();
33+
* // returns {...}
34+
*/
35+
declare function getGlobal( codegen?: boolean ): any;
36+
37+
38+
// EXPORTS //
39+
40+
export = getGlobal;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 getGlobal = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an object...
25+
{
26+
getGlobal(); // $ExpectType any
27+
getGlobal( true ); // $ExpectType any
28+
getGlobal( false ); // $ExpectType any
29+
}
30+
31+
// The compiler throws an error if the function is provided a value other than a boolean...
32+
{
33+
getGlobal( 'abc' ); // $ExpectError
34+
getGlobal( 5 ); // $ExpectError
35+
getGlobal( [] ); // $ExpectError
36+
getGlobal( {} ); // $ExpectError
37+
getGlobal( ( x: number ): number => x ); // $ExpectError
38+
}
39+
40+
// The compiler throws an error if the function is provided more than one argument...
41+
{
42+
getGlobal( true, 2 ); // $ExpectError
43+
getGlobal( true, 2, 3 ); // $ExpectError
44+
}

lib/node_modules/@stdlib/utils/global/package.json

Lines changed: 1 addition & 0 deletions
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)