3.0.0 • Published 7 years ago

normalize-path v3.0.0

Weekly downloads
35,356,326
License
MIT
Repository
github
Last release
7 years ago

normalize-path NPM version NPM monthly downloads NPM total downloads Linux Build Status

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.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.

Install

Install with npm:

$ npm install --save normalize-path

Usage

const normalize = require('normalize-path');

console.log(normalize('\\foo\\bar\\baz\\')); 
//=> '/foo/bar/baz'

win32 namespaces

console.log(normalize('\\\\?\\UNC\\Server01\\user\\docs\\Letter.txt')); 
//=> '//?/UNC/Server01/user/docs/Letter.txt'

console.log(normalize('\\\\.\\CdRomX')); 
//=> '//./CdRomX'

Consecutive slashes

Condenses multiple consecutive forward slashes (except for leading slashes in win32 namespaces) to a single slash.

console.log(normalize('.//foo//bar///////baz/')); 
//=> './foo/bar/baz'

Trailing slashes

By default trailing slashes are removed. Pass false as the last argument to disable this behavior and keep trailing slashes:

console.log(normalize('foo\\bar\\baz\\', false)); //=> 'foo/bar/baz/'
console.log(normalize('./foo/bar/baz/', false)); //=> './foo/bar/baz/'

Release history

v3.0

No breaking changes in this release.

  • a check was added to ensure that win32 namespaces are handled properly by win32 path.parse() after a path has been normalized by this library.
  • a minor optimization was made to simplify how the trailing separator was handled

About

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

Other useful path-related libraries:

Contributors

CommitsContributor
35jonschlinkert
1phated

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on April 19, 2018.

anymatchcontains-pathcopy-webpack-pluginzip-streamcompress-commonsarchiver-utilsglob-streamstylelintvinyl-fsstylus-loaderunixifyeslint-webpack-plugin@savaleukhin/s3-static-assets@savaleukhin/core@savaleukhin/lambda-at-edgearchetype-librarybit-bincomponennentt@dinert/utilseasy-select-rnimily-ftpvuedragdropuploadimagespopsmart-common-authreact-native-bluetooth2killi8n-react-native-fast-image@lucat1/linariarn-send-smsspecify-importsbabel-specify-imports@icanpm/api-master@arisageha/react-lazyload@arisageha/react-lazyload-fix@nhatle/react-build-tools@cashremit/cr-streamline-iconstemp-eleventy-temp@xinke-core/yorkie@dubb/mickeyreact-native-template-rfbasecloud-archive-s3airscanairscan-example@njmaeff/node-build-core@njmaeff/node-build-ui-cli@njmaeff/node-build-clibb-chat@nghiepuit/sdk-builderbase-sdk-buildernghiepuit-build-toolsreact-native-esc-pos-sahaabtwindxnext-linaria-babel@nghiepuit/react-build-tool@ihikmawan/tailwindcss-multi-theme-l2@borisovart/atol-kkt-module@twstyled/next@frxf/frxf@phil8795/pecuniarius-apideneme323112@primal/filesystem@texttree/demo-bsa-reference-rcl@translation/cli@fundefund/funde_ck@ntt_app/react-native-custom-notificationreact-native-custom-text-hwjames@sonammalhotra/lotide@smishra17/lotide@cheapthrills/lotidediscord-music-botsreact-native-covid-sdkgql_din_modbitgetalex-frontend-sdk-stagingreact-native-thanh-toast-library@jttechnic/interpreter@thanhnguyen14797/react-native-thanh-toast-library@l1nyanm1ng/react-picture-viewercthpb-plugin-social@iobroker-community-adapters/iobroker.device-watcher@olivervorasai/sliderpanqibaoreact-native-printer-brothersrn-pdf-reader-offlinecbmis-ai-toolboxamr_to_mp3_sxfomantic-ui-semeia@newhorizon-tech/dd-npm-package-templatereact-native-shekhar-bridge-testasterjscogoportutilsukor-remasterlevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29levinodelib
3.0.0

7 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.0

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago