Skip to content

Commit 4a7956b

Browse files
committed
Add Typescript definitions
1 parent 39b4271 commit 4a7956b

File tree

6 files changed

+374
-0
lines changed

6 files changed

+374
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
* Interface defining `isAbsolutePath` with methods for testing POSIX and Windows paths, respectively.
23+
*/
24+
interface IsAbsolutePath {
25+
/**
26+
* Tests if a value is an absolute path.
27+
*
28+
* @param value - value to test
29+
* @returns boolean indicating whether value is an absolute path
30+
*
31+
* @example
32+
* var IS_WINDOWS = require( '@stdlib/assert/is-windows' );
33+
* var bool;
34+
* if ( IS_WINDOWS ) {
35+
* bool = isAbsolutePath( 'C:\\foo\\bar\\baz' );
36+
* // returns true
37+
* } else {
38+
* bool = isAbsolutePath( '/foo/bar/baz' );
39+
* // returns true
40+
* }
41+
*/
42+
( value: any ): boolean;
43+
44+
/**
45+
* Tests if a value is a POSIX absolute path.
46+
*
47+
* @param value - value to test
48+
* @returns boolean indicating whether value is a POSIX absolute path
49+
*
50+
* @example
51+
* var bool = isAbsolutePath.posix( '/foo/bar/baz' );
52+
* // returns true
53+
*
54+
* @example
55+
* var bool = isAbsolutePath.posix( 'foo/bar/baz' );
56+
* // returns false
57+
*/
58+
posix( value: any ): boolean;
59+
60+
/**
61+
* Tests if a value is a Windows absolute path.
62+
*
63+
* @param value - value to test
64+
* @returns boolean indicating whether value is a Windows absolute path
65+
*
66+
* @example
67+
* var bool = isAbsolutePath.win32( 'C:\\foo\\bar\\baz' );
68+
* // returns true
69+
*
70+
* @example
71+
* var bool = isAbsolutePath.win32( 'foo\\bar\\baz' );
72+
* // returns false
73+
*/
74+
win32( value: any ): boolean;
75+
}
76+
77+
/**
78+
* Tests if a value is an absolute path.
79+
*
80+
* ## Notes
81+
*
82+
* - Function behavior is platform-specific. On Windows platforms, the function is equal to `.win32()`. On POSIX platforms, the function is equal to `.posix()`.
83+
*
84+
* @param value - value to test
85+
* @returns boolean indicating whether value is an absolute path
86+
*
87+
* @example
88+
* var IS_WINDOWS = require( '@stdlib/assert/is-windows' );
89+
* var bool;
90+
* if ( IS_WINDOWS ) {
91+
* bool = isAbsolutePath( 'C:\\foo\\bar\\baz' );
92+
* // returns true
93+
* } else {
94+
* bool = isAbsolutePath( '/foo/bar/baz' );
95+
* // returns true
96+
* }
97+
*
98+
* @example
99+
* var bool = isAbsolutePath.posix( '/foo/bar/baz' );
100+
* // returns true
101+
*
102+
* @example
103+
* var bool = isAbsolutePath.posix( 'foo/bar/baz' );
104+
* // returns false
105+
*
106+
* @example
107+
* var bool = isAbsolutePath.win32( 'C:\\foo\\bar\\baz' );
108+
* // returns true
109+
*
110+
* @example
111+
* var bool = isAbsolutePath.win32( 'foo\\bar\\baz' );
112+
* // returns false
113+
*/
114+
declare var isAbsolutePath: IsAbsolutePath;
115+
116+
117+
// EXPORTS //
118+
119+
export = isAbsolutePath;
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 isAbsolutePath = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isAbsolutePath( 'C:\\foo\\bar\\baz' ); // $ExpectType boolean
27+
isAbsolutePath( '/foo/bar/baz' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isAbsolutePath(); // $ExpectError
33+
isAbsolutePath( 'C:\\foo\\bar\\baz', 123 ); // $ExpectError
34+
}
35+
36+
// Attached to main export is an posix method which returns a boolean...
37+
{
38+
// tslint:disable-next-line:no-construct
39+
isAbsolutePath.posix( '/foo/bar/baz' ); // $ExpectType boolean
40+
isAbsolutePath.posix( '/foo/../bar/baz' ); // $ExpectType boolean
41+
}
42+
43+
// The compiler throws an error if the posix method is provided an unsupported number of arguments...
44+
{
45+
isAbsolutePath.posix(); // $ExpectError
46+
isAbsolutePath.posix( '/foo/../bar/baz', 123 ); // $ExpectError
47+
}
48+
49+
50+
// Attached to main export is an win32 method which returns a boolean...
51+
{
52+
// tslint:disable-next-line:no-construct
53+
isAbsolutePath.win32( 'foo\\bar\\baz' ); // $ExpectType boolean
54+
isAbsolutePath.win32( 'C:\\foo\\..\\bar\\baz' ); // $ExpectType boolean
55+
}
56+
57+
// The compiler throws an error if the win32 method is provided an unsupported number of arguments...
58+
{
59+
isAbsolutePath.win32(); // $ExpectError
60+
isAbsolutePath.win32( 'C:\\foo\\..\\bar\\baz', 123 ); // $ExpectError
61+
}

lib/node_modules/@stdlib/assert/is-absolute-path/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"lib": "./lib",
2626
"test": "./test"
2727
},
28+
"types": "./docs/types",
2829
"scripts": {},
2930
"homepage": "https://github.com/stdlib-js/stdlib",
3031
"repository": {
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
* Interface defining `isRelativePath` with methods for testing POSIX and Windows paths, respectively.
23+
*/
24+
interface IsRelativePath {
25+
/**
26+
* Tests if a value is a relative path.
27+
*
28+
* @param value - value to test
29+
* @returns boolean indicating whether value is a relative path
30+
*
31+
* @example
32+
* var IS_WINDOWS = require( '@stdlib/assert/is-windows' );
33+
* var bool;
34+
* if ( IS_WINDOWS ) {
35+
* bool = isRelativePath( 'foo\\bar\\baz' );
36+
* // returns true
37+
*
38+
* bool = isRelativePath( 'C:\\foo\\..\\bar\\baz' );
39+
* // returns false
40+
* } else {
41+
* bool = isRelativePath( './foo/bar/baz' );
42+
* // returns true
43+
*
44+
* bool = isRelativePath( '/foo/../bar/baz' );
45+
* // returns false
46+
* }
47+
*/
48+
( value: any ): boolean;
49+
50+
/**
51+
* Tests if a value is a POSIX relative path.
52+
*
53+
* @param value - value to test
54+
* @returns boolean indicating whether value is a POSIX relative path
55+
*
56+
* @example
57+
* var bool = isRelativePath.posix( './foo/bar/baz' );
58+
* // returns true
59+
*
60+
* @example
61+
* var bool = isRelativePath.posix( '/foo/../bar/baz' );
62+
* // returns false
63+
*/
64+
posix( value: any ): boolean;
65+
66+
/**
67+
* Tests if a value is a Windows relative path.
68+
*
69+
* @param value - value to test
70+
* @returns boolean indicating whether value is a Windows relative path
71+
*
72+
* @example
73+
* var bool = isRelativePath.win32( 'foo\\bar\\baz' );
74+
* // returns true
75+
*
76+
* @example
77+
* var bool = isRelativePath.win32( 'C:\\foo\\..\\bar\\baz' );
78+
* // returns false
79+
*/
80+
win32( value: any ): boolean;
81+
}
82+
83+
/**
84+
* Tests if a value is a relative path.
85+
*
86+
* ## Notes
87+
*
88+
* - Function behavior is platform-specific. On Windows platforms, the function is equal to `.win32()`. On POSIX platforms, the function is equal to `.posix()`.
89+
*
90+
* @param value - value to test
91+
* @returns boolean indicating whether value is a relative path
92+
*
93+
* @example
94+
* var IS_WINDOWS = require( '@stdlib/assert/is-windows' );
95+
* var bool;
96+
* if ( IS_WINDOWS ) {
97+
* bool = isRelativePath( 'foo\\bar\\baz' );
98+
* // returns true
99+
*
100+
* bool = isRelativePath( 'C:\\foo\\..\\bar\\baz' );
101+
* // returns false
102+
* } else {
103+
* bool = isRelativePath( './foo/bar/baz' );
104+
* // returns true
105+
*
106+
* bool = isRelativePath( '/foo/../bar/baz' );
107+
* // returns false
108+
* }
109+
*
110+
* @example
111+
* var bool = isRelativePath.posix( './foo/bar/baz' );
112+
* // returns true
113+
*
114+
* @example
115+
* var bool = isRelativePath.posix( '/foo/../bar/baz' );
116+
* // returns false
117+
*
118+
* @example
119+
* var bool = isRelativePath.win32( 'foo\\bar\\baz' );
120+
* // returns true
121+
*
122+
* @example
123+
* var bool = isRelativePath.win32( 'C:\\foo\\..\\bar\\baz' );
124+
* // returns false
125+
*/
126+
declare var isRelativePath: IsRelativePath;
127+
128+
129+
// EXPORTS //
130+
131+
export = isRelativePath;
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 isRelativePath = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isRelativePath( 'foo\\bar\\baz' ); // $ExpectType boolean
27+
isRelativePath( './foo/bar/baz' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isRelativePath(); // $ExpectError
33+
isRelativePath( 'foo\\bar\\baz', 123 ); // $ExpectError
34+
}
35+
36+
// Attached to main export is an posix method which returns a boolean...
37+
{
38+
// tslint:disable-next-line:no-construct
39+
isRelativePath.posix( './foo/bar/baz' ); // $ExpectType boolean
40+
isRelativePath.posix( '/foo/../bar/baz' ); // $ExpectType boolean
41+
}
42+
43+
// The compiler throws an error if the posix method is provided an unsupported number of arguments...
44+
{
45+
isRelativePath.posix(); // $ExpectError
46+
isRelativePath.posix( '/foo/../bar/baz', 123 ); // $ExpectError
47+
}
48+
49+
50+
// Attached to main export is an win32 method which returns a boolean...
51+
{
52+
// tslint:disable-next-line:no-construct
53+
isRelativePath.win32( 'foo\\bar\\baz' ); // $ExpectType boolean
54+
isRelativePath.win32( 'C:\\foo\\..\\bar\\baz' ); // $ExpectType boolean
55+
}
56+
57+
// The compiler throws an error if the win32 method is provided an unsupported number of arguments...
58+
{
59+
isRelativePath.win32(); // $ExpectError
60+
isRelativePath.win32( 'C:\\foo\\..\\bar\\baz', 123 ); // $ExpectError
61+
}

lib/node_modules/@stdlib/assert/is-relative-path/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"lib": "./lib",
2323
"test": "./test"
2424
},
25+
"types": "./docs/types",
2526
"scripts": {},
2627
"homepage": "https://github.com/stdlib-js/stdlib",
2728
"repository": {

0 commit comments

Comments
 (0)