normalize-slashes

1.0.1 • Public • Published

normalize-slashes Build Status js-standard-style

Normalize paths to by adding or removing beginning and/or end slashes. Also, deduplicates extra slashes to a single slash and resolves .. and ..

Installation

npm i -g normalize-slashes

Usage

// remove start and end slashes by default
normalize('hello/world')            // 'hello/world'
normalize('/hello/world/')          // 'hello/world'
normalize('//hello//world//')       // 'hello/world'
normalize('/hello/../world/', opts) // 'world'
 
// normalize to have end slashes (remove start slashes)
var opts = {
  end: true
}
normalize('hello/world', opts)      // 'hello/world/' <- slash added
normalize('/hello/world/', opts)    // 'hello/world/'
normalize('//hello//world//', opts) // 'hello/world/'
normalize('/hello/../world/', opts) // 'world/'
 
// normalize to have start slashes (remove end slashes)
var opts = {
  start: true
}
normalize('hello/world', opts)      // '/hello/world' <- slash added
normalize('/hello/world/', opts)    // '/hello/world'
normalize('//hello//world//', opts) // '/hello/world'
normalize('/hello/../world/', opts) // '/world'
 
// normalize to have start and end slashes
var opts = {
  start: true,
  end: true
}
normalize('hello/world', opts)      // '/hello/world/' <- slashes added
normalize('/hello/world/', opts)    // '/hello/world/'
normalize('//hello//world//', opts) // '/hello/world/'
normalize('/hello/../world/', opts) // '/world/'

License

MIT

Dependencies (2)

Dev Dependencies (3)

Package Sidebar

Install

npm i normalize-slashes

Weekly Downloads

3

Version

1.0.1

License

MIT

Last publish

Collaborators

  • tjmehta