Gathering detailed insights and metrics for @stdlib/fs-resolve-parent-path-by
Gathering detailed insights and metrics for @stdlib/fs-resolve-parent-path-by
Gathering detailed insights and metrics for @stdlib/fs-resolve-parent-path-by
Gathering detailed insights and metrics for @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
Resolve a path according to a predicate function by walking parent directories.
npm install @stdlib/fs-resolve-parent-path-by
Typescript
Module System
Min. Node Version
Node Version
NPM Version
71.2
Supply Chain
88.9
Quality
81.4
Maintenance
100
Vulnerability
88
License
JavaScript (100%)
Total Downloads
3,420
Last Day
1
Last Week
10
Last Month
73
Last Year
712
Apache-2.0 License
1 Stars
60 Commits
3 Watchers
5 Branches
13 Contributors
Updated on Jan 13, 2025
Minified
Minified + Gzipped
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
Published on
Jul 27, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-47.4%
10
Compared to previous week
Last Month
-15.1%
73
Compared to previous month
Last Year
-22.3%
712
Compared to previous year
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!
Resolve a path according to a predicate function by walking parent directories.
1npm install @stdlib/fs-resolve-parent-path-by
1var resolveParentPathBy = require( '@stdlib/fs-resolve-parent-path-by' );
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
:
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 the predicate
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.
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.
predicate
function calls the next
callback with a truthy error
argument, the function suspends execution and immediately calls the done
callback for subsequent error
handling.resolveParentPathBy
, execution is not guaranteed to be asynchronous. To guarantee asynchrony, wrap the done
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
).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.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 );
@stdlib/fs-resolve-parent-path
: resolve a path by walking parent directories.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.
See LICENSE.
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
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-05-05
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 More