These methods test a string for various attributes in a string
- Source:
Requires
- module:ink/strings/shape
- module:ink/strings/patterns
- module:lodash
Methods
-
<static> contains(string, substring, fromIndex)
-
Returns true if string contains substring.
Parameters:
Name Type Argument Description string
String the string to search in
substring
String the string to search for
fromIndex
Number <optional>
optional index to start searching
- Source:
Returns:
true if str is contained in this string
-
<static> count(str, substr) → {Number}
-
Counts the instances of one string inside another
Parameters:
Name Type Description str
string The string to look in
substr
string The pattern to count
- Source:
Returns:
- Type
- Number
-
<static> endsWith(string, substring)
-
Returns true if string ends with the given substring
Parameters:
Name Type Description string
String the string to search in
substring
String pattern to search for
- Source:
Returns:
Boolean true in case it matches the end of the string, false otherwise
-
<static> getCommonPrefix(str1, str2) → {String}
-
Get the longest common segment that two strings have in common, starting at the beginning of the string
Parameters:
Name Type Description str1
String a string
str2
String another string
- Source:
Returns:
the longest common segment
- Type
- String
Example
strings.getCommonPrefix("Chocolate Fudge", "Choco Mocha") -> "Choco" strings.getCommonPrefix("Chocolate Fudge", "cocoa") -> ""
-
<static> isAlpha()
-
function returns true if the string contains only characters a-z
- Source:
Returns:
Boolean true in case string is alpha, false otherwise
-
<static> isAlphanumeric()
-
function returns true if the string contains only a-z and 0-9 (case insensitive!)
- Source:
Returns:
Boolean true in case string is alpha, false otherwise
-
<static> isDateFormat(string) → {Boolean}
-
checks if a date format pattern is correct
Parameters:
Name Type Description string
String the string to check
- Source:
Returns:
true if the pattern is correct
- Type
- Boolean
Example
var strings = require("ink-strings"); strings.isDateFormat("waka waka") -> false strings.isDateFormat("01/01/2013") -> true
-
<static> isEmail(string)
-
returns true if the string looks like an e-mail
Parameters:
Name Type Description string
String - Source:
-
<static> isHexColor(string) → {Boolean}
-
function checks a string for a valid color value in hexadecimal format. it may also contain # as first character
Parameters:
Name Type Description string
String the string to check
- Source:
Returns:
false, if string length (without #) > 6 or < 6 or contains any character which is not a valid hex value
- Type
- Boolean
Example
var strings = require("ink-strings"); strings.isHexColor("fred is a great guy"); -> false strings.isHexColor("#FF0000"); -> true strings.isHexColor("ABCDEF"); -> true strings.isHexColor("ABCDEF00"); -> false
-
<static> isNumeric()
-
function returns true if the string contains only 0-9
- Source:
Returns:
Boolean true in case string is numeric, false otherwise
-
<static> isUrl(string) → {Boolean}
-
function checks if the string passed contains any characters that are forbidden in URLs and tries to create a java.net.URL from it
Parameters:
Name Type Description string
String the string to check
- Source:
Returns:
- Type
- Boolean
Example
var strings = require("ink-strings"); strings.isUrl("waka waka") -> false strings.isUrl("http://home.com/terry") -> true strings.isUrl("ftp://home.com/terry") -> true strings.isUrl("file://home.com/terry") -> false // this is arguably wrong, but this is what you should expect from this method
-
<static> levenshtein(str1, str2) → {number}
-
Calculates Levenshtein distance between two strings.
Parameters:
Name Type Description str1
string The first string to look at
str2
string The second string to look at
Returns:
- Type
- number
-
<static> startsWith(string, substring) → {Boolean}
-
Returns true if string starts with the given substring
Parameters:
Name Type Description string
String the string to search in
substring
String pattern to search for
- Source:
Returns:
true in case it matches the beginning of the string, false otherwise
- Type
- Boolean
-
<static> strLeft(str, sep) → {string}
-
Searches a string from left to right for a pattern and returns a substring consisting of the characters in the string that are to the left of the pattern or all string if no match found.
Parameters:
Name Type Description str
string sep
string The pattern to look for
- Source:
Returns:
- Type
- string
-
<static> strLeftBack(str, sep) → {string}
-
Searches a string from right to left for a pattern and returns a substring consisting of the characters in the string that are to the left of the pattern or all string if no match found.
Parameters:
Name Type Description str
string sep
string The pattern to look for
- Source:
Returns:
- Type
- string
-
<static> strRight(str, sep) → {string}
-
Searches a string from left to right for a pattern and returns a substring consisting of the characters in the string that are to the right of the pattern or all string if no match found.
Parameters:
Name Type Description str
string sep
string The pattern to look for
- Source:
Returns:
- Type
- string
-
<static> strRightBack(str, sep) → {string}
-
Searches a string from right to left for a pattern and returns a substring consisting of the characters in the string that are to the right of the pattern or all string if no match found.
Parameters:
Name Type Description str
string sep
string The pattern to look for
- Source:
Returns:
- Type
- string