I'm looking for a js library like StringUtils of commons-lang in java, which contains a lot of common methods to operating strings.
Such as:
It'll be better if it contains some other methods for arrays/date, etc.
isEmpty() is a static method of the StringUtils class that is used to check if a given string is empty or not. If a string satisfies any of the criteria below, then the string is considered to be empty. The length of the string is zero. The string points to a null reference.
A string is a sequence of one or more characters that may consist of letters, numbers, or symbols. Strings in JavaScript are primitive data types and immutable, which means they are unchanging.
Use the length property to check if a string is empty, e.g. if (str. length === 0) {} . If the string's length is equal to 0 , then it's empty, otherwise it isn't empty. Copied!
isEmpty(String) , which checks if a string is an empty string or null. It also provides the StringUtils. isBlank(String) method, which also checks for whitespace.
Here we go:
IsEmpty
str.length === 0
IsBlank
str.trim().length === 0
Trim
str.trim()
Equals
str1 === str2
startsWith
str.indexOf( str2 ) === 0
IndexOf
str.indexOf( str2 )
LastIndexOf
str.lastIndexOf( str2 )
Contains
str.indexOf( str2 ) !== -1
Substring
str.substring( start, end )
Left
str.slice( 0, len )
Mid
str.substr( i, len )
Right
str.slice( -len, str.length )
And so on... (should I continue?)
String utils - Underscore.string
Object/array utils - Underscore
Date utils - Moment.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With