API Docs for: 0.0.1
Show:

String Class

Module: lib/string.js
Parent Module: js-ext

Pollyfils for often used functionality for Strings Copyright (c) 2014 ITSA - https://github.com/itsa New BSD License - http://choosealicense.com/licenses/bsd-3-clause/

Methods

contains

(
  • substring
  • [caseInsensitive=false]
)
Boolean

Checks whether the substring is part if this String. Alias for (String.indexOf(substring) > -1)

Parameters:

  • substring String

    the substring to test for

  • [caseInsensitive=false] Boolean optional

    whether to ignore case-sensivity

Returns:

Boolean:

whether the substring is found

endsWith

(
  • test
  • [caseInsensitive=false]
)
Boolean

Checks if the string ends with the value specified by test

Parameters:

  • test String

    the string to test for

  • [caseInsensitive=false] Boolean optional

    whether to ignore case-sensivity

Returns:

Boolean:

whether the string ends with test

parsable

() Boolean

Checks if the string can be parsed into a number when using parseInt()

Returns:

Boolean:

whether the string is parsable

replace

(
  • search
  • replacement
  • [caseInsensitive=false]
)
String

Replaces search-characters by a replacement. Replaces only the firts occurence. Does not alter the String itself, but returns a new String with the replacement.

Parameters:

  • search String

    the character(s) to be replaced

  • replacement String

    the replacement

  • [caseInsensitive=false] Boolean optional

    whether to do search case-insensitive

Returns:

String:

new String with the replacement

replaceAll

(
  • search
  • replacement
  • [caseInsensitive=false]
)
String

Replaces search-characters by a replacement. Replaces all occurences. Does not alter the String itself, but returns a new String with the replacements.

Parameters:

  • search String

    the character(s) to be replaced

  • replacement String

    the replacement

  • [caseInsensitive=false] Boolean optional

    whether to do search case-insensitive

Returns:

String:

new String with the replacements

startsWith

(
  • test
  • [caseInsensitive=false]
)
Boolean

Checks if the string starts with the value specified by test

Parameters:

  • test String

    the string to test for

  • [caseInsensitive=false] Boolean optional

    whether to ignore case-sensivity

Returns:

Boolean:

whether the string starts with test

substitute

(
  • obj
)
String

Performs {placeholder} substitution on a string. The object passed provides values to replace the {placeholder}s. {placeholder} token names must match property names of the object.

{placeholder} tokens that are undefined on the object map will be removed.

Parameters:

  • obj Object

    Object containing replacement values.

Returns:

String:

the substitute result.

Example:

var greeting = '{message} {who}!'; greeting.substitute({message: 'Hello'}); // results into 'Hello !'

toDate

() Date | Null

Returns a ISO-8601 Date-object build by the String's value. If the String-value doesn't match ISO-8601, null will be returned.

ISO-8601 Date's are generated by JSON.stringify(), so it's very handy to be able to reconvert them.

Returns:

Date | Null:

the Date represented by the String's value or null when invalid

Example:

var birthday = '2010-02-10T14:45:30.000Z'; birthday.toDate(); // --> Wed Feb 10 2010 15:45:30 GMT+0100 (CET)

trim

() String

Generated the string without any white-spaces at the start or end.

Returns:

String:

new String without leading and trailing white-spaces

trimLeft

() String

Generated the string without any white-spaces at the beginning.

Returns:

String:

new String without leading white-spaces

trimRight

() String

Generated the string without any white-spaces at the end.

Returns:

String:

new String without trailing white-spaces

validateBoolean

() Boolean

Validates if the String's value represents a valid boolean.

Returns:

Boolean:

whether the String's value is a valid boolean.

validateDate

() Boolean

Validates if the String's value represents a valid Date.

Returns:

Boolean:

whether the String's value is a valid Date object.

validateEmail

() Boolean

Validates if the String's value represents a valid emailaddress.

Returns:

Boolean:

whether the String's value is a valid emailaddress.

validateFloat

(
  • [comma]
)
Boolean

Validates if the String's value represents a valid floated number.

Parameters:

  • [comma] Boolean optional

    whether to use a comma as decimal separator instead of a dot

Returns:

Boolean:

whether the String's value is a valid floated number.

validateHexaColor

(
  • [alpha=false]
)
Boolean

Validates if the String's value represents a hexadecimal color.

Parameters:

  • [alpha=false] Boolean optional

    whether to accept alpha transparancy

Returns:

Boolean:

whether the String's value is a valid hexadecimal color.

validateNumber

() Boolean

Validates if the String's value represents a valid integer number.

Returns:

Boolean:

whether the String's value is a valid integer number.

validateURL

(
  • [options]
)
Boolean

Validates if the String's value represents a valid URL.

Parameters:

  • [options] Object optional
    • [http] Boolean optional

      to force matching starting with http://

    • [https] Boolean optional

      to force matching starting with https://

Returns:

Boolean:

whether the String's value is a valid URL.