Skip to content

tjmehta/normalize-slashes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Remove or add beginning and/or end slashes

Resources

License

Stars

Watchers

Forks

Packages

No packages published