ALKMaps custom string, number and function functions are described here.
ALKMaps Base Types | ALKMaps custom string, number and function functions are described here. |
ALKMaps. | Contains convenience functions for string manipulation. |
Functions and Properties | |
startsWith | Test whether a string starts with another string. |
contains | Test whether a string contains another string. |
trim | Removes leading and trailing whitespace characters from a string. |
camelize | Camel-case a hyphenated string. |
format | Given a string with tokens in the form ${token}, return a string with tokens replaced with properties from the given context object. |
tokenRegEx | Used to find tokens in a string. |
numberRegEx | Used to test strings as numbers. |
isNumeric | Determine whether a string contains only a numeric value. |
numericIf | Converts a string that appears to be a numeric value into a number. |
ALKMaps. | Contains convenience functions for manipulating numbers. |
Properties | |
decimalSeparator | Decimal separator to use when formatting numbers. |
thousandsSeparator | Thousands separator to use when formatting numbers. |
Functions | |
limitSigDigs | Limit the number of significant digits on a float. |
format | Formats a number for output. |
ALKMaps. | Contains convenience functions for function manipulation. |
Functions | |
bind | Bind a function to an object. |
bindAsEventListener | Bind a function to an object, and configure it to receive the event object as first parameter when called. |
False | A simple function to that just does “return false”. |
True | A simple function to that just does “return true”. |
Void | A reusable function that returns ``undefined``. |
ALKMaps. | Contains convenience functions for array manipulation. |
Functions | |
filter | Filter an array. |
Contains convenience functions for string manipulation.
Functions and Properties | |
startsWith | Test whether a string starts with another string. |
contains | Test whether a string contains another string. |
trim | Removes leading and trailing whitespace characters from a string. |
camelize | Camel-case a hyphenated string. |
format | Given a string with tokens in the form ${token}, return a string with tokens replaced with properties from the given context object. |
tokenRegEx | Used to find tokens in a string. |
numberRegEx | Used to test strings as numbers. |
isNumeric | Determine whether a string contains only a numeric value. |
numericIf | Converts a string that appears to be a numeric value into a number. |
format: function( template, context, args )
Given a string with tokens in the form ${token}, return a string with tokens replaced with properties from the given context object. Represent a literal “${“ by doubling it, e.g. “${${“.
template | {String} A string with tokens to be replaced. A template has the form “literal ${token}” where the token will be replaced by the value of context[“token”]. |
context | {Object} An optional object with properties corresponding to the tokens in the format string. If no context is sent, the window object will be used. |
args | {Array} Optional arguments to pass to any functions found in the context. If a context property is a function, the token will be replaced by the return from the function called with these arguments. |
{String} A string with tokens replaced from the context object.
isNumeric: function( value )
Determine whether a string contains only a numeric value.
ALKMaps.String.isNumeric("6.02e23") // true ALKMaps.String.isNumeric("12 dozen") // false ALKMaps.String.isNumeric("4") // true ALKMaps.String.isNumeric(" 4 ") // false
{Boolean} String contains only a number.
Contains convenience functions for manipulating numbers.
Properties | |
decimalSeparator | Decimal separator to use when formatting numbers. |
thousandsSeparator | Thousands separator to use when formatting numbers. |
Functions | |
limitSigDigs | Limit the number of significant digits on a float. |
format | Formats a number for output. |
format: function( num, dec, tsep, dsep )
Formats a number for output.
num | {Float} |
dec | {Integer} Number of decimal places to round to. Defaults to 0. Set to null to leave decimal places unchanged. |
tsep | {String} Thousands separator. Default is “,”. |
dsep | {String} Decimal separator. Default is “.”. |
{String} A string representing the formatted number.
Contains convenience functions for function manipulation.
Functions | |
bind | Bind a function to an object. |
bindAsEventListener | Bind a function to an object, and configure it to receive the event object as first parameter when called. |
False | A simple function to that just does “return false”. |
True | A simple function to that just does “return true”. |
Void | A reusable function that returns ``undefined``. |
filter: function( array, callback, caller )
Filter an array. Provides the functionality of the Array.prototype.filter extension to the ECMA-262 standard. Where available, Array.prototype.filter will be used.
Based on well known example from https://developer.mozilla.org
array | {Array} The array to be filtered. This array is not mutated. Elements added to this array by the callback will not be visited. |
callback | {Function} A function that is called for each element in the array. If this function returns true, the element will be included in the return. The function will be called with three arguments: the element in the array, the index of that element, and the array itself. If the optional caller parameter is specified the callback will be called with this set to caller. |
caller | {Object} Optional object to be set as this when the callback is called. |
{Array} An array of elements from the passed in array for which the callback returns true.
Test whether a string starts with another string.
startsWith: function( str, sub )
Test whether a string contains another string.
contains: function( str, sub )
Removes leading and trailing whitespace characters from a string.
trim: function( str )
Camel-case a hyphenated string.
camelize: function( str )
Given a string with tokens in the form ${token}, return a string with tokens replaced with properties from the given context object.
format: function( template, context, args )
Determine whether a string contains only a numeric value.
isNumeric: function( value )
Converts a string that appears to be a numeric value into a number.
numericIf: function( value )
Limit the number of significant digits on a float.
limitSigDigs: function( num, sig )
Formats a number for output.
format: function( num, dec, tsep, dsep )
Bind a function to an object.
bind: function( func, object )
Bind a function to an object, and configure it to receive the event object as first parameter when called.
bindAsEventListener: function( func, object )
A simple function to that just does “return false”.
False : function()
A simple function to that just does “return true”.
True : function()
A reusable function that returns ``undefined``.
Void: function()
Filter an array.
filter: function( array, callback, caller )