Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
strip-dirs
Advanced tools
Remove leading directory components from a path, like tar's --strip-components option
Remove leading directory components from a path, like tar(1)'s --strip-components
option
const stripDirs = require('strip-dirs');
stripDirs('foo/bar/baz', 1); //=> 'bar/baz'
stripDirs('foo/bar/baz', 2); //=> 'baz'
stripDirs('foo/bar/baz', 999); //=> 'baz'
npm install strip-dirs
const stripDirs = require('strip-dirs');
path: string
(A relative path)
count: integer
(>= 0
)
option: Object
Return: string
It removes directory components from the beginning of the path by count.
const stripDirs = require('strip-dirs');
stripDirs('foo/bar', 1); //=> 'bar'
stripDirs('foo/bar/baz', 2); //=> 'bar'
stripDirs('foo/././/bar/./', 1); //=> 'bar'
stripDirs('foo/bar', 0); //=> 'foo/bar'
stripDirs('/foo/bar', 1) // throw an error because the path is an absolute path
If you want to remove all directory components certainly, use path.basename
instead of this module.
Type: boolean
Default: false
By default, it keeps the last path component when path components are fewer than the count.
If this option is enabled, it throws an error in this situation.
stripDirs('foo/bar/baz', 9999); //=> 'baz'
stripDirs('foo/bar/baz', 9999, {disallowOverflow: true}); // throws an range error
ISC License © 2017 - 2018 Shinnosuke Watanabe
FAQs
Remove leading directory components from a path, like tar's --strip-components option
The npm package strip-dirs receives a total of 2,780,245 weekly downloads. As such, strip-dirs popularity was classified as popular.
We found that strip-dirs 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.