@easytech-international-sdn-bhd/jstring
v1.1.7
Published
Custom string class for JavaScript
Downloads
18
Maintainers
Readme
JString
Handy tool for Javascript String. Can be used in NodeJS
React-Native
ReactJS
applications.
Table of Contents
Installation
With npm
:
$ npm install @easytech-international-sdn-bhd/jstring
With yarn
:
$ yarn add @easytech-international-sdn-bhd/jstring
Methods
Any string like 'null'/'undefined' will be auto converted to ''
| method | description | example |
|---|---|---|
| trimHtml
| Remove all the html tags from string | JString(<p>Hello World</p>
).trimHtml().toStr(); output
: Hello World |
| searchDeep
| Search case insensitive in string | JString('Hello World').searchDeep('w'); output
: true
|
| searchTokens
| Search tokens in string(case insensitive) | JString('Hello World').searchTokens(['w','h']); output
: true
|
| isSafe
| Check if the string isValid
and returns the string if it's valid otherwise empty string | JString(' ').isSafe(); output
: '' |
| removeLastChar
| Remove last character from string. This method comes with an optional parameter. If the optional parameter is provided, the function will remove that parameter only | var ex = JString('abc-com').removeLastChar().toStr(); output
: 'abc-co'ex.removeLastChar('o').toStr();output
: 'abc-c' |
| removeFirstChar
| Remove first char. Same functionality as removeLastChar
| - |
| removeSpecialChar
| Remove all the special or sensitive characters from string | JString('abc_de/f^g%h%i$j').removeSpecialChar().toStr();output
: 'abcdefghij' |
| replaceInfinity
| Replace all from string based on given parameter | JString('Dogge Doggo').replaceInfinity('g','').toStr();output
: 'Doe Doo' |
| rollback
| Rollback changes | JString('Dogge Doggo').replaceInfinity('g','').rollback(); |
| inCurrency
| Convert into currency format | JString('12345.67').inCurrency('$').toStr();output
: '$12,345.67' |
| isJson
| Check whether the string is JSON | JString('{"jstring":"JSON example"}').isJson();output
: true
|
| toJson
| Convert string to JSON. Return null
if not JSON | JString('{"jstring":"JSON example"}').toJson(); |
| isNumber
| Check if the string can be a number
| JString('101').isNumber();output
: true
|
| toNumber
| Convert string to number | JString('101').toNumber();output
: 101
|
| isPassword
| Check if the string is a number with an optional parameter of minimum number of characters | JString('abc'o').isPassword();output
:false
|
| isFormSafe
| Check if a string is valid for form or database | JString('ab#c').isFormSafe();output
:false
|
| isEmail
| Check if the string is an email | JString('abc.com').isEmail();output
:false
|
| isValid
| Check if the string is a valid string | JString('').isValid();output
:false
|
| instanceOfJString
| Return JString instance | - |
| instanceOfString
| Return String instance | - |
| firstUpperCase
| Convert first character to upper case | JString('aBC').firstUpperCase().toStr();output
:'ABC' |
| firstLowerCase
| Convert first character to lower case | JString('ABC').firstLowerCase().toStr();output
:'aBC' |
| lastUpperCase
| Convert last character to upper case | JString('abc').lastUpperCase().toStr();output
:'abC' |
| lastLowerCase
| Convert last character to lower case | JString('ABC').lastLowerCase().toStr();output
:'ABc' |
| isEqual
| Compare string case sensitive | JString('AC').isEqual('ac');output
:false
|
| isEqualDeep
| Compare string case insensitive | JString('AC').isEqualDeep('ac');output
:true
|
| toArray
| Convert string into array
of char | JString('ADC').toArray();output
:['A','D','C']
|
| walk
| Loop through string | JString('abcd').walk((char,index)=>{ }); |
| occurrenceOf
| Count number of occurance of char | JString('abcdcc').occurrenceOf('c');output
:3
|
TODO
- Allow schema for password validation
- Allow schema for form validation
- Compress & Decompress string
- ~~Allow tokenize search~~
Author
💻 🛠 Mohammad Julfikar Mahmud