Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The 'parents' npm package is a utility that allows you to get an array of the directory paths from a given directory up to the root directory. It is useful for file system navigation and operations that require knowledge of a file or directory's ancestry.
Get parent directories
This feature allows you to retrieve an array of parent directories of a given path. The array starts with the immediate parent directory and ends with the root directory.
const parents = require('parents');
const dirs = parents('/usr/local/bin/node');
console.log(dirs); // ['/usr/local/bin', '/usr/local', '/usr', '/']
The 'path-parents' package provides similar functionality to 'parents' by returning an array of parent paths. It differs in its API and additional options for filtering the results.
The 'find-parent-dir' package finds the nearest parent directory that contains a given file or directory. It is similar to 'parents' but focuses on locating a specific file or directory in the ancestry rather than listing all parent directories.
The 'pkg-dir' package finds the root directory of a Node.js project or npm package. This is a more specialized use case compared to 'parents', which is more general in listing parent directories.
Return all the parent directories of a directory, inclusive of that directory.
var parents = require('parents');
var dirs = parents(__dirname);
console.dir(dirs);
[ '/home/substack/projects/node-parents/example',
'/home/substack/projects/node-parents',
'/home/substack/projects',
'/home/substack',
'/home',
'/' ]
var parents = require('parents');
var dir = 'C:\\Program Files\\Maxis\\Sim City 2000\\cities';
var dirs = parents(dir, { platform : 'win32' });
console.dir(dirs);
[ 'C:\\Program Files\\Maxis\\Sim City 2000\\cities',
'C:\\Program Files\\Maxis\\Sim City 2000',
'C:\\Program Files\\Maxis',
'C:\\Program Files',
'C:' ]
var parents = require('parents')
Return an array of the parent directories of dir
, including and starting with
dir
. If a dir
isn't specified, process.cwd()
will be used.
Optionally specify an opts.platform
to control whether the separator and paths
works the unixy way with '/'
or the windowsy way where sometimes things use
'/'
and sometimes they use '\\'
and also there are leading drive letters and
other exotic features. If opts.platform
isn't specified, process.platform
will be used. Anything that matches /^win/
will use the windowsy behavior.
With npm do:
npm install parents
MIT
FAQs
return all the parent directories for a directory
The npm package parents receives a total of 1,075,214 weekly downloads. As such, parents popularity was classified as popular.
We found that parents demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.