@ohos-ports/stdlib-fs 0.0.0-stage → 0.4.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +230 -2
- package/SECURITY.md +5 -0
- package/append-file/README.md +239 -0
- package/append-file/bin/cli +110 -0
- package/append-file/docs/repl.txt +72 -0
- package/append-file/docs/types/index.d.ts +133 -0
- package/append-file/docs/types/test.ts +193 -0
- package/append-file/docs/usage.txt +10 -0
- package/append-file/etc/cli_opts.json +22 -0
- package/append-file/lib/async.js +58 -0
- package/append-file/lib/index.js +61 -0
- package/append-file/lib/sync.js +58 -0
- package/append-file/package.json +69 -0
- package/close/README.md +172 -0
- package/close/docs/repl.txt +45 -0
- package/close/docs/types/index.d.ts +135 -0
- package/close/docs/types/test.ts +89 -0
- package/close/lib/index.js +73 -0
- package/close/lib/main.js +68 -0
- package/close/lib/sync.js +65 -0
- package/close/package.json +64 -0
- package/docs/types/index.d.ts +502 -0
- package/exists/README.md +252 -0
- package/exists/bin/cli +83 -0
- package/exists/docs/repl.txt +42 -0
- package/exists/docs/types/index.d.ts +112 -0
- package/exists/docs/types/test.ts +87 -0
- package/exists/docs/usage.txt +8 -0
- package/exists/etc/cli_opts.json +14 -0
- package/exists/lib/async.js +85 -0
- package/exists/lib/index.js +66 -0
- package/exists/lib/sync.js +62 -0
- package/exists/package.json +69 -0
- package/lib/index.js +186 -0
- package/open/README.md +204 -0
- package/open/docs/repl.txt +65 -0
- package/open/docs/types/index.d.ts +150 -0
- package/open/docs/types/test.ts +129 -0
- package/open/lib/defaults.json +4 -0
- package/open/lib/index.js +63 -0
- package/open/lib/main.js +64 -0
- package/open/lib/sync.js +68 -0
- package/open/package.json +64 -0
- package/package.json +67 -4
- package/read-dir/README.md +232 -0
- package/read-dir/bin/cli +83 -0
- package/read-dir/docs/repl.txt +44 -0
- package/read-dir/docs/types/index.d.ts +99 -0
- package/read-dir/docs/types/test.ts +85 -0
- package/read-dir/docs/usage.txt +8 -0
- package/read-dir/etc/cli_opts.json +14 -0
- package/read-dir/lib/async.js +57 -0
- package/read-dir/lib/index.js +62 -0
- package/read-dir/lib/sync.js +52 -0
- package/read-dir/package.json +69 -0
- package/read-file/README.md +246 -0
- package/read-file/bin/cli +91 -0
- package/read-file/docs/repl.txt +68 -0
- package/read-file/docs/types/index.d.ts +138 -0
- package/read-file/docs/types/test.ts +147 -0
- package/read-file/docs/usage.txt +10 -0
- package/read-file/etc/cli_opts.json +21 -0
- package/read-file/lib/index.js +61 -0
- package/read-file/lib/main.js +59 -0
- package/read-file/lib/sync.js +61 -0
- package/read-file/package.json +68 -0
- package/read-file-list/README.md +197 -0
- package/read-file-list/bin/cli +100 -0
- package/read-file-list/docs/repl.txt +81 -0
- package/read-file-list/docs/types/index.d.ts +166 -0
- package/read-file-list/docs/types/test.ts +166 -0
- package/read-file-list/docs/usage.txt +10 -0
- package/read-file-list/etc/cli_opts.json +21 -0
- package/read-file-list/lib/async.js +202 -0
- package/read-file-list/lib/clear_pending.js +47 -0
- package/read-file-list/lib/clear_timeout.js +23 -0
- package/read-file-list/lib/config.json +4 -0
- package/read-file-list/lib/delay.js +47 -0
- package/read-file-list/lib/index.js +66 -0
- package/read-file-list/lib/sync.js +94 -0
- package/read-file-list/package.json +72 -0
- package/read-json/README.md +176 -0
- package/read-json/docs/repl.txt +72 -0
- package/read-json/docs/types/index.d.ts +170 -0
- package/read-json/docs/types/test.ts +175 -0
- package/read-json/lib/async.js +114 -0
- package/read-json/lib/index.js +65 -0
- package/read-json/lib/sync.js +89 -0
- package/read-json/package.json +66 -0
- package/read-ndjson/README.md +166 -0
- package/read-ndjson/docs/repl.txt +72 -0
- package/read-ndjson/docs/types/index.d.ts +170 -0
- package/read-ndjson/docs/types/test.ts +179 -0
- package/read-ndjson/lib/async.js +114 -0
- package/read-ndjson/lib/index.js +65 -0
- package/read-ndjson/lib/sync.js +89 -0
- package/read-ndjson/package.json +68 -0
- package/read-wasm/README.md +158 -0
- package/read-wasm/docs/repl.txt +58 -0
- package/read-wasm/docs/types/index.d.ts +153 -0
- package/read-wasm/docs/types/test.ts +127 -0
- package/read-wasm/lib/async.js +106 -0
- package/read-wasm/lib/index.js +67 -0
- package/read-wasm/lib/sync.js +86 -0
- package/read-wasm/package.json +67 -0
- package/rename/README.md +259 -0
- package/rename/bin/cli +89 -0
- package/rename/docs/repl.txt +80 -0
- package/rename/docs/types/index.d.ts +109 -0
- package/rename/docs/types/test.ts +111 -0
- package/rename/docs/usage.txt +7 -0
- package/rename/etc/cli_opts.json +15 -0
- package/rename/lib/index.js +60 -0
- package/rename/lib/main.js +51 -0
- package/rename/lib/sync.js +53 -0
- package/rename/package.json +73 -0
- package/resolve-parent-path/README.md +204 -0
- package/resolve-parent-path/bin/cli +85 -0
- package/resolve-parent-path/docs/repl.txt +58 -0
- package/resolve-parent-path/docs/types/index.d.ts +128 -0
- package/resolve-parent-path/docs/types/test.ts +117 -0
- package/resolve-parent-path/docs/usage.txt +9 -0
- package/resolve-parent-path/etc/cli_opts.json +17 -0
- package/resolve-parent-path/lib/async.js +116 -0
- package/resolve-parent-path/lib/index.js +58 -0
- package/resolve-parent-path/lib/sync.js +83 -0
- package/resolve-parent-path/lib/validate.js +67 -0
- package/resolve-parent-path/package.json +78 -0
- package/resolve-parent-path-by/README.md +220 -0
- package/resolve-parent-path-by/docs/repl.txt +105 -0
- package/resolve-parent-path-by/docs/types/index.d.ts +220 -0
- package/resolve-parent-path-by/docs/types/test.ts +225 -0
- package/resolve-parent-path-by/lib/async.js +156 -0
- package/resolve-parent-path-by/lib/index.js +67 -0
- package/resolve-parent-path-by/lib/sync.js +98 -0
- package/resolve-parent-path-by/lib/validate.js +67 -0
- package/resolve-parent-path-by/package.json +76 -0
- package/resolve-parent-paths/README.md +228 -0
- package/resolve-parent-paths/bin/cli +93 -0
- package/resolve-parent-paths/docs/repl.txt +84 -0
- package/resolve-parent-paths/docs/types/index.d.ts +145 -0
- package/resolve-parent-paths/docs/types/test.ts +196 -0
- package/resolve-parent-paths/docs/usage.txt +10 -0
- package/resolve-parent-paths/etc/cli_opts.json +18 -0
- package/resolve-parent-paths/lib/index.js +60 -0
- package/resolve-parent-paths/lib/main.js +415 -0
- package/resolve-parent-paths/lib/sync.js +231 -0
- package/resolve-parent-paths/lib/validate.js +81 -0
- package/resolve-parent-paths/package.json +78 -0
- package/unlink/README.md +233 -0
- package/unlink/bin/cli +81 -0
- package/unlink/docs/repl.txt +62 -0
- package/unlink/docs/types/index.d.ts +105 -0
- package/unlink/docs/types/test.ts +85 -0
- package/unlink/docs/usage.txt +7 -0
- package/unlink/etc/cli_opts.json +15 -0
- package/unlink/lib/index.js +60 -0
- package/unlink/lib/main.js +50 -0
- package/unlink/lib/sync.js +52 -0
- package/unlink/package.json +70 -0
- package/write-file/README.md +250 -0
- package/write-file/bin/cli +110 -0
- package/write-file/docs/repl.txt +74 -0
- package/write-file/docs/types/index.d.ts +133 -0
- package/write-file/docs/types/test.ts +193 -0
- package/write-file/docs/usage.txt +10 -0
- package/write-file/etc/cli_opts.json +22 -0
- package/write-file/lib/index.js +60 -0
- package/write-file/lib/main.js +58 -0
- package/write-file/lib/sync.js +58 -0
- package/write-file/package.json +68 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Rename a file.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/fs/rename
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var rename = require( '@stdlib/fs/rename' );
|
|
28
|
+
*
|
|
29
|
+
* function done( error ) {
|
|
30
|
+
* if ( error ) {
|
|
31
|
+
* throw error;
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* rename( './beep/boop.txt', './beep/foo.txt', done );
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var renameSync = require( '@stdlib/fs/rename' ).sync;
|
|
39
|
+
*
|
|
40
|
+
* var err = renameSync( './beep/boop.txt', './beep/foo.txt' );
|
|
41
|
+
* if ( err instanceof Error ) {
|
|
42
|
+
* throw err;
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
// MODULES //
|
|
47
|
+
|
|
48
|
+
var setReadOnly = require( '@ohos-ports/stdlib-utils/define-nonenumerable-read-only-property' );
|
|
49
|
+
var main = require( './main.js' );
|
|
50
|
+
var sync = require( './sync.js' );
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// MAIN //
|
|
54
|
+
|
|
55
|
+
setReadOnly( main, 'sync', sync );
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// EXPORTS //
|
|
59
|
+
|
|
60
|
+
module.exports = main;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var native = require( 'fs' ).rename;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Asynchronously renames a file.
|
|
30
|
+
*
|
|
31
|
+
* @param {(string|Buffer)} oldPath - old path
|
|
32
|
+
* @param {(string|Buffer)} newPath - new path
|
|
33
|
+
* @param {Function} clbk - callback to invoke after renaming a path
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* function done( error ) {
|
|
37
|
+
* if ( error ) {
|
|
38
|
+
* throw error;
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* rename( './beep/boop.txt', './beep/foo.txt', done );
|
|
43
|
+
*/
|
|
44
|
+
function rename( oldPath, newPath, clbk ) {
|
|
45
|
+
native( oldPath, newPath, clbk );
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// EXPORTS //
|
|
50
|
+
|
|
51
|
+
module.exports = rename;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var rename = require( 'fs' ).renameSync;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Synchronously renames a file.
|
|
30
|
+
*
|
|
31
|
+
* @param {(string|Buffer)} oldPath - old path
|
|
32
|
+
* @param {(string|Buffer)} newPath - new path
|
|
33
|
+
* @returns {(Error|null)} error object or null
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var err = renameSync( './beep/boop.txt', './beep/foo.txt' );
|
|
37
|
+
* if ( err instanceof Error ) {
|
|
38
|
+
* throw err;
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
function renameSync( oldPath, newPath ) {
|
|
42
|
+
try {
|
|
43
|
+
rename( oldPath, newPath );
|
|
44
|
+
} catch ( err ) {
|
|
45
|
+
return err;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
// EXPORTS //
|
|
52
|
+
|
|
53
|
+
module.exports = renameSync;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/fs/rename",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Rename a file.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"bin": {
|
|
17
|
+
"rename": "./bin/cli"
|
|
18
|
+
},
|
|
19
|
+
"main": "./lib",
|
|
20
|
+
"directories": {
|
|
21
|
+
"benchmark": "./benchmark",
|
|
22
|
+
"doc": "./docs",
|
|
23
|
+
"example": "./examples",
|
|
24
|
+
"lib": "./lib",
|
|
25
|
+
"test": "./test"
|
|
26
|
+
},
|
|
27
|
+
"types": "./docs/types",
|
|
28
|
+
"scripts": {},
|
|
29
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {},
|
|
38
|
+
"devDependencies": {},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=0.10.0",
|
|
41
|
+
"npm": ">2.7.0"
|
|
42
|
+
},
|
|
43
|
+
"os": [
|
|
44
|
+
"aix",
|
|
45
|
+
"darwin",
|
|
46
|
+
"freebsd",
|
|
47
|
+
"linux",
|
|
48
|
+
"macos",
|
|
49
|
+
"openbsd",
|
|
50
|
+
"sunos",
|
|
51
|
+
"win32",
|
|
52
|
+
"windows"
|
|
53
|
+
],
|
|
54
|
+
"keywords": [
|
|
55
|
+
"stdlib",
|
|
56
|
+
"stdfs",
|
|
57
|
+
"fs",
|
|
58
|
+
"rename",
|
|
59
|
+
"renamesync",
|
|
60
|
+
"path",
|
|
61
|
+
"async",
|
|
62
|
+
"sync",
|
|
63
|
+
"file",
|
|
64
|
+
"delete",
|
|
65
|
+
"remove",
|
|
66
|
+
"rm",
|
|
67
|
+
"del",
|
|
68
|
+
"change",
|
|
69
|
+
"move",
|
|
70
|
+
"relocate",
|
|
71
|
+
"filesystem"
|
|
72
|
+
]
|
|
73
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2018 The Stdlib Authors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
# Resolve Parent Path
|
|
22
|
+
|
|
23
|
+
> Resolve a path by walking parent directories.
|
|
24
|
+
|
|
25
|
+
<section class="usage">
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
var resolveParentPath = require( '@stdlib/fs/resolve-parent-path' );
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
<a name="resolve-parent-path"></a>
|
|
34
|
+
|
|
35
|
+
#### resolveParentPath( path\[, options], clbk )
|
|
36
|
+
|
|
37
|
+
Asynchronously resolves a path by walking parent directories.
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
resolveParentPath( 'package.json', onPath );
|
|
41
|
+
|
|
42
|
+
function onPath( error, path ) {
|
|
43
|
+
if ( error ) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
console.log( path );
|
|
47
|
+
// => '...'
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The function accepts the following `options`:
|
|
52
|
+
|
|
53
|
+
- **dir**: base directory from which to begin walking. May be either an absolute path or a path relative to the current working directory.
|
|
54
|
+
|
|
55
|
+
By default, the function begins walking from the current working directory. To specify an alternative directory, set the `dir` option.
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
var opts = {
|
|
59
|
+
'dir': __dirname
|
|
60
|
+
};
|
|
61
|
+
resolveParentPath( 'package.json', opts, onPath );
|
|
62
|
+
|
|
63
|
+
function onPath( error, path ) {
|
|
64
|
+
if ( error ) {
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
console.log( path );
|
|
68
|
+
// => '...'
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### resolveParentPath.sync( path\[, options] )
|
|
73
|
+
|
|
74
|
+
Synchronously resolves a path by walking parent directories.
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
var path = resolveParentPath.sync( 'package.json' );
|
|
78
|
+
// returns '...'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The function accepts the same `options` as [`resolveParentPath()`](#resolve-parent-path).
|
|
82
|
+
|
|
83
|
+
</section>
|
|
84
|
+
|
|
85
|
+
<!-- /.usage -->
|
|
86
|
+
|
|
87
|
+
<section class="notes">
|
|
88
|
+
|
|
89
|
+
## Notes
|
|
90
|
+
|
|
91
|
+
- If unable to resolve a path, both functions return `null`.
|
|
92
|
+
- This implementation is **not** similar in functionality to core [`path.resolve`][node-core-path-resolve]. The latter performs string manipulation to generate a full path. This implementation walks parent directories to perform a **search**, thereby touching the file system. Accordingly, this implementation resolves a _real_ absolute file path and is intended for use when a target's location in a parent directory is unknown relative to a child directory; e.g., when wanting to find a package root from deep within a package directory.
|
|
93
|
+
|
|
94
|
+
</section>
|
|
95
|
+
|
|
96
|
+
<!-- /.notes -->
|
|
97
|
+
|
|
98
|
+
<section class="examples">
|
|
99
|
+
|
|
100
|
+
## Examples
|
|
101
|
+
|
|
102
|
+
<!-- eslint no-undef: "error" -->
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
var resolveParentPath = require( '@stdlib/fs/resolve-parent-path' );
|
|
106
|
+
|
|
107
|
+
var opts = {
|
|
108
|
+
'dir': __dirname
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/* Sync */
|
|
112
|
+
|
|
113
|
+
var out = resolveParentPath.sync( 'package.json', opts );
|
|
114
|
+
// returns '...'
|
|
115
|
+
|
|
116
|
+
out = resolveParentPath.sync( 'non_existent_basename' );
|
|
117
|
+
// returns null
|
|
118
|
+
|
|
119
|
+
/* Async */
|
|
120
|
+
|
|
121
|
+
resolveParentPath( 'package.json', opts, onPath );
|
|
122
|
+
resolveParentPath( './../non_existent_path', onPath );
|
|
123
|
+
|
|
124
|
+
function onPath( error, path ) {
|
|
125
|
+
if ( error ) {
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
console.log( path );
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
</section>
|
|
133
|
+
|
|
134
|
+
<!-- /.examples -->
|
|
135
|
+
|
|
136
|
+
* * *
|
|
137
|
+
|
|
138
|
+
<section class="cli">
|
|
139
|
+
|
|
140
|
+
## CLI
|
|
141
|
+
|
|
142
|
+
<section class="usage">
|
|
143
|
+
|
|
144
|
+
### Usage
|
|
145
|
+
|
|
146
|
+
```text
|
|
147
|
+
Usage: resolve-parent-path [options] <path>
|
|
148
|
+
|
|
149
|
+
Options:
|
|
150
|
+
|
|
151
|
+
-h, --help Print this message.
|
|
152
|
+
-V, --version Print the package version.
|
|
153
|
+
--dir dir Base search directory.
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
</section>
|
|
157
|
+
|
|
158
|
+
<!-- /.usage -->
|
|
159
|
+
|
|
160
|
+
<section class="examples">
|
|
161
|
+
|
|
162
|
+
### Examples
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
$ resolve-parent-path package.json
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
</section>
|
|
169
|
+
|
|
170
|
+
<!-- /.examples -->
|
|
171
|
+
|
|
172
|
+
</section>
|
|
173
|
+
|
|
174
|
+
<!-- /.cli -->
|
|
175
|
+
|
|
176
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
177
|
+
|
|
178
|
+
<section class="related">
|
|
179
|
+
|
|
180
|
+
* * *
|
|
181
|
+
|
|
182
|
+
## See Also
|
|
183
|
+
|
|
184
|
+
- <span class="package-name">[`@stdlib/fs/resolve-parent-path-by`][@stdlib/fs/resolve-parent-path-by]</span><span class="delimiter">: </span><span class="description">resolve a path according to a predicate function by walking parent directories.</span>
|
|
185
|
+
|
|
186
|
+
</section>
|
|
187
|
+
|
|
188
|
+
<!-- /.related -->
|
|
189
|
+
|
|
190
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
191
|
+
|
|
192
|
+
<section class="links">
|
|
193
|
+
|
|
194
|
+
[node-core-path-resolve]: https://nodejs.org/api/path.html#path_path_resolve_paths
|
|
195
|
+
|
|
196
|
+
<!-- <related-links> -->
|
|
197
|
+
|
|
198
|
+
[@stdlib/fs/resolve-parent-path-by]: https://github.com/stdlib-js/fs/tree/main/resolve-parent-path-by
|
|
199
|
+
|
|
200
|
+
<!-- </related-links> -->
|
|
201
|
+
|
|
202
|
+
</section>
|
|
203
|
+
|
|
204
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2021 The Stdlib Authors.
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
'use strict';
|
|
22
|
+
|
|
23
|
+
// MODULES //
|
|
24
|
+
|
|
25
|
+
var resolve = require( 'path' ).resolve;
|
|
26
|
+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
|
|
27
|
+
var CLI = require( '@stdlib/cli/ctor' );
|
|
28
|
+
var resolveParentPath = require( './../lib' );
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// MAIN //
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Main execution sequence.
|
|
35
|
+
*
|
|
36
|
+
* @private
|
|
37
|
+
* @returns {void}
|
|
38
|
+
*/
|
|
39
|
+
function main() {
|
|
40
|
+
var flags;
|
|
41
|
+
var args;
|
|
42
|
+
var opts;
|
|
43
|
+
var cli;
|
|
44
|
+
|
|
45
|
+
// Create a command-line interface:
|
|
46
|
+
cli = new CLI({
|
|
47
|
+
'pkg': require( './../package.json' ),
|
|
48
|
+
'options': require( './../etc/cli_opts.json' ),
|
|
49
|
+
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
|
|
50
|
+
'encoding': 'utf8'
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Get any provided command-line options:
|
|
55
|
+
flags = cli.flags();
|
|
56
|
+
if ( flags.help || flags.version ) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Get any provided command-line arguments:
|
|
61
|
+
args = cli.args();
|
|
62
|
+
|
|
63
|
+
opts = {};
|
|
64
|
+
if ( flags.dir ) {
|
|
65
|
+
opts.dir = flags.dir;
|
|
66
|
+
}
|
|
67
|
+
resolveParentPath( args[ 0 ], opts, onPath );
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Callback invoked upon resolving a path.
|
|
71
|
+
*
|
|
72
|
+
* @private
|
|
73
|
+
* @param {(Error|null)} error - error object
|
|
74
|
+
* @param {string} path - resolved path
|
|
75
|
+
* @returns {void}
|
|
76
|
+
*/
|
|
77
|
+
function onPath( error, path ) {
|
|
78
|
+
if ( error ) {
|
|
79
|
+
return cli.error( error );
|
|
80
|
+
}
|
|
81
|
+
console.log( path ); // eslint-disable-line no-console
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
main();
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( path[, options], clbk )
|
|
3
|
+
Asynchronously resolves a path by walking parent directories.
|
|
4
|
+
|
|
5
|
+
If unable to resolve a path, the function returns `null` as the path result.
|
|
6
|
+
|
|
7
|
+
Parameters
|
|
8
|
+
----------
|
|
9
|
+
path: string
|
|
10
|
+
Path to resolve.
|
|
11
|
+
|
|
12
|
+
options: Object (optional)
|
|
13
|
+
Options.
|
|
14
|
+
|
|
15
|
+
options.dir: string (optional)
|
|
16
|
+
Base directory from which to search. Default: current working directory.
|
|
17
|
+
|
|
18
|
+
clbk: Function
|
|
19
|
+
Callback to invoke after resolving a path.
|
|
20
|
+
|
|
21
|
+
Examples
|
|
22
|
+
--------
|
|
23
|
+
> function onPath( error, path ) {
|
|
24
|
+
... if ( error ) {
|
|
25
|
+
... console.error( error.message );
|
|
26
|
+
... } else {
|
|
27
|
+
... console.log( path );
|
|
28
|
+
... }
|
|
29
|
+
... };
|
|
30
|
+
> {{alias}}( 'package.json', onPath );
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
{{alias}}.sync( path[, options] )
|
|
34
|
+
Synchronously resolves a path by walking parent directories.
|
|
35
|
+
|
|
36
|
+
Parameters
|
|
37
|
+
----------
|
|
38
|
+
path: string
|
|
39
|
+
Path to resolve.
|
|
40
|
+
|
|
41
|
+
options: Object (optional)
|
|
42
|
+
Options.
|
|
43
|
+
|
|
44
|
+
options.dir: string (optional)
|
|
45
|
+
Base directory from which to search. Default: current working directory.
|
|
46
|
+
|
|
47
|
+
Returns
|
|
48
|
+
-------
|
|
49
|
+
out: string|null
|
|
50
|
+
Resolved path.
|
|
51
|
+
|
|
52
|
+
Examples
|
|
53
|
+
--------
|
|
54
|
+
> var out = {{alias}}.sync( 'package.json' );
|
|
55
|
+
|
|
56
|
+
See Also
|
|
57
|
+
--------
|
|
58
|
+
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020 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: 4.1
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Interface defining function options.
|
|
23
|
+
*/
|
|
24
|
+
interface Options {
|
|
25
|
+
/**
|
|
26
|
+
* Base directory from which to search (default: current working directory).
|
|
27
|
+
*/
|
|
28
|
+
dir?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Callback invoked after resolving a path.
|
|
33
|
+
*
|
|
34
|
+
* @param err - error argument
|
|
35
|
+
* @param path - resolved path
|
|
36
|
+
*/
|
|
37
|
+
type Callback = ( err: Error | null, path: string | null ) => void;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Interface for resolving a path by walking parent directories.
|
|
41
|
+
*/
|
|
42
|
+
interface ResolveParentPath {
|
|
43
|
+
/**
|
|
44
|
+
* Asynchronously resolves a path by walking parent directories.
|
|
45
|
+
*
|
|
46
|
+
* @param path - path to resolve
|
|
47
|
+
* @param options - function options
|
|
48
|
+
* @param options.dir - base directory
|
|
49
|
+
* @param clbk - callback to invoke after resolving a path
|
|
50
|
+
* @throws must provide valid options
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* resolveParentPath( 'package.json', { 'dir': __dirname }, onPath );
|
|
54
|
+
*
|
|
55
|
+
* function onPath( error, path ) {
|
|
56
|
+
* if ( error ) {
|
|
57
|
+
* throw error;
|
|
58
|
+
* }
|
|
59
|
+
* console.log( path );
|
|
60
|
+
* }
|
|
61
|
+
*/
|
|
62
|
+
( path: string, options: Options, clbk: Callback ): void;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Asynchronously resolves a path by walking parent directories.
|
|
66
|
+
*
|
|
67
|
+
* @param path - path to resolve
|
|
68
|
+
* @param clbk - callback to invoke after resolving a path
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* resolveParentPath( 'package.json', onPath );
|
|
72
|
+
*
|
|
73
|
+
* function onPath( error, path ) {
|
|
74
|
+
* if ( error ) {
|
|
75
|
+
* throw error;
|
|
76
|
+
* }
|
|
77
|
+
* console.log( path );
|
|
78
|
+
* }
|
|
79
|
+
*/
|
|
80
|
+
( path: string, clbk: Callback ): void;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Synchronously resolves a path by walking parent directories.
|
|
84
|
+
*
|
|
85
|
+
* ## Notes
|
|
86
|
+
*
|
|
87
|
+
* - If unable to resolve a path, the function returns `null` as the path result.
|
|
88
|
+
*
|
|
89
|
+
* @param path - path to resolve
|
|
90
|
+
* @param options - function options
|
|
91
|
+
* @param options.dir - base directory
|
|
92
|
+
* @throws must provide valid options
|
|
93
|
+
* @returns resolved path or null
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* var path = resolveParentPath.sync( 'package.json', { 'dir': __dirname } );
|
|
97
|
+
*/
|
|
98
|
+
sync( path: string, options?: Options ): string | null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Asynchronously resolves a path by walking parent directories.
|
|
103
|
+
*
|
|
104
|
+
* @param path - path to resolve
|
|
105
|
+
* @param options - function options
|
|
106
|
+
* @param options.dir - base directory
|
|
107
|
+
* @param clbk - callback to invoke after resolving a path
|
|
108
|
+
* @throws must provide valid options
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* resolveParentPath( 'package.json', onPath );
|
|
112
|
+
*
|
|
113
|
+
* function onPath( error, path ) {
|
|
114
|
+
* if ( error ) {
|
|
115
|
+
* throw error;
|
|
116
|
+
* }
|
|
117
|
+
* console.log( path );
|
|
118
|
+
* }
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* var path = resolveParentPath.sync( 'package.json' );
|
|
122
|
+
*/
|
|
123
|
+
declare var resolveParentPath: ResolveParentPath;
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
// EXPORTS //
|
|
127
|
+
|
|
128
|
+
export = resolveParentPath;
|