trim-whitespace

Remove leading and/or trailing spaces and tabs from each line of a string

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
trim-whitespace
101.3.37 years ago8 years agoMinified + gzip package size for trim-whitespace in KB

Readme

trim whitespace
npm node CircleCI Coveralls styled with prettier
Remove leading and/or trailing spaces and tabs from each line of a string

Install

$ npm install trim-whitespace --save

Usage

Remove leading and trailing spaces and tabs from a string.
const trim = require('trim-whitespace');

trim('\n \tAnakin Skywalker \t\n\t Padme Amidala\t \n');
// \nAnakin Skywalker\nPadme Amidala\n

Remove leading spaces and tabs from a string.
const { leading } = require('trim-whitespace');

leading('\n \tAnakin Skywalker \t\n\t Padme Amidala\t \n');
// \nAnakin Skywalker \t\nPadme Amidala\t \n

Remove trailing spaces and tabs from a string.
const { trailing } = require('trim-whitespace');

trailing('\n \tAnakin Skywalker \t\n\t Padme Amidala\t \n');
// \n \tAnakin Skywalker\n\t Padme Amidala\n

API

const trim = require('trim-whitespace');

trim(str)

Returns a string without any leading or trailing spaces or tabs.

str

  • type: String

The string to trim.

trim.leading(str)

Returns a string without any leading spaces or tabs.

str

  • type: String

The string to trim.

trim.trailing(str)

Returns a string without any trailing spaces or tabs.

str

  • type: String

The string to trim.