@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,228 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2024 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
|
+
# resolveParentPaths
|
|
22
|
+
|
|
23
|
+
> Resolve paths from a set of paths by walking parent directories.
|
|
24
|
+
|
|
25
|
+
<section class="usage">
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
var resolveParentPaths = require( '@stdlib/fs/resolve-parent-paths' );
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
<a name="resolve-parent-paths"></a>
|
|
34
|
+
|
|
35
|
+
#### resolveParentPaths( paths\[, options], clbk )
|
|
36
|
+
|
|
37
|
+
Asynchronously resolves paths from a set of paths by walking parent directories.
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
resolveParentPaths( [ 'package.json', 'package-lock.json' ], onPaths );
|
|
41
|
+
|
|
42
|
+
function onPaths( error, paths ) {
|
|
43
|
+
if ( error ) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
console.log( paths );
|
|
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
|
+
- **mode**: mode of operation. The following modes are supported:
|
|
56
|
+
|
|
57
|
+
- `first`: return the first resolved path.
|
|
58
|
+
- `some`: return one or more paths resolved within the first directory level containing a match.
|
|
59
|
+
- `all`: return all resolved paths within the first directory level containing matches for all provided paths.
|
|
60
|
+
- `each`: independently return the first resolved path for each path at any directory level.
|
|
61
|
+
|
|
62
|
+
Default: `'all'`.
|
|
63
|
+
|
|
64
|
+
By default, the function begins walking from the current working directory. To specify an alternative directory, set the `dir` option.
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
var opts = {
|
|
68
|
+
'dir': __dirname
|
|
69
|
+
};
|
|
70
|
+
resolveParentPaths( [ 'package.json' ], opts, onPaths );
|
|
71
|
+
|
|
72
|
+
function onPaths( error, paths ) {
|
|
73
|
+
if ( error ) {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
console.log( paths );
|
|
77
|
+
// => [...]
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
By default, the function requires that a directory contains matches for all provided paths before returning results. To specify an alternative operation mode, set the `mode` option.
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
var opts = {
|
|
85
|
+
'dir': __dirname,
|
|
86
|
+
'mode': 'first'
|
|
87
|
+
};
|
|
88
|
+
resolveParentPaths( [ 'package.json', 'package-lock.json' ], opts, onPaths );
|
|
89
|
+
|
|
90
|
+
function onPaths( error, paths ) {
|
|
91
|
+
if ( error ) {
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
console.log( paths );
|
|
95
|
+
// => [...]
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### resolveParentPaths.sync( paths\[, options] )
|
|
100
|
+
|
|
101
|
+
Synchronously resolves paths from a set of paths by walking parent directories.
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
var paths = resolveParentPaths.sync( [ 'package.json', 'README.md' ] );
|
|
105
|
+
// returns [...]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The function accepts the same `options` as [`resolveParentPaths()`](#resolve-parent-paths).
|
|
109
|
+
|
|
110
|
+
</section>
|
|
111
|
+
|
|
112
|
+
<!-- /.usage -->
|
|
113
|
+
|
|
114
|
+
<section class="notes">
|
|
115
|
+
|
|
116
|
+
## Notes
|
|
117
|
+
|
|
118
|
+
- In `some` mode, the return order of asynchronously resolved paths is not guaranteed.
|
|
119
|
+
- 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 _real_ absolute file paths 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.
|
|
120
|
+
|
|
121
|
+
</section>
|
|
122
|
+
|
|
123
|
+
<!-- /.notes -->
|
|
124
|
+
|
|
125
|
+
<section class="examples">
|
|
126
|
+
|
|
127
|
+
## Examples
|
|
128
|
+
|
|
129
|
+
<!-- eslint no-undef: "error" -->
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
var resolveParentPaths = require( '@stdlib/fs/resolve-parent-paths' );
|
|
133
|
+
|
|
134
|
+
var opts = {
|
|
135
|
+
'dir': __dirname
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/* Sync */
|
|
139
|
+
|
|
140
|
+
var out = resolveParentPaths.sync( [ 'package.json', 'README.md' ], opts );
|
|
141
|
+
// returns [...]
|
|
142
|
+
|
|
143
|
+
out = resolveParentPaths.sync( [ 'non_existent_basename' ], opts );
|
|
144
|
+
// returns []
|
|
145
|
+
|
|
146
|
+
opts.mode = 'first';
|
|
147
|
+
out = resolveParentPaths.sync( [ 'non_existent_basename', 'package.json' ], opts );
|
|
148
|
+
// returns [...]
|
|
149
|
+
|
|
150
|
+
/* Async */
|
|
151
|
+
|
|
152
|
+
resolveParentPaths( [ 'package.json', 'README.md' ], opts, onPaths );
|
|
153
|
+
resolveParentPaths( [ './../non_existent_path' ], onPaths );
|
|
154
|
+
|
|
155
|
+
function onPaths( error, paths ) {
|
|
156
|
+
if ( error ) {
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
console.log( paths );
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
</section>
|
|
164
|
+
|
|
165
|
+
<!-- /.examples -->
|
|
166
|
+
|
|
167
|
+
* * *
|
|
168
|
+
|
|
169
|
+
<section class="cli">
|
|
170
|
+
|
|
171
|
+
## CLI
|
|
172
|
+
|
|
173
|
+
<section class="usage">
|
|
174
|
+
|
|
175
|
+
### Usage
|
|
176
|
+
|
|
177
|
+
```text
|
|
178
|
+
Usage: resolve-parent-paths [options] <path> [<path>...]
|
|
179
|
+
|
|
180
|
+
Options:
|
|
181
|
+
|
|
182
|
+
-h, --help Print this message.
|
|
183
|
+
-V, --version Print the package version.
|
|
184
|
+
--dir dir Base search directory.
|
|
185
|
+
--mode mode Mode of operation.
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
</section>
|
|
189
|
+
|
|
190
|
+
<!-- /.usage -->
|
|
191
|
+
|
|
192
|
+
<section class="examples">
|
|
193
|
+
|
|
194
|
+
### Examples
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
$ resolve-parent-paths package.json package-lock.json
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
</section>
|
|
201
|
+
|
|
202
|
+
<!-- /.examples -->
|
|
203
|
+
|
|
204
|
+
</section>
|
|
205
|
+
|
|
206
|
+
<!-- /.cli -->
|
|
207
|
+
|
|
208
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
209
|
+
|
|
210
|
+
<section class="related">
|
|
211
|
+
|
|
212
|
+
</section>
|
|
213
|
+
|
|
214
|
+
<!-- /.related -->
|
|
215
|
+
|
|
216
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
217
|
+
|
|
218
|
+
<section class="links">
|
|
219
|
+
|
|
220
|
+
[node-core-path-resolve]: https://nodejs.org/api/path.html#path_path_resolve_paths
|
|
221
|
+
|
|
222
|
+
<!-- <related-links> -->
|
|
223
|
+
|
|
224
|
+
<!-- </related-links> -->
|
|
225
|
+
|
|
226
|
+
</section>
|
|
227
|
+
|
|
228
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2024 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 resolveParentPaths = 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
|
+
if ( flags.mode ) {
|
|
68
|
+
opts.mode = flags.mode;
|
|
69
|
+
}
|
|
70
|
+
resolveParentPaths( args, opts, onPaths );
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Callback invoked upon resolving a path.
|
|
74
|
+
*
|
|
75
|
+
* @private
|
|
76
|
+
* @param {(Error|null)} error - error object
|
|
77
|
+
* @param {string} paths - resolved paths
|
|
78
|
+
* @returns {void}
|
|
79
|
+
*/
|
|
80
|
+
function onPaths( error, paths ) {
|
|
81
|
+
var i;
|
|
82
|
+
if ( error ) {
|
|
83
|
+
return cli.error( error );
|
|
84
|
+
}
|
|
85
|
+
for ( i = 0; i < paths.length; i++ ) {
|
|
86
|
+
if ( paths[ i ] ) {
|
|
87
|
+
console.log( paths[ i ] ); // eslint-disable-line no-console
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
main();
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( paths[, options], clbk )
|
|
3
|
+
Asynchronously resolves paths from a set of paths by walking parent
|
|
4
|
+
directories.
|
|
5
|
+
|
|
6
|
+
Parameters
|
|
7
|
+
----------
|
|
8
|
+
paths: Array<string>
|
|
9
|
+
Paths to resolve.
|
|
10
|
+
|
|
11
|
+
options: Object (optional)
|
|
12
|
+
Options.
|
|
13
|
+
|
|
14
|
+
options.dir: string (optional)
|
|
15
|
+
Base directory from which to search. Default: current working directory.
|
|
16
|
+
|
|
17
|
+
options.mode: string (optional)
|
|
18
|
+
Mode of operation. The following modes are supported:
|
|
19
|
+
|
|
20
|
+
- first: return the first resolved path.
|
|
21
|
+
- some: return one or more paths resolved within the first directory
|
|
22
|
+
level containing a match.
|
|
23
|
+
- all: return all resolved paths within the first directory level
|
|
24
|
+
containing matches for all provided paths.
|
|
25
|
+
- each: independently return the first resolved path for each path at
|
|
26
|
+
any directory level.
|
|
27
|
+
|
|
28
|
+
Default: 'all'.
|
|
29
|
+
|
|
30
|
+
clbk: Function
|
|
31
|
+
Callback to invoke after resolving a path.
|
|
32
|
+
|
|
33
|
+
Examples
|
|
34
|
+
--------
|
|
35
|
+
> function onPaths( error, paths ) {
|
|
36
|
+
... if ( error ) {
|
|
37
|
+
... console.error( error.message );
|
|
38
|
+
... } else {
|
|
39
|
+
... console.log( paths );
|
|
40
|
+
... }
|
|
41
|
+
... };
|
|
42
|
+
> {{alias}}( [ 'package.json', 'package-lock.json' ], onPaths );
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
{{alias}}.sync( paths[, options] )
|
|
46
|
+
Synchronously resolves paths from a set of paths by walking parent
|
|
47
|
+
directories.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
paths: Array<string>
|
|
52
|
+
Paths to resolve.
|
|
53
|
+
|
|
54
|
+
options: Object (optional)
|
|
55
|
+
Options.
|
|
56
|
+
|
|
57
|
+
options.dir: string (optional)
|
|
58
|
+
Base directory from which to search. Default: current working directory.
|
|
59
|
+
|
|
60
|
+
options.mode: string (optional)
|
|
61
|
+
Mode of operation. The following modes are supported:
|
|
62
|
+
|
|
63
|
+
- first: return the first resolved path.
|
|
64
|
+
- some: return one or more paths resolved within the first directory
|
|
65
|
+
level containing a match.
|
|
66
|
+
- all: return all resolved paths within the first directory level
|
|
67
|
+
containing matches for all provided paths.
|
|
68
|
+
- each: independently return the first resolved path for each path at
|
|
69
|
+
any directory level.
|
|
70
|
+
|
|
71
|
+
Default: 'all'.
|
|
72
|
+
|
|
73
|
+
Returns
|
|
74
|
+
-------
|
|
75
|
+
out: Array<string|null>
|
|
76
|
+
Resolved paths.
|
|
77
|
+
|
|
78
|
+
Examples
|
|
79
|
+
--------
|
|
80
|
+
> var out = {{alias}}.sync( [ 'package.json', 'package-lock.json' ] );
|
|
81
|
+
|
|
82
|
+
See Also
|
|
83
|
+
--------
|
|
84
|
+
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
* Mode of operation.
|
|
32
|
+
*
|
|
33
|
+
* ## Notes
|
|
34
|
+
*
|
|
35
|
+
* - The following modes are supported:
|
|
36
|
+
*
|
|
37
|
+
* - **first**: return the first resolved path.
|
|
38
|
+
* - **some**: return one or more paths resolved within the first directory level containing a match.
|
|
39
|
+
* - **all**: return all resolved paths within the first directory level containing matches for all provided paths.
|
|
40
|
+
* - **each**: independently return the first resolved path for each path at any directory level.
|
|
41
|
+
*
|
|
42
|
+
* Default: `'all'`.
|
|
43
|
+
*
|
|
44
|
+
* - In `'some'` mode, the return order of resolved paths is not guaranteed.
|
|
45
|
+
*/
|
|
46
|
+
mode?: 'first' | 'some' | 'all' | 'each';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Callback invoked after resolving paths.
|
|
51
|
+
*
|
|
52
|
+
* @param err - error argument
|
|
53
|
+
* @param paths - resolved paths
|
|
54
|
+
*/
|
|
55
|
+
type Callback = ( err: Error | null, paths: Array<string|null> ) => void;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Interface for resolving paths from a set of paths by walking parent directories.
|
|
59
|
+
*/
|
|
60
|
+
interface ResolveParentPaths {
|
|
61
|
+
/**
|
|
62
|
+
* Asynchronously resolves paths from a set of paths by walking parent directories.
|
|
63
|
+
*
|
|
64
|
+
* @param paths - path to resolve
|
|
65
|
+
* @param options - function options
|
|
66
|
+
* @param options.dir - base directory
|
|
67
|
+
* @param options.mode - mode of operation
|
|
68
|
+
* @param clbk - callback to invoke after resolving paths
|
|
69
|
+
* @throws must provide valid options
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* resolveParentPaths( [ 'package.json', 'package-lock.json' ], { 'dir': __dirname, 'mode': 'some' }, onPaths );
|
|
73
|
+
*
|
|
74
|
+
* function onPaths( error, paths ) {
|
|
75
|
+
* if ( error ) {
|
|
76
|
+
* throw error;
|
|
77
|
+
* }
|
|
78
|
+
* console.log( paths );
|
|
79
|
+
* }
|
|
80
|
+
*/
|
|
81
|
+
( paths: Array<string>, options: Options, clbk: Callback ): void;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Asynchronously resolves paths from a set of paths by walking parent directories.
|
|
85
|
+
*
|
|
86
|
+
* @param paths - path to resolve
|
|
87
|
+
* @param clbk - callback to invoke after resolving paths
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* resolveParentPaths( [ 'package.json', 'package-lock.json' ], onPaths );
|
|
91
|
+
*
|
|
92
|
+
* function onPaths( error, paths ) {
|
|
93
|
+
* if ( error ) {
|
|
94
|
+
* throw error;
|
|
95
|
+
* }
|
|
96
|
+
* console.log( paths );
|
|
97
|
+
* }
|
|
98
|
+
*/
|
|
99
|
+
( paths: Array<string>, clbk: Callback ): void;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Synchronously resolves paths from a set of paths by walking parent directories.
|
|
103
|
+
*
|
|
104
|
+
* @param paths - paths to resolve
|
|
105
|
+
* @param options - function options
|
|
106
|
+
* @param options.dir - base directory
|
|
107
|
+
* @param options.mode - mode of operation
|
|
108
|
+
* @throws must provide valid options
|
|
109
|
+
* @returns resolved paths
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* var paths = resolveParentPaths.sync( [ 'package.json', 'package-lock.json' ], { 'dir': __dirname, 'mode': 'some' } );
|
|
113
|
+
*/
|
|
114
|
+
sync( paths: Array<string>, options?: Options ): Array<string|null>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Asynchronously resolves paths from a set of paths by walking parent directories.
|
|
119
|
+
*
|
|
120
|
+
* @param paths - paths to resolve
|
|
121
|
+
* @param options - function options
|
|
122
|
+
* @param options.dir - base directory
|
|
123
|
+
* @param options.mode - mode of operation
|
|
124
|
+
* @param clbk - callback to invoke after resolving paths
|
|
125
|
+
* @throws must provide valid options
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* resolveParentPaths( [ 'package.json', 'package-lock.json' ], onPaths );
|
|
129
|
+
*
|
|
130
|
+
* function onPaths( error, paths ) {
|
|
131
|
+
* if ( error ) {
|
|
132
|
+
* throw error;
|
|
133
|
+
* }
|
|
134
|
+
* console.log( paths );
|
|
135
|
+
* }
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* var paths = resolveParentPaths.sync( [ 'package.json', 'package-lock.json' ] );
|
|
139
|
+
*/
|
|
140
|
+
declare var resolveParentPaths: ResolveParentPaths;
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
// EXPORTS //
|
|
144
|
+
|
|
145
|
+
export = resolveParentPaths;
|