Installations
npm install @stdlib/fs-resolve-parent-path-by
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=0.10.0
Node Version
16.20.2
NPM Version
8.19.4
Score
71.2
Supply Chain
88.9
Quality
82.8
Maintenance
100
Vulnerability
88
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
3,165
Last Day
2
Last Week
25
Last Month
87
Last Year
792
GitHub Statistics
1 Stars
60 Commits
3 Watching
5 Branches
11 Contributors
Bundle Size
15.64 kB
Minified
4.18 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
0.2.2
Package Id
@stdlib/fs-resolve-parent-path-by@0.2.2
Unpacked Size
53.80 kB
Size
12.54 kB
File Count
13
NPM Version
8.19.4
Node Version
16.20.2
Publised On
27 Jul 2024
Total Downloads
Cumulative downloads
Total Downloads
3,165
Last day
0%
2
Compared to previous day
Last week
13.6%
25
Compared to previous week
Last month
480%
87
Compared to previous month
Last year
-17.3%
792
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
resolveParentPathBy
Resolve a path according to a predicate function by walking parent directories.
Installation
1npm install @stdlib/fs-resolve-parent-path-by
Usage
1var resolveParentPathBy = require( '@stdlib/fs-resolve-parent-path-by' );
resolveParentPathBy( path[, options], predicate, clbk )
Asynchronously resolves a path according to a predicate
function by walking parent directories.
1resolveParentPathBy( 'package.json', predicate, onPath ); 2 3function predicate( path, next ) { 4 var bool = ( /\/test\//.test( path ) === false ); 5 next( null, bool ); 6} 7 8function onPath( error, path ) { 9 if ( error ) { 10 throw error; 11 } 12 console.log( path ); 13 // e.g., => '...' 14}
The function accepts the following options
:
- dir: base directory from which to begin walking. May be either an absolute path or a path relative to the current working directory.
By default, the function begins walking from the current working directory. To specify an alternative directory, set the dir
option.
1var opts = { 2 'dir': __dirname 3}; 4resolveParentPathBy( 'package.json', opts, predicate, onPath ); 5 6function predicate( path, next ) { 7 var bool = ( /\/test\//.test( path ) === false ); 8 next( null, bool ); 9} 10 11function onPath( error, path ) { 12 if ( error ) { 13 throw error; 14 } 15 console.log( path ); 16 // e.g., => '...' 17}
When invoked, the predicate
function is provided two arguments:
path
: a resolved path.next
: a callback which should be called once thepredicate
function has finished processing a resolved path.
If a predicate
function calls the next
callback with a truthy second argument, the function stops processing any additional paths and returns the resolved path as the test result.
If unable to resolve a path, the function returns null
as the path result.
resolveParentPathBy.sync( path[, options], predicate )
Synchronously resolves a path according to a predicate
function by walking parent directories.
1function predicate( path ) { 2 return ( /\/test\//.test( path ) === false ); 3} 4 5var path = resolveParentPathBy.sync( 'package.json', predicate ); 6// e.g., returns '...'
The function accepts the same options
as resolveParentPathBy()
.
When invoked, the predicate
function is provided one argument:
path
: a resolved path.
The function immediately returns upon encountering a truthy predicate
function return value.
If unable to resolve a path, the function returns null
as the path result.
Notes
- If a provided
predicate
function calls thenext
callback with a truthyerror
argument, the function suspends execution and immediately calls thedone
callback for subsequenterror
handling. - For
resolveParentPathBy
, execution is not guaranteed to be asynchronous. To guarantee asynchrony, wrap thedone
callback in a function which either executes at the end of the current stack (e.g.,nextTick
) or during a subsequent turn of the event loop (e.g.,setImmediate
,setTimeout
). - This implementation is not similar in functionality to 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.
Examples
1var resolveParentPathBy = require( '@stdlib/fs-resolve-parent-path-by' ); 2 3var opts = { 4 'dir': __dirname 5}; 6 7/* Sync */ 8 9function predicateSync( path ) { 10 var pkg = require( path ); 11 if ( pkg.name !== '@stdlib/stdlib' ) { 12 return false; 13 } 14 return true; 15} 16 17var out = resolveParentPathBy.sync( 'package.json', opts, predicateSync ); 18console.log( out ); 19// e.g., => '...' 20 21out = resolveParentPathBy.sync( 'non_existent_basename/package.json', predicateSync ); 22console.log( out ); 23// => null 24 25/* Async */ 26 27function predicateAsync( path, next ) { 28 setTimeout( onTimeout, 0 ); 29 30 function onTimeout() { 31 var pkg = require( path ); 32 if ( pkg.name !== '@stdlib/stdlib' ) { 33 return next( null, false ); 34 } 35 next( null, true ); 36 } 37} 38 39function onPath( error, path ) { 40 if ( error ) { 41 throw error; 42 } 43 console.log( path ); 44} 45 46resolveParentPathBy( 'package.json', opts, predicateAsync, onPath ); 47resolveParentPathBy( './../non_existent_path/package.json', predicateAsync, onPath );
See Also
@stdlib/fs-resolve-parent-path
: resolve a path by walking parent directories.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy
- Info: Found text in security policy: SECURITY.md:1
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:85: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/fs-resolve-parent-path-by/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:275: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/fs-resolve-parent-path-by/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:449: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/fs-resolve-parent-path-by/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:457: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/fs-resolve-parent-path-by/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:623: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/fs-resolve-parent-path-by/productionize.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:165
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:83
- Warn: npmCommand not pinned by hash: .github/workflows/test_bundles.yml:72
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:74
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_published_package.yml:93
- Info: 33 out of 33 GitHub-owned GitHubAction dependencies pinned
- Info: 19 out of 24 third-party GitHubAction dependencies pinned
- Info: 0 out of 32 npmCommand dependencies pinned
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/benchmark.yml:1
- Warn: no topLevel permission defined: .github/workflows/cancel.yml:1
- Warn: no topLevel permission defined: .github/workflows/close_pull_requests.yml:1
- Warn: no topLevel permission defined: .github/workflows/examples.yml:1
- Warn: no topLevel permission defined: .github/workflows/npm_downloads.yml:1
- Warn: no topLevel permission defined: .github/workflows/productionize.yml:1
- Warn: no topLevel permission defined: .github/workflows/publish.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_bundles.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_coverage.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_install.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_published_package.yml:1
- Info: no jobLevel write permissions found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
4.3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @stdlib/fs-resolve-parent-path-by
@stdlib/fs-resolve-parent-path
Resolve a path by walking parent directories.
@stdlib/fs-resolve-parent-path-cli
Resolve a path by walking parent directories.
@ffras4vnpm/vitae-facere-tempora
A utility that provides a fluent, convenient interface for working with arrays of data in JavaScript. Influenced by Laravel Collections.
@crabas0npm/vitae-alias-blanditiis
* Convert an absolute path to a tilde path: `/Users/YourUserName/dev` → `~/dev` * Inspired by [tilify](https://github.com/sindresorhus/tildify) by [Sindre Sorhus](https://github.com/sindresorhus) * Since tildify uses ES6 syntax, I created this package to