Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
normalize-path
Advanced tools
Normalize file path slashes to be unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes.
The normalize-path npm package is designed to normalize file paths, making them consistent across different operating systems and environments. It can be particularly useful for handling file paths in a cross-platform manner, ensuring that paths are correctly formatted and can be reliably compared or manipulated regardless of the underlying OS.
Normalize slashes
Converts Windows backslash paths to POSIX forward slashes, making paths consistent across different environments.
"const normalize = require('normalize-path');
console.log(normalize('C:\\path\\to\\file')); // 'C:/path/to/file'"
Remove trailing slashes
Optionally removes trailing slashes from paths, which can be useful for comparing directory paths or constructing URLs.
"const normalize = require('normalize-path');
console.log(normalize('path/to/resource/', false)); // 'path/to/resource'"
Normalize for use in URLs
Cleans up the path by resolving dot segments (e.g., '..' and '.') to produce a canonical path. This is particularly useful for creating clean URLs.
"const normalize = require('normalize-path');
console.log(normalize('/foo/bar//baz/asdf/quux/..')); // '/foo/bar/baz/asdf'"
The 'path' module is a core Node.js module that provides utilities for working with file and directory paths. It offers similar normalization functionalities but is built into Node.js, meaning it doesn't require an additional installation. Unlike normalize-path, it handles paths differently based on the operating system.
upath is an extension of Node.js's path module that normalizes paths to always use forward slashes, similar to normalize-path. It also adds filename and extension manipulation functions. upath provides a broader set of path manipulation utilities while maintaining cross-platform consistency.
Normalize file path slashes to be unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes.
npm i normalize-path --save
npm test
var normalize = require('normalize-path');
console.log(normalize('\\foo\\bar\\baz\\'));
//=> '/foo/bar/baz'
console.log(normalize('./foo/bar/baz/'));
//=> './foo/bar/baz'
Pass false
as the last argument to not strip trailing slashes:
console.log(normalize('./foo/bar/baz/', false));
//=> './foo/bar/baz/'
console.log(normalize('foo\\bar\\baz\\', false));
//=> 'foo/bar/baz/'
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Jon Schlinkert
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on October 24, 2014.
FAQs
Normalize slashes in a file path to be posix/unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes, unless disabled.
The npm package normalize-path receives a total of 46,378,761 weekly downloads. As such, normalize-path popularity was classified as popular.
We found that normalize-path demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.