1.0.1 • Published 7 years ago

normalize-slashes v1.0.1

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

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