Skip to content

Commit 89c1baa

Browse files
committed
Add namespace Typescript definition
1 parent a8434ac commit 89c1baa

3 files changed

Lines changed: 238 additions & 0 deletions

File tree

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
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+
import ARCH = require( '@stdlib/os/arch' );
22+
import BYTE_ORDER = require( '@stdlib/os/byte-order' );
23+
import configdir = require( '@stdlib/os/configdir' );
24+
import FLOAT_WORD_ORDER = require( '@stdlib/os/float-word-order' );
25+
import homedir = require( '@stdlib/os/homedir' );
26+
import NUM_CPUS = require( '@stdlib/os/num-cpus' );
27+
import PLATFORM = require( '@stdlib/os/platform' );
28+
import tmpdir = require( '@stdlib/os/tmpdir' );
29+
30+
/**
31+
* Interface describing the `os` namespace.
32+
*/
33+
interface OS {
34+
/**
35+
* Operating system CPU architecture.
36+
*
37+
* ## Notes
38+
*
39+
* Current possible values:
40+
*
41+
* - arm
42+
* - arm64
43+
* - ia32
44+
* - mips
45+
* - mipsel
46+
* - ppc
47+
* - ppc64
48+
* - s390
49+
* - s390x
50+
* - x32
51+
* - x64
52+
*
53+
* @example
54+
* if ( ARCH === 'arm' || ARCH === 'arm64' ) {
55+
* console.log( 'Running on ARM...' );
56+
* } else {
57+
* console.log( 'Running on something else...' );
58+
* }
59+
*/
60+
ARCH: typeof ARCH;
61+
62+
/**
63+
* Platform byte order.
64+
*
65+
* ## Notes
66+
*
67+
* Possible values:
68+
*
69+
* - `'little-endian'`
70+
* - `'big-endian'`
71+
* - `'mixed-endian'`
72+
* - `'unknown'`
73+
*
74+
* @example
75+
* if ( BYTE_ORDER === 'little-endian' ) {
76+
* console.log( 'Least significant byte comes first...' );
77+
* } else if ( BYTE_ORDER === 'big-endian' ) {
78+
* console.log( 'Most significant byte comes first...' );
79+
* } else {
80+
* console.log( 'This is uncommon...' );
81+
* }
82+
*/
83+
BYTE_ORDER: typeof BYTE_ORDER;
84+
85+
/**
86+
* Returns a directory for user-specific configuration files.
87+
*
88+
* ## Notes
89+
*
90+
* - On Windows platforms, the function first checks for a `LOCALAPPDATA` environment variable before checking for an `APPDATA` environment variable. This means that machine specific user configuration files have precedence over roaming user configuration files.
91+
* - On non-Windows platforms, if the function is unable to locate the current user's `home` directory, the function returns `null`. Similarly, on Windows platforms, if the function is unable to locate an application data directory, the function also returns `null`.
92+
*
93+
* @param [p] - path to append to a base directory
94+
* @returns directory
95+
*
96+
* @example
97+
* var dir = configdir();
98+
* // e.g., returns '/Users/<username>/Library/Preferences'
99+
*
100+
* @example
101+
* var dir = configdir( 'appname/config' );
102+
* // e.g., returns '/Users/<username>/Library/Preferences/appname/config'
103+
*/
104+
configdir: typeof configdir;
105+
106+
/**
107+
* Platform float word order.
108+
*
109+
* ## Notes
110+
*
111+
* Possible values:
112+
*
113+
* - `'little-endian'`
114+
* - `'big-endian'`
115+
* - `'unknown'`
116+
*
117+
* @example
118+
* if ( FLOAT_WORD_ORDER === 'little-endian' ) {
119+
* console.log( 'Least significant word comes first...' );
120+
* } else if ( FLOAT_WORD_ORDER === 'big-endian' ) {
121+
* console.log( 'Most significant word comes first...' );
122+
* } else {
123+
* console.log( 'Unknown...' );
124+
* }
125+
*/
126+
FLOAT_WORD_ORDER: typeof FLOAT_WORD_ORDER;
127+
128+
/**
129+
* Returns the current user's home directory.
130+
*
131+
* ## Notes
132+
*
133+
* - If unable to locate a home directory, the function returns `null`.
134+
*
135+
* @returns home directory
136+
*
137+
* @example
138+
* var home = homedir();
139+
* // e.g., returns '/Users/<username>'
140+
*/
141+
homedir: typeof homedir;
142+
143+
/**
144+
* Number of CPUs.
145+
*
146+
* ## Notes
147+
*
148+
* - In browser environments, the number of CPUs is determined by querying the hardware concurrency API.
149+
* - In Node.js environments, the number of CPUs is determined via the `os` module.
150+
*
151+
* @example
152+
* var num = NUM_CPUS;
153+
* // returns <number>
154+
*/
155+
NUM_CPUS: typeof NUM_CPUS;
156+
157+
/**
158+
* Platform on which the current process is running.
159+
*
160+
* ## Notes
161+
*
162+
* Possible values:
163+
*
164+
* - `'win32'`
165+
* - `'darwin'`
166+
* - `'linux'`
167+
* - `'freebsd'`
168+
* - `'sunos'`
169+
*
170+
* @example
171+
* if ( PLATFORM === 'win32' ) {
172+
* console.log( 'Running on a PC...' );
173+
* } else if ( PLATFORM === 'darwin' ) {
174+
* console.log( 'Running on a Mac...' );
175+
* } else {
176+
* console.log( 'Running on something else...' );
177+
* }
178+
*/
179+
PLATFORM: typeof PLATFORM;
180+
181+
/**
182+
* Returns the directory for storing temporary files.
183+
*
184+
* @returns directory for temporary files
185+
*
186+
* @example
187+
* var dir = tmpdir();
188+
* // e.g., returns '/path/to/temporary/files/directory'
189+
*/
190+
tmpdir: typeof tmpdir;
191+
}
192+
193+
/**
194+
* Standard library OS utilities.
195+
*/
196+
declare var os: OS;
197+
198+
199+
// EXPORTS //
200+
201+
export = os;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
/* tslint:disable:no-unused-expression */
20+
21+
import os = require( './index' );
22+
23+
24+
// TESTS //
25+
26+
// The exported object has the expected function interfaces...
27+
{
28+
os.ARCH; // $ExpectType string
29+
os.BYTE_ORDER; // $ExpectType string
30+
os.configdir; // $ExpectType (p?: string | undefined) => string
31+
os.FLOAT_WORD_ORDER; // $ExpectType string
32+
os.homedir; // $ExpectType () => string | null
33+
os.NUM_CPUS; // $ExpectType number
34+
os.PLATFORM; // $ExpectType string
35+
os.tmpdir; // $ExpectType () => string
36+
}

lib/node_modules/@stdlib/os/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": {

0 commit comments

Comments
 (0)