accu
static
Object<Array>
accu
(
obj
,
key
,
val
)
Accumulate a key/value pair in an object.
Starting from an new empty object, accumulating values produces an object of arrays of values.
- Parameters:
-
obj <Object>the destination object -
key <String>the key under which the value has to be accumulated -
val <Any>any value to accumulate in the destination object
- Returns:
Object<Array> - the modified destination object
buildTimeZone
static
string
buildTimeZone
(
date
)
Builds a string representation of the current websurfer's time offset.
This is not strictly speaking a time zone, but it still helps to get some reasonable default value.
- Parameters:
-
date <Date>an optional date value to get the time offset from
- Returns:
string - the representation of the current time offset
cloneObject
static
Object|Array
cloneObject
(
obj
,
defaults
)
Creates a new object, puts default keys/values into it, and then source key/value pairs.
The resulting clone is a one-level-deep copy.
If
obj is an Array, then the clone will also be an Array.
Approximatively equivalent to U.putAll(U.putAll(U.isArray(obj) ? [] : {}, defaults), obj);
- Parameters:
-
obj <Object|Array>source object (or array) to be cloned -
defaults <Object>default values to put first into the clone
- Returns:
Object|Array - a newly created object (an array if
objwas).
countDefined
static
number
countDefined
(
o
)
Counts defined values in an object or an array. Sparse arrays are supported.
Properties from any secretly linked object in the prototype chain are ignored.
- Parameters:
-
o <Object|Array>an object or an array
- Returns:
number - the number of defined values
createMarkupNode
static
Node
createMarkupNode
(
markup
,
document
)
Create a
Node hierarchy based on some specification.
This hierarchy lives in some Document, defaulting to the current one.
The specification is based on some data structure made of objects, arrays and strings.
Mapping rules are the following:
- (0) markup is an element or a string
- (1) element is a 1-keyed object (tagName: content)
- (2) content is an 2-elements array (attrs, body), an element or a string
- (3) attrs is an object (name: value)
- (4) body is an array of elements or strings, an element or a string
{
ul: [ { style: 'background-color: gray;' },
[
// childrens illustrating rule (4)
{ li: [ { style: 'color: blue;' }, [ { span: 'toto' }, { span: 'titi' } ] ] },
{ li: [ { style: 'color: blue;' }, [ { span: 'toto' }, 'titi' ] ] },
{ li: [ { style: 'color: blue;' }, [ 'toto', { span: 'titi' } ] ] },
{ li: [ { style: 'color: blue;' }, { span: 'blue item' } ] },
{ li: [ { style: 'color: blue;' }, 'blue item' ] },
// childrens illustrating rule (2)
{ li: [ {}, [ 'black', ' ', 'item' ] ] },
{ li: [ {}, 'black item' ] },
{ li: { span: 'black item' } },
{ li: 'black item' }
]
]
]
}
- Parameters:
-
markup <Object|String>the markup to generate, expressed as a JS value as explained above -
document <Document>an optional document used to create newNodes
- Returns:
Node - a text
Node, anElementor anHTMLElement
formatDateTime
static
string
formatDateTime
(
d
)
Format a
Date instance as a string. The output complies with the LnkWcb format "DD/MM/YYYY hh:mm".
- Parameters:
-
d <Date>the date instance to format
- Returns:
string - the formated date
indexOf
static
number
indexOf
(
array
,
elt
,
from
)
Search an element into an array. Strict equality
=== is used here.
This method is useful to support old IE versions that don't have the Array.indexOf() method.
- Parameters:
-
array <Array>an array, or any object with a meaningfullengthattribute -
elt <Any>an element to look for -
from <Number>an optional index to start the search from, defaulting to0
- Returns:
number - the index of the first matching element, or
-1if element was not found.
isArray
static
boolean
isArray
(
any
)
Tells whether a value is an Array.
It might have been created with the
[] literal construct
or with the new Array() statement.
When this method returns true, then the length
attribute does have the special Array length semantic.
- Parameters:
-
any <Any>value to test
- Returns:
boolean trueif the value is an Array,falseotherwise.
keySet
static
Array<String>
keySet
(
o
)
Compute an array of all own keys of an object. Undefined values are taken into account.
Properties from any secretly linked object in the prototype chain are ignored.
- Parameters:
-
o <Object>an object
- Returns:
Array<String> - the array of keys
object
static
Object
object
(
o
)
Create an object secretly linked to the object passed as argument.
- Parameters:
-
o <Object>base object
- Returns:
Object - a newly created object
putAll
static
Object
putAll
(
dest
,
src
)
Put all source keys/values into destination. Source is left unchanged. Undefined keys are copied. Destination is modified an returned.
- Parameters:
-
dest <Object>destination object -
src <Object>source object
- Returns:
Object - the modified destination object
toPaddedString
static
string
toPaddedString
(
number
,
length
,
radix
)
Format a number as a string. Optionally left-padded with zeroes.
- Parameters:
-
number <Number>the number to format -
length <Number>the minimum length of the resulting string -
radix <Number>an optional radix, defaulting to10
- Returns:
string - the formated number
urlDecode
static
Object<String|Array<String>>
urlDecode
(
)
Decodes a query string encoded set of key/value pairs. Produces an object of Strings or Arrays.
Single values are Strings, and multiple values are arrays of strings.