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.
@autovance/filepath
Advanced tools
URL like utility for manipulating file paths, names and extensions
URL like utility for manipulating file paths, names and extensions
Use this class to parse and manipulate file paths and names across platforms. Check out the tests for example use.
Dependencies: zero
Test Coverage: 100%
Setup a path
const path = new FilePath('this/is/a/file.jpeg');
Set: set up a path. Used in the constructor
Get: get the fully qualified path
const originalFile = new FilePath();
originalFile.path = '/this/is/a/file.jpeg';
console.log(originalFile.path);
> '/this/is/a/file.jpeg'
Set: set a file and extension
If the extension is missing, it will be undefined.
Get: get the file with the extension
const path = new FilePath('this/is/a/file.jpeg');
path.file = 'other.pdf'
console.log(path.file, path.filename, path.extension, path.path);
> 'other.pdf'
> 'other'
> 'pdf'
> 'this/is/a/other.pdf'
path.file = 'new';
console.log(path.file, path.filename, path.extension, path.path);
> 'new'
> 'new'
> undefined
> 'this/is/a/new'
Set: change the directory (without the file) Get: get the directory (without the file)
const path = new FilePath('this/is/a/file.jpeg');
path.dir = '/this/is/the'
console.log(path.dir, path.file, path.filename, path.extension, path.path);
> '/this/is/the'
> 'file.jpeg'
> 'file'
> 'jpeg'
> 'this/is/the/file.jpeg'
Set: set the filename (without extension)
Get: get the filename (without extension)
const path = new FilePath('this/is/a/file.jpeg');
path.filename = 'new'
console.log(path.file, path.filename, path.extension, path.path);
> 'new.jpeg'
> 'new'
> 'jpeg'
> 'this/is/a/new.jpeg'
Set: set the extension
Get: get the extension (does not include the .
delimiter)
const path = new FilePath('this/is/a/file.jpeg');
path.extension = 'png';
console.log(path.extension, path.file, path.path);
> 'png'
> 'file.png'
> 'this/is/a/file.png'
An ordered array of folder names. folders[0] represents the root of the path. If absolute, it will be empty '' (required), if relative, it will be the first folder, or reference '.' or '..'.
The recommended use it to change a specific folder in the path, using the index.
const path = new FilePath('/this/is/a/file.jpeg');
console.log(path.folders);
> ['', 'this', 'is', 'a']
path.path = 'this/is/the/file.jpeg';
console.log(path.folders);
> ['this', 'is', 'the']
path.folders.unshift('..');
path.folders[path.folders.length - 1] = 'relative';
console.log(path.folders, path.path);
> ['..', 'this', 'is', 'relative']
> '../this/is/relative/file.jpeg'
Booleans indicating if the path is absolute or relative. Absolute paths start with '/',
and path.folders[0] === ''
;
const path = new FilePath('/this/is/a/file.jpeg');
console.log(path.isAbsolute, path.isRelative)
> true
> false
path.path = 'this/is/a/file.jpeg';
console.log(path.isAbsolute, path.isRelative)
> false
> true
path.path = './this/is/a/file.jpeg';
console.log(path.isAbsolute, path.isRelative)
> false
> true
path.path = '../this/is/a/file.jpeg';
console.log(path.isAbsolute, path.isRelative)
> false
> true
FAQs
URL like utility for manipulating file paths, names and extensions
The npm package @autovance/filepath receives a total of 25 weekly downloads. As such, @autovance/filepath popularity was classified as not popular.
We found that @autovance/filepath 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.