These methods shape a string into the form you want it
- Source:
Requires
- module:ink/strings/patterns
- module:lodash
Methods
-
<static> camelize(string) → {String}
-
Transforms string from space, dash, or underscore notation to camel-case.
Parameters:
Name Type Description stringString a string
- Source:
Returns:
the resulting string
- Type
- String
Example
strings.camelize( "the_doctor" ); -> "theDoctor" -
<static> capitalize(str) → {string}
-
Converts first letter of the string to uppercase.
Parameters:
Name Type Description strstring The string to check
- Source:
Returns:
- Type
- string
-
<static> chars(str) → {array.<string>}
-
Returns an array of the characters in the string
Parameters:
Name Type Description strstring The string to split up
- Source:
Returns:
- Type
- array.<string>
-
<static> chop(str, step) → {array.<string>}
-
Chops a string into chunks that are <code>steps</code> wide.
Parameters:
Name Type Description strstring The string to check
stepinteger The chunk to use when chopping the string up
- Source:
Returns:
- Type
- array.<string>
-
<static> classify(str) → {string}
-
Converts string to camelized class name
Parameters:
Name Type Description strstring The string to convert
- Source:
Returns:
- Type
- string
-
<static> clean(str) → {string}
-
Compress consecutive whitespaces to one.
Parameters:
Name Type Description strstring The string to check
- Source:
Returns:
- Type
- string
-
<static> dasherize(str) → {string}
-
Converts a underscored or camelized string into an dasherized one
Parameters:
Name Type Description strstring The string to convert
- Source:
Returns:
- Type
- string
-
<static> escapeRegExp(str) → {string}
-
Prefixes RegEx special characters with a backslash ().
Parameters:
Name Type Description strstring The string to work with
- Source:
Returns:
- Type
- string
-
<static> format(format, The) → {string}
-
Formats a string with {} placeholders like .net's format method. This is a very simple and fast replacement and not an interpolation. It is only appropriate for values and not object unless they format well with
toString().Parameters:
Name Type Argument Description formatstring The format string
Theobject <repeatable>
contents to replace
- Source:
Returns:
- Type
- string
Example
var res = strings.format( "Well, this is {0} how do yo do!", "fine" ); -> "Well, this is fine how do yo do!" -
<static> group(string, interval, string)
-
function inserts a string every number of characters
Parameters:
Name Type Description stringString intervalNumber number of characters after which insertion should take place
stringString to be inserted
- Source:
Returns:
String resulting string
Example
strings.group( "Madame Vastra wears a veil", 3, ":)" ) -> "Mad:)ame:) Va:)str:)a w:)ear:)s a:) ve:)il:)" -
<static> humanize(str) → {string}
-
Converts an underscored, camelized, or dasherized string into a humanized one. Also removes beginning and ending whitespace, and removes the postfix '_id'.
Parameters:
Name Type Description strstring The string to convert
- Source:
Returns:
- Type
- string
-
<static> insert(str, i, substr) → {string}
-
Insert one string into another
Parameters:
Name Type Description strstring The string that receive the insert
iinteger Where to insert the string
substrstring The string to insert
- Source:
Returns:
- Type
- string
-
<static> join(str) → {string}
-
Joins strings together with given separator
Parameters:
Name Type Argument Description strstring <repeatable>
The strings you want to join.
- Source:
Returns:
- Type
- string
-
<static> lines(str) → {array.<string>}
-
Splits a string with <code>\n</code> new line markers into one string per line as an array.
Parameters:
Name Type Description strstring The string to split
- Source:
Returns:
- Type
- array.<string>
-
<static> lpad(str, length, padStr) → {string}
-
left-pad a string. Alias for pad(str, length, padStr, 'left').
Parameters:
Name Type Argument Description strstring The string to pad
lengthinteger The length to pad out
padStrstring <optional>
The string to pad with
- Source:
Returns:
- Type
- string
-
<static> lrpad(str, length, padStr) → {string}
-
left/right-pad a string. Alias for pad(str, length, padStr, 'both')
Parameters:
Name Type Argument Description strstring The string to pad
lengthinteger The length to pad out
padStrstring <optional>
The string to pad with
- Source:
Returns:
- Type
- string
-
<static> ltrim(str, characters) → {string}
-
Left trim. Similar to trim, but only for left side.
Parameters:
Name Type Argument Description strstring The string to trim
charactersstring <optional>
The characters to replace
- Source:
Returns:
- Type
- string
-
<static> pad(str, length, padStr, type) → {string}
-
Pads the striong with characters until the total string length is equal to the passed length parameter. By default, pads on the left with the space char (" "). padStr is truncated to a single character if necessary
Parameters:
Name Type Argument Description strstring The string to pad
lengthinteger The length to pad out
padStrstring <optional>
The string to pad with
typestring <optional>
How to pad the string, choices are "right", "left", "both"
- Source:
Returns:
- Type
- string
-
<static> prune(str, length, pruneStr) → {string}
-
A more elegant version of truncate prune extra chars, never leaving a half-chopped word.
Parameters:
Name Type Argument Description strstring The string to truncate
lengthinteger The length of the truncated string
pruneStrstring <optional>
The trailer
- Source:
- See:
Returns:
- Type
- string
-
<static> quote(str) → {string}
-
Quotes a string.
Parameters:
Name Type Description strstring The string to quote
- Source:
Returns:
- Type
- string
-
<static> reverse(str) → {string}
-
Return reversed strings
Parameters:
Name Type Description strstring The string to reverse
- Source:
Returns:
- Type
- string
-
<static> rpad(str, length, padStr) → {string}
-
right-pad a string. Alias for pad(str, length, padStr, 'right')
Parameters:
Name Type Argument Description strstring The string to pad
lengthinteger The length to pad out
padStrstring <optional>
The string to pad with
- Source:
Returns:
- Type
- string
-
<static> rtrim(str, characters) → {string}
-
Right trim. Similar to trim, but only for right side.
Parameters:
Name Type Argument Description strstring The string to trim
charactersstring <optional>
The characters to replace
- Source:
Returns:
- Type
- string
-
<static> slugify(str) → {string}
-
Transform text into a URL slug. Replaces whitespaces, accentuated, and special characters with a dash.
Parameters:
Name Type Description strstring The string to slugify
- Source:
Returns:
- Type
- string
-
<static> splice(str, i, howmany, substr) → {string}
-
Splices one string into another.
Parameters:
Name Type Description strstring The string to work with
iinteger The index to start splicing the new string into
howmanyinteger How many characters to replace
substrstring The string to splice in
- Source:
Returns:
- Type
- string
-
<static> succ(str) → {char}
-
Returns the next alphabetic letter. When you get to Z, you get the next char in the table (set by the OS or the browser), so be careful to limit yourself to alphas only.
Parameters:
Name Type Description strchar The character to get the next letter for
- Source:
Returns:
- Type
- char
-
<static> surround(str, wrapper) → {string}
-
Surround a string with another string.
Parameters:
Name Type Description strstring The string to surround
wrapperstring The string to wrap it with
- Source:
Returns:
- Type
- string
-
<static> swapCase(str) → {string}
-
Returns a copy of the string in which all the case-based characters have had their case swapped.
Parameters:
Name Type Description strstring The string to work with
- Source:
Returns:
- Type
- string
-
<static> titleize(str) → {string}
-
Returns the string with each first letter capitalized
Parameters:
Name Type Description strstring The string to capitalize
- Source:
Returns:
- Type
- string
-
<static> toAlphanumeric()
-
function cleans a string by throwing away all non-alphanumeric characters
- Source:
Returns:
cleaned string
-
<static> toHexColor(string) → {String}
-
converts a string into a hexadecimal color representation (e.g. "ffcc33") from a color string like "rgb (255, 204, 51)".
Parameters:
Name Type Description stringString the string to convert
- Source:
Returns:
the resulting hex color (w/o "#")
- Type
- String
Example
var strings = require("ink-strings"); strings.toHexColor("rgb(255, 0, 0)"); -> "ff0000" -
<static> toNumber(str, decimals) → {number}
-
Parse string to number. Returns NaN if string can't be parsed to number.
Parameters:
Name Type Argument Description strstring The string to parse
decimalsinteger <optional>
The number of decimals to return
- Source:
Returns:
- Type
- number
-
<static> toSentence(array, separator, lastSeparator, serial) → {string}
-
Join an array into a human readable sentence.
Parameters:
Name Type Argument Description arrayarray The array to join
separatorstring <optional>
The separator to use, defaults to ","
lastSeparatorstring <optional>
The last seperator to use, defaults to "and"
serialboolean <optional>
Serial commas? defaults to <code>false</code>
- Source:
Returns:
- Type
- string
-
<static> toSentenceSerial(array, separator, lastSeparator) → {string}
-
The same as toSentence, but adjusts delimeters to use Serial comma.
Parameters:
Name Type Argument Description arrayarray The array to join
separatorstring <optional>
The separator to use, defaults to ","
lastSeparatorstring <optional>
The last seperator to use, defaults to "and"
- Source:
Returns:
- Type
- string
-
<static> trim(str) → {string}
-
Trims defined characters from begining and ending of the string. Defaults to whitespace characters.
Parameters:
Name Type Description strstring The string to trim
- Source:
Returns:
- Type
- string
-
<static> truncate(str, length, truncateStr) → {string}
-
Truncates a string to a fixed length and you can optionally specify what you want the trailer to be, defaults to "..."
Parameters:
Name Type Argument Description strstring The string to truncate
lengthinteger The length of the truncated string
truncateStrstring <optional>
The trailer
- Source:
Returns:
- Type
- string
-
<static> underscored(str) → {string}
-
Converts a camelized or dasherized string into an underscored one
Parameters:
Name Type Description strstring The string to convert
- Source:
Returns:
- Type
- string
-
<static> unwrap(flag, removeTags, replacement) → {string}
-
replace all linebreaks and optionally all br tags
Parameters:
Name Type Argument Description flagString indicating if html tags should be replaced
removeTagsBoolean <optional>
When true, <br/> and \n \r are all removed
replacementstring <optional>
for the linebreaks / html tags
- Source:
Returns:
the unwrapped string
- Type
- string
Example
strings.unwrap( "The Doctor
has a cool\n bowtie" ); -> "The Doctor
has a cool bowtie" strings.unwrap( "The Doctor
has a cool\n bowtie", true ); ->"The Doctor has a cool bowtie" -
<static> words(str, delimiter) → {array.<string>}
-
Split string by delimiter (String or RegExp), /\s+/ by default.
Parameters:
Name Type Argument Description strstring The string to split
delimiterstring <optional>
An optional delimiter to use
- Source:
Returns:
- Type
- array.<string>