Packageweavejs.util
Classpublic class StandardLib
InheritanceStandardLib Inheritance Object



Public Properties
 PropertyDefined By
  lodash : Object
[static] This must be set externally.
StandardLib
  ol : Object
[static]
StandardLib
Public Methods
 MethodDefined By
  
arrayIsType(a:Array, type:Class):Boolean
[static] Checks if all items in an Array are instances of a given type.
StandardLib
  
asBoolean(value:*):Boolean
[static] This function attempts to derive a boolean value from different types of objects.
StandardLib
  
asNumber(value:*):Number
[static] This function will cast a value of any type to a Number, interpreting the empty string ("") and null as NaN.
StandardLib
  
asString(value:*):String
[static] Converts a value to a non-null String
StandardLib
  
byteArrayToString(byteArray:Array):String
[static] Converts a Uint8Array to a binary String
StandardLib
  
compare(a:Object, b:Object, objectCompare:Function = null):int
[static] This compares two dynamic objects or primitive values and is much faster than ObjectUtil.compare().
StandardLib
  
constrain(value:Number, min:Number, max:Number):Number
[static] This function constrains a number between min and max values.
StandardLib
  
dateCompare(a:Date, b:Date):int
[static]
StandardLib
  
formatDate(value:Object, formatString:String = null, formatAsUniversalTime:Boolean = true):String
[static] This will generate a date string from a Number or a Date object using the specified date format.
StandardLib
  
formatNumber(number:Number, precision:int = -1):String
[static]
StandardLib
  
getArrayType(a:Array):Class
[static] This will return the type of item found in the Array if each item has the same type.
StandardLib
  
getColorLuma(color:Number):Number
[static] ITU-R 601
StandardLib
  
getHexColor(color:Number):String
[static]
StandardLib
  
getNiceNumber(x:Number, round:Boolean):Number
[static] Code from Graphics Gems Volume 1
StandardLib
  
getNiceNumbersInRange(min:Number, max:Number, numberOfValuesInRange:int):Array
[static] Code from Graphics Gems Volume 1 Note: This may return less than the requested number of values
StandardLib
  
guid():String
[static]
StandardLib
  
interpolateColor(normValue:Number, ... colors):Number
[static] Calculates an interpolated color for a normalized value.
StandardLib
  
isDefined(value:*):Boolean
[static] Tests if a value is anything other than undefined, null, or NaN.
StandardLib
  
isUndefined(value:*, orEmptyString:Boolean = false):Boolean
[static] Tests if a value is undefined, null, or NaN.
StandardLib
  
isWhitespace(character:String):Boolean
[static]
StandardLib
  
logTransform(normValue:Number, factor:Number = 1024):Number
[static] This will perform a log transformation on a normalized value to produce another normalized value.
StandardLib
  
lpad(str:String, length:uint, padString:String = ):String
[static] Pads a string on the left.
StandardLib
  
mean(... args):Number
[static] Calculates the mean value from a list of Numbers.
StandardLib
  
normalize(value:Number, min:Number, max:Number):Number
[static] Scales a number between 0 and 1 using specified min and max values.
StandardLib
  
numberToBase(number:Number, base:int = 10, zeroPad:int = 1):String
[static] Converts a number to a String using a specific numeric base and optionally pads with leading zeros.
StandardLib
  
numericCompare(a:Number, b:Number):int
[static]
StandardLib
  
replace(string:String, findStr:String, replaceStr:String, ... moreFindAndReplace):String
[static] This function performs find and replace operations on a String.
StandardLib
  
roundPrecision(number:Number, precision:Number):Number
[static] Rounds a number to the nearest multiple of a precision value.
StandardLib
  
roundSignificant(value:Number, significantDigits:uint = 14):Number
[static] This rounds a Number to a given number of significant digits.
StandardLib
  
rpad(str:String, length:uint, padString:String = ):String
[static] Pads a string on the right.
StandardLib
  
scale(inputValue:Number, inputMin:Number, inputMax:Number, outputMin:Number, outputMax:Number):Number
[static] This function performs a linear scaling of a value from an input min,max range to an output min,max range.
StandardLib
  
sign(value:Number):Number
[static] This function returns -1 if the given value is negative, and 1 otherwise.
StandardLib
  
sortOn(array:*, params:*, sortDirections:*, inPlace:Boolean = true, returnSortedIndexArray:Boolean = false):*
[static] Sorts an Array of items in place using properties, lookup tables, or replacer functions.
StandardLib
  
stringCompare(a:String, b:String, caseInsensitive:Boolean = false):int
[static]
StandardLib
  
substitute(format:String, ... args):String
[static] Substitutes "{n}" tokens within the specified string with the respective arguments passed in.
StandardLib
  
suggestPrecision(n:Number, d:int):Number
[static]
StandardLib
  
sum(... args):Number
[static] Calculates the sum of a list of Numbers.
StandardLib
  
trim(str:String):String
[static]
StandardLib
  
ucs2encode(value:uint):String
[static]
StandardLib
  
unIndent(script:String, spacesPerTab:int = -1):String
[static] Takes a script where all lines have been indented with tabs, removes the common indentation from all lines and optionally replaces extra leading tabs with a number of spaces.
StandardLib
Property Detail
lodashproperty
public static var lodash:Object

This must be set externally.

olproperty 
public static var ol:Object

Method Detail
arrayIsType()method
public static function arrayIsType(a:Array, type:Class):Boolean

Checks if all items in an Array are instances of a given type.

Parameters

a:Array — An Array of items to test
 
type:Class — A type to check for

Returns
Boolean — true if each item in the Array is an object of the given type.
asBoolean()method 
public static function asBoolean(value:*):Boolean

This function attempts to derive a boolean value from different types of objects.

Parameters

value:* — An object to parse as a Boolean.

Returns
Boolean
asNumber()method 
public static function asNumber(value:*):Number

This function will cast a value of any type to a Number, interpreting the empty string ("") and null as NaN.

Parameters

value:* — A value to cast to a Number.

Returns
Number — The value cast to a Number, or NaN if the casting failed.
asString()method 
public static function asString(value:*):String

Converts a value to a non-null String

Parameters

value:* — A value to cast to a String.

Returns
String — The value cast to a String.
byteArrayToString()method 
public static function byteArrayToString(byteArray:Array):String

Converts a Uint8Array to a binary String

Parameters

byteArray:Array

Returns
String
compare()method 
public static function compare(a:Object, b:Object, objectCompare:Function = null):int

This compares two dynamic objects or primitive values and is much faster than ObjectUtil.compare(). Does not check for circular refrences.

Parameters

a:Object — First dynamic object or primitive value.
 
b:Object — Second dynamic object or primitive value.
 
objectCompare:Function (default = null) — An optional compare function to replace the default compare behavior for non-primitive Objects. The function should return -1, 0, or 1 to override the comparison result, or NaN to use the default recursive comparison result.

Returns
int — A value of zero if the two objects are equal, nonzero if not equal.
constrain()method 
public static function constrain(value:Number, min:Number, max:Number):Number

This function constrains a number between min and max values.

Parameters

value:Number — A value to constrain between a min and max.
 
min:Number — The minimum value.
 
max:Number — The maximum value.

Returns
Number — If value < min, returns min. If value > max, returns max. Otherwise, returns value.
dateCompare()method 
public static function dateCompare(a:Date, b:Date):int

Parameters

a:Date
 
b:Date

Returns
int

See also

mx.utils.ObjectUtil.dateCompare()
formatDate()method 
public static function formatDate(value:Object, formatString:String = null, formatAsUniversalTime:Boolean = true):String

This will generate a date string from a Number or a Date object using the specified date format.

Parameters

value:Object — The Date object or date string to format.
 
formatString:String (default = null) — The format of the date string to be generated.
 
formatAsUniversalTime:Boolean (default = true) — If set to true, the date string will be generated using universal time. If set to false, the timezone of the user's computer will be used.

Returns
String — The resulting formatted date string.

See also

mx.formatters::DateFormatter.formatString
Date
formatNumber()method 
public static function formatNumber(number:Number, precision:int = -1):String

Parameters

number:Number
 
precision:int (default = -1)

Returns
String
getArrayType()method 
public static function getArrayType(a:Array):Class

This will return the type of item found in the Array if each item has the same type.

Parameters

a:Array — An Array to check.

Returns
Class — The type of all items in the Array, or null if the types differ.
getColorLuma()method 
public static function getColorLuma(color:Number):Number

ITU-R 601

Parameters

color:Number

Returns
Number
getHexColor()method 
public static function getHexColor(color:Number):String

Parameters

color:Number — A numeric color value

Returns
String — A hex color string like #FFFFFF
getNiceNumber()method 
public static function getNiceNumber(x:Number, round:Boolean):Number

Code from Graphics Gems Volume 1

Parameters

x:Number
 
round:Boolean

Returns
Number
getNiceNumbersInRange()method 
public static function getNiceNumbersInRange(min:Number, max:Number, numberOfValuesInRange:int):Array

Code from Graphics Gems Volume 1 Note: This may return less than the requested number of values

Parameters

min:Number
 
max:Number
 
numberOfValuesInRange:int

Returns
Array
guid()method 
public static function guid():String

Returns
String
interpolateColor()method 
public static function interpolateColor(normValue:Number, ... colors):Number

Calculates an interpolated color for a normalized value.

Parameters

normValue:Number — A Number between 0 and 1.
 
... colors — An Array or list of colors to interpolate between. Normalized values of 0 and 1 will be mapped to the first and last colors.

Returns
Number — An interpolated color associated with the given normValue based on the list of color values.
isDefined()method 
public static function isDefined(value:*):Boolean

Tests if a value is anything other than undefined, null, or NaN.

Parameters

value:*

Returns
Boolean
isUndefined()method 
public static function isUndefined(value:*, orEmptyString:Boolean = false):Boolean

Tests if a value is undefined, null, or NaN.

Parameters

value:*
 
orEmptyString:Boolean (default = false)

Returns
Boolean
isWhitespace()method 
public static function isWhitespace(character:String):Boolean

Parameters

character:String

Returns
Boolean

See also

mx.utils.StringUtil.isWhitespace()
logTransform()method 
public static function logTransform(normValue:Number, factor:Number = 1024):Number

This will perform a log transformation on a normalized value to produce another normalized value.

Parameters

normValue:Number — A number between 0 and 1.
 
factor:Number (default = 1024) — The log factor to use.

Returns
Number — A number between 0 and 1.
lpad()method 
public static function lpad(str:String, length:uint, padString:String = ):String

Pads a string on the left.

Parameters

str:String
 
length:uint
 
padString:String (default = )

Returns
String
mean()method 
public static function mean(... args):Number

Calculates the mean value from a list of Numbers.

Parameters

... args

Returns
Number
normalize()method 
public static function normalize(value:Number, min:Number, max:Number):Number

Scales a number between 0 and 1 using specified min and max values.

Parameters

value:Number — The value between min and max.
 
min:Number — The minimum value that corresponds to a result of 0.
 
max:Number — The maximum value that corresponds to a result of 1.

Returns
Number — The normalized value between 0 and 1, or NaN if value is out of range.
numberToBase()method 
public static function numberToBase(number:Number, base:int = 10, zeroPad:int = 1):String

Converts a number to a String using a specific numeric base and optionally pads with leading zeros.

Parameters

number:Number — The Number to convert to a String.
 
base:int (default = 10) — Specifies the numeric base (from 2 to 36) to use.
 
zeroPad:int (default = 1) — This is the minimum number of digits to return. The number will be padded with zeros if necessary.

Returns
String — The String representation of the number using the specified numeric base.
numericCompare()method 
public static function numericCompare(a:Number, b:Number):int

Parameters

a:Number
 
b:Number

Returns
int

See also

mx.utils.ObjectUtil.numericCompare()
replace()method 
public static function replace(string:String, findStr:String, replaceStr:String, ... moreFindAndReplace):String

This function performs find and replace operations on a String.

Parameters

string:String — A String to perform replacements on.
 
findStr:String — A String to find.
 
replaceStr:String — A String to replace occurrances of the 'findStr' String with.
 
... moreFindAndReplace — A list of additional find,replace parameters to use.

Returns
String — The String with all the specified replacements performed.
roundPrecision()method 
public static function roundPrecision(number:Number, precision:Number):Number

Rounds a number to the nearest multiple of a precision value.

Parameters

number:Number — A number to round.
 
precision:Number — A precision to use.

Returns
Number — The number rounded to the nearest multiple of the precision value.
roundSignificant()method 
public static function roundSignificant(value:Number, significantDigits:uint = 14):Number

This rounds a Number to a given number of significant digits.

Parameters

value:Number — A value to round.
 
significantDigits:uint (default = 14) — The desired number of significant digits in the result.

Returns
Number — The number, rounded to the specified number of significant digits.
rpad()method 
public static function rpad(str:String, length:uint, padString:String = ):String

Pads a string on the right.

Parameters

str:String
 
length:uint
 
padString:String (default = )

Returns
String
scale()method 
public static function scale(inputValue:Number, inputMin:Number, inputMax:Number, outputMin:Number, outputMax:Number):Number

This function performs a linear scaling of a value from an input min,max range to an output min,max range.

Parameters

inputValue:Number — A value to scale.
 
inputMin:Number — The minimum value in the input range.
 
inputMax:Number — The maximum value in the input range.
 
outputMin:Number — The minimum value in the output range.
 
outputMax:Number — The maximum value in the output range.

Returns
Number — The input value rescaled such that a value equal to inputMin is scaled to outputMin and a value equal to inputMax is scaled to outputMax.
sign()method 
public static function sign(value:Number):Number

This function returns -1 if the given value is negative, and 1 otherwise.

Parameters

value:Number — A value to test.

Returns
Number — -1 if value < 0, 1 otherwise
sortOn()method 
public static function sortOn(array:*, params:*, sortDirections:*, inPlace:Boolean = true, returnSortedIndexArray:Boolean = false):*

Sorts an Array of items in place using properties, lookup tables, or replacer functions.

Parameters

array:* — An Array to sort.
 
params:* — Specifies how to get values used to sort items in the array. This can either be an Array of params or a single param, each of which can be one of the following: Array: values are looked up based on index (Such an Array must be nested in a params array rather than given alone as a single param) Object or Dictionary: values are looked up using items in the array as keys Property name: values are taken from items in the array using a property name Replacer function: array items are passed through this function to get values
 
sortDirections:* (default = NaN) — Specifies sort direction(s) (1 or -1) corresponding to the params.
 
inPlace:Boolean (default = true) — Set this to true to modify the original Array in place or false to return a new, sorted copy.
 
returnSortedIndexArray:Boolean (default = false) — Set this to true to return a new Array of sorted indices.

Returns
* — Either the original Array or a new one.

See also

Array.sortOn()
stringCompare()method 
public static function stringCompare(a:String, b:String, caseInsensitive:Boolean = false):int

Parameters

a:String
 
b:String
 
caseInsensitive:Boolean (default = false)

Returns
int

See also

mx.utils.ObjectUtil.stringCompare()
substitute()method 
public static function substitute(format:String, ... args):String

Substitutes "{n}" tokens within the specified string with the respective arguments passed in. Same syntax as StringUtil.substitute() without the side-effects of using String.replace() with a regex.

Parameters

format:String
 
... args

Returns
String

See also

String.replace()
mx.utils.StringUtil.substitute()
suggestPrecision()method 
public static function suggestPrecision(n:Number, d:int):Number

Parameters

n:Number — The number to round.
 
d:int — The total number of non-zero digits we care about for small numbers.

Returns
Number
sum()method 
public static function sum(... args):Number

Calculates the sum of a list of Numbers.

Parameters

... args

Returns
Number
trim()method 
public static function trim(str:String):String

Parameters

str:String

Returns
String

See also

mx.utils.StringUtil.trim()
ucs2encode()method 
public static function ucs2encode(value:uint):String

Parameters

value:uint

Returns
String

See also

https://github.com/bestiejs/punycode.js
unIndent()method 
public static function unIndent(script:String, spacesPerTab:int = -1):String

Takes a script where all lines have been indented with tabs, removes the common indentation from all lines and optionally replaces extra leading tabs with a number of spaces.

Parameters

script:String — A script.
 
spacesPerTab:int (default = -1) — If zero or greater, this is the number of spaces to be used in place of each tab character used as indentation.

Returns
String — The modified script.