Giter Site home page Giter Site logo

rohitsg / string-methods-extension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from onesmallstepfortheweb/string-methods-extension

0.0 0.0 0.0 13 KB

An extension to String Methods, to add some features to ECMAScript 6. It works bothe for Node and the browser.

JavaScript 100.00%

string-methods-extension's Introduction

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:

<script src="string-methods-extension.js"></script>

In Node.js:

require('string-methods-extension');

Using yarn

yarn add string-methods-extension

Table of Contents

Usage

stripLineBreak

The stripLineBreak() method removes all line breaks from a string.

`test\ntest\ntest.`.stripLineBreak();
// => `test test test.`

`test \ntest \ntest.`.stripLineBreak('');
// => `test test test.`

`test\ntest\ntest.`.stripLineBreak('.');
// => `test.test.test.`

trim

The trim() method removes whitespace or a specified character from both sides of a string.

`     ahsdfjhfhf    `.trim();
// => `ahsdfjhfhf`

`......ahsdfjhfhf.....`.trim('.');
// => `ahsdfjhfhf`

trimStart

The trimStart() method removes whitespace or a specified character at the left side of a string.

`     ahsdfjhfhf    `.trimStart();
// => `ahsdfjhfhf    `

`......ahsdfjhfhf.....`.trimStart('.');
// => `ahsdfjhfhf.....`

trimEnd

The trimEnd() method removes whitespace or a specified character at the right side of a string.

`     ahsdfjhfhf    `.trimEnd();
// => `     ahsdfjhfhf`

`......ahsdfjhfhf.....`.trimEnd('.');
// => `......ahsdfjhfhf`

reverse

The reverse() method reverse the characters of a string.

`abcdef`.reverse();
// => `fedcba`

`Hello World`.reverse();
// => `dlroW olleH`

stripTags

The stripTags() method removes html or xml tags from a string.

`Hello <b>world!</b>`.stripTags();
// => `Hello world!`

`Hello <b><a href="hello.html">world!</a></b>`.stripTags();
// => `Hello world!`

stripWhiteSpace

The stripWhiteSpace() method removes white spaces from a string, with a single space or specified character.

`test     test    test`.stripWhiteSpace();
// => `test test test`

`test     test    test`.stripWhiteSpace('.');
// => `test.test.test`

replaceAll

The replaceAll() method returns a string where a specified string is replaced with another specified string.

`123 test nl.`.replaceAll({'123': 'abc','nl': 'Netherlands',});
// => `abc test Netherlands.`

`You should eat fruits, vegetables, and fiber every day`.replaceAll({'fruits': 'pizza','vegetables': 'beer', 'fiber': 'ice cream',});
// => `You should eat pizza, beer, and ice cream every day`

encodeXML

The encodeXML() method adds XML encoding to a string.

`test&"test" 1<2`.encodeXML();
// => `test&amp;&quot;testquot; 1&lt;2`

decodeXML

The decodeXML() method removes XML encoding form a string.

`test&amp;&quot;testquot; 1&lt;2`.decodeXML();
// => `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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.