Module: ink/strings/shape

ink/strings/shape

These methods shape a string into the form you want it

Author:
  • Terry Weiss
  • zumbrunn
  • Esa-Matti Suurone
  • Pavel Pravosud
Source:

Requires

Methods

<static> camelize(string) → {String}

Transforms string from space, dash, or underscore notation to camel-case.

Parameters:
Name Type Description
string String

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
str string

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
str string

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
str string

The string to check

step integer

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
str string

The string to convert

Source:
Returns:
Type
string

<static> clean(str) → {string}

Compress consecutive whitespaces to one.

Parameters:
Name Type Description
str string

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
str string

The string to convert

Source:
Returns:
Type
string

<static> escapeRegExp(str) → {string}

Prefixes RegEx special characters with a backslash ().

Parameters:
Name Type Description
str string

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
format string

The format string

The object <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
string String
interval Number

number of characters after which insertion should take place

string String

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
str string

The string to convert

Source:
Returns:
Type
string

<static> insert(str, i, substr) → {string}

Insert one string into another

Parameters:
Name Type Description
str string

The string that receive the insert

i integer

Where to insert the string

substr string

The string to insert

Source:
Returns:
Type
string

<static> join(str) → {string}

Joins strings together with given separator

Parameters:
Name Type Argument Description
str string <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
str string

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
str string

The string to pad

length integer

The length to pad out

padStr string <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
str string

The string to pad

length integer

The length to pad out

padStr string <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
str string

The string to trim

characters string <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
str string

The string to pad

length integer

The length to pad out

padStr string <optional>

The string to pad with

type string <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
str string

The string to truncate

length integer

The length of the truncated string

pruneStr string <optional>

The trailer

Author:
  • Pavel Pravosud
Source:
See:
Returns:
Type
string

<static> quote(str) → {string}

Quotes a string.

Parameters:
Name Type Description
str string

The string to quote

Source:
Returns:
Type
string

<static> reverse(str) → {string}

Return reversed strings

Parameters:
Name Type Description
str string

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
str string

The string to pad

length integer

The length to pad out

padStr string <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
str string

The string to trim

characters string <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
str string

The string to slugify

Source:
Returns:
Type
string

<static> splice(str, i, howmany, substr) → {string}

Splices one string into another.

Parameters:
Name Type Description
str string

The string to work with

i integer

The index to start splicing the new string into

howmany integer

How many characters to replace

substr string

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
str char

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
str string

The string to surround

wrapper string

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
str string

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
str string

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
string String

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
str string

The string to parse

decimals integer <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
array array

The array to join

separator string <optional>

The separator to use, defaults to ","

lastSeparator string <optional>

The last seperator to use, defaults to "and"

serial boolean <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
array array

The array to join

separator string <optional>

The separator to use, defaults to ","

lastSeparator string <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
str string

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
str string

The string to truncate

length integer

The length of the truncated string

truncateStr string <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
str string

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
flag String

indicating if html tags should be replaced

removeTags Boolean <optional>

When true, <br/> and \n \r are all removed

replacement string <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
str string

The string to split

delimiter string <optional>

An optional delimiter to use

Source:
Returns:
Type
array.<string>
See NOTICE.md for licenses
ink-strings Copyright contributers to ink-strings, base64, Helma, RingoJS, sprintf projects.
Documentation generated by JSDoc 3.2.0-dev on Sun Jun 09 2013 11:56:08 GMT-0400 (EDT) using the DocStrap template.