string-methods-extension
This package extends the String Methods, to add some features to ECMAScript 6. It works nicely bothe for Node and the browser.
Installation
Via npm:
npm install string-methods-extension
In a browser:
In Node.js:
;
Using yarn
yarn add string-methods-extension
Table of Contents
- stripLineBreak
- trim
- trimStart
- trimEnd
- reverse
- stripTags
- stripWhiteSpace
- replaceAll
- encodeXML
- decodeXML
Usage
stripLineBreak
The stripLineBreak()
method removes all line breaks from a string.
`test\ntest\ntest.`;// => `test test test.` `test \ntest \ntest.`;// => `test test test.` `test\ntest\ntest.`;// => `test.test.test.`
trim
The trim()
method removes whitespace or a specified character from both sides of a string.
` ahsdfjhfhf `;// => `ahsdfjhfhf` `......ahsdfjhfhf.....`;// => `ahsdfjhfhf`
trimStart
The trimStart()
method removes whitespace or a specified character at the left side of a string.
` ahsdfjhfhf `;// => `ahsdfjhfhf ` `......ahsdfjhfhf.....`;// => `ahsdfjhfhf.....`
trimEnd
The trimEnd()
method removes whitespace or a specified character at the right side of a string.
` ahsdfjhfhf `;// => ` ahsdfjhfhf` `......ahsdfjhfhf.....`;// => `......ahsdfjhfhf`
reverse
The reverse()
method reverse the characters of a string.
`abcdef`;// => `fedcba` `Hello World`;// => `dlroW olleH`
stripTags
The stripTags()
method removes html or xml tags from a string.
`Hello <b>world!</b>`;// => `Hello world!` `Hello <b><a href="hello.html">world!</a></b>`;// => `Hello world!`
stripWhiteSpace
The stripWhiteSpace()
method removes white spaces from a string, with a single space or specified character.
`test test test`;// => `test test test` `test test test`;// => `test.test.test`
replaceAll
The replaceAll()
method returns a string where a specified string is replaced with another specified string.
`123 test nl.`;// => `abc test Netherlands.` `You should eat fruits, vegetables, and fiber every day`;// => `You should eat pizza, beer, and ice cream every day`
encodeXML
The encodeXML()
method adds XML encoding to a string.
`test&"test" 1<2`;// => `test&"testquot; 1<2`
decodeXML
The decodeXML()
method removes XML encoding form a string.
`test&"testquot; 1<2`;// => `test&"test" 1<2`
Unit tests & code coverage
After cloning this repository, run npm install--dev
to install the dependencies needed for he development and testing.
Once that is done, you can run the unit tests in Node using npm test