Skip to content

jridgewell/trimmest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trimmest Build Status

Trims leading and trialing whitespace off of a string, with optional specified start and end indices.

Semantically equivalent to String.prototype.trim, but much faster for strings with little or no whitespace.

Also provides trimStart/trimLeft and trimEnd/trimRight methods.

Installation

npm install trimmest

Usage

var trimmest = require('trimmest')

trimmest('   ') // => ''
trimmest(' \n\t\r') // => ''
trimmest(' test ') // => 'test'

trimmest.trimStart(' test ') // => 'test '
trimmest.trimLeft(' test ') // => 'test '

trimmest.trimEnd(' test ') // => ' test'
trimmest.trimRight(' test ') // => ' test'


// Optional start and end indices, which is convenient for trimming
// during string parsing.
// Whitespace will be trimmed around these indices.
trimmest('test1,   test2', /* start */ 6) // => 'test2'
trimmest('test1,   test2', undefined, /* end */ 7) // => 'test1'

License

MIT

About

Trims leading and trailing whitespace

Resources

License

Stars

Watchers

Forks

Packages

No packages published