Namespace Popcorn.Utils


namespace Popcorn.Utils
'Utils' namespace contains helper functions used by all Popcorn modules.
Authors:
Adam Smyczek

Function Summary
any[] args2array(arguments args)
Converts JavaScript function arguments to an array.
any[] args2range(arguments args, integer min, integer max)
Function arguments parser for 'range' functions.
any[] arrayOf(any inp)
object clone(object o)
Creates a new object with the argument objects as prototype.
date dateOf(any inp)
function functionOf(any inp)
integer intOf(any inp)
'intOf' truncates the input to an int if the input object is a number.
boolean isArray(any inp)
boolean isDate(any inp)
boolean isFunction(any inp)
boolean isInt(any inp)
boolean isNull(any inp)
boolean isNumber(any inp)
boolean isObject(any inp)
boolean isString(any inp)
boolean isUndefined(any inp)
any[] map(function f, any[] as)
Applies function 'f' on all elements of array 'as'.
object merge(object+ os)
Merges argument objects together.
number numberOf(any inp)
string stringOf(any inp)
string typeOf(any inp)
'typeOf' extends JavaScript 'typeof' operator with support for 'null', 'undefined', 'array' and 'date' types.

Function Details

function args2array

any[] args2array(arguments args)
Converts JavaScript function arguments to an array.
For example:
   function() {
     var args = args2array(arguments);
     ...
   }
 
Parameters:
args - the JavaScript function 'arguments'.
Defined in Popcorn.Core

function args2range

any[] args2range(arguments args, integer min, integer max)
Function arguments parser for 'range' functions.
A 'range' function performs operations on an input range between a min and max integer value. A 'range' function takes no arguments, or one or two integer arguments. Bases on arguments the function is called with and the provided default 'min' and 'max' values, 'args2rage' returns the following range array:
  • no args -> [min, max]
  • one arg -> [min, arg one]
  • two args -> [arg one, arg two]
For example:
   function() {
     var min_max = args2range(arguments);
     ...
   }
 
Parameters:
args - the JavaScript function 'arguments'.
min - range min value used when no arguments are passed to the range function.
max - range max value used when no or one argument is passed to the range function.
See also:
Popcorn.Common.range for an example range function.
Defined in Popcorn.Core

function arrayOf

any[] arrayOf(any inp)
Parameters:
inp - any variable, object etc.
Returns:
the input object if it is an array and throws an exception otherwise.
Throws:
an exception if input is not an array.
Defined in Popcorn.Core

function clone

object clone(object o)
Creates a new object with the argument objects as prototype.
Parameters:
o - the object to clone.
Defined in Popcorn.Core

function dateOf

date dateOf(any inp)
Parameters:
inp - any variable, object etc.
Returns:
the input object if it is a date object or a date string.
Throws:
an exception if input is not a date object.
Defined in Popcorn.Core

function functionOf

function functionOf(any inp)
Parameters:
inp - any variable, object etc.
Returns:
the input object if it is a function and throws an exception otherwise.
Throws:
an exception if input is not a function.
Defined in Popcorn.Core

function intOf

integer intOf(any inp)
'intOf' truncates the input to an int if the input object is a number. An exception is thrown when the input is not a number.
Parameters:
inp - any variable, object etc.
Returns:
the input object if it is an int and throws an exception otherwise.
Throws:
an exception if input is not an int.
Defined in Popcorn.Core

function isArray

boolean isArray(any inp)
Parameters:
inp - any variable, object etc.
Returns:
true if the input is an array.
Defined in Popcorn.Core

function isDate

boolean isDate(any inp)
Parameters:
inp - any variable, object etc.
Returns:
true if the input is a date object.
Defined in Popcorn.Core

function isFunction

boolean isFunction(any inp)
Parameters:
inp - any variable, object etc.
Returns:
true if the input is a function.
Defined in Popcorn.Core

function isInt

boolean isInt(any inp)
Parameters:
inp - any variable, object etc.
Returns:
true if the input is an int.
Defined in Popcorn.Core

function isNull

boolean isNull(any inp)
Parameters:
inp - any variable, object etc.
Returns:
true if the input is null.
Defined in Popcorn.Core

function isNumber

boolean isNumber(any inp)
Parameters:
inp - any variable, object etc.
Returns:
true if the input is a number.
Defined in Popcorn.Core

function isObject

boolean isObject(any inp)
Parameters:
inp - any variable, object etc.
Returns:
true if the input is an object (not an array of function).
Defined in Popcorn.Core

function isString

boolean isString(any inp)
Parameters:
inp - any variable, object etc.
Returns:
true if the input is a string.
Defined in Popcorn.Core

function isUndefined

boolean isUndefined(any inp)
Parameters:
inp - any variable, object etc.
Returns:
true if the input is undefined.
Defined in Popcorn.Core

function map

any[] map(function f, any[] as)
Applies function 'f' on all elements of array 'as'.
map(f, as) => [f(as[i])]
Parameters:
f - function.
as - input array.
Defined in Popcorn.Core

function merge

object merge(object+ os)
Merges argument objects together. This function copies all attributes of all argument objects into one. Use with care, name conflicts are not handled, attributes can be overwritten.
Parameters:
os - one ore more objects to merge.
Defined in Popcorn.Core

function numberOf

number numberOf(any inp)
Parameters:
inp - any variable, object etc.
Returns:
the input object if it is a number and throws an exception otherwise.
Throws:
an exception if input is not a number.
Defined in Popcorn.Core

function stringOf

string stringOf(any inp)
Parameters:
inp - any variable, object etc.
Returns:
the input object if it is a string and throws an exception otherwise.
Throws:
an exception if input is not a string.
Defined in Popcorn.Core

function typeOf

string typeOf(any inp)
'typeOf' extends JavaScript 'typeof' operator with support for 'null', 'undefined', 'array' and 'date' types. See 'Remedial JavaScript' for more details.
Parameters:
inp - any variable, object etc.
Returns:
a string representation of the type, for example 'null', 'array', 'data'.
Defined in Popcorn.Core