Helper functions used in various places within ical.js

Methods

(static) binsearchInsert(list, seekVal, cmpfunc) → {Number}

Find the index for insertion using binary search.

Parameters:
NameTypeDescription
listArray

The list to search

seekVal?

The value to insert

cmpfuncfunction

The comparison func, that can compare two seekVals

Returns:

The insert position

Type: 
Number

(static) clone(aSrc, aDeepopt) → {*}

Clone the passed object or primitive. By default a shallow clone will be executed.

Parameters:
NameTypeAttributesDescription
aSrc*

The thing to clone

aDeepBoolean<optional>

If true, a deep clone will be performed

Returns:

The copy of the thing

Type: 
*

(static) extend(source, target) → {Object}

Poor-man's cross-browser object extension. Doesn't support all the features, but enough for our usage. Note that the target's properties are not overwritten with the source properties.

Parameters:
NameTypeDescription
sourceObject

The object to extend

targetObject

The object to extend with

Returns:

Returns the target.

Type: 
Object
Example
var child = ICAL.helpers.extend(parent, {
  "bar": 123
});

(static) foldline(aLine) → {String}

Performs iCalendar line folding. A line ending character is inserted and the next line begins with a whitespace.

Parameters:
NameTypeDescription
aLineString

The line to fold

Returns:

The folded line

Type: 
String
Example
SUMMARY:This line will be fold
 ed right in the middle of a word.

(static) formatClassType(data, type) → {?}

Creates or returns a class instance of a given type with the initialization data if the data is not already an instance of the given type.

Parameters:
NameTypeDescription
dataObject

object initialization data

typeObject

object type (like ICAL.Time)

Returns:

An instance of the found type.

Type: 
?
Example
var time = new ICAL.Time(...);
var result = ICAL.helpers.formatClassType(time, ICAL.Time);

(result instanceof ICAL.Time)
// => true

result = ICAL.helpers.formatClassType({}, ICAL.Time);
(result isntanceof ICAL.Time)
// => true

(static) isStrictlyNaN(number) → {Boolean}

Checks if the given type is of the number type and also NaN.

Parameters:
NameTypeDescription
numberNumber

The number to check

Returns:

True, if the number is strictly NaN

Type: 
Boolean

(static) pad2(data) → {String}

Pads the given string or number with zeros so it will have at least two characters.

Parameters:
NameTypeDescription
dataString | Number

The string or number to pad

Returns:

The number padded as a string

Type: 
String

(static) strictParseInt(string) → {Number}

Parses a string value that is expected to be an integer, when the valid is not an integer throws a decoration error.

Parameters:
NameTypeDescription
stringString

Raw string input

Returns:

Parsed integer

Type: 
Number

(static) trunc(number) → {Number}

Truncates the given number, correctly handling negative numbers.

Parameters:
NameTypeDescription
numberNumber

The number to truncate

Returns:

The truncated number

Type: 
Number

(static) unescapedIndexOf(buffer, search, pos) → {Number}

Identical to indexOf but will only match values when they are not preceded by a backslash character.

Parameters:
NameTypeDescription
bufferString

String to search

searchString

Value to look for

posNumber

Start position

Returns:

The position, or -1 if not found

Type: 
Number

(static) updateTimezones(vcal) → {ICAL.Component}

Compiles a list of all referenced TZIDs in all subcomponents and removes any extra VTIMEZONE subcomponents. In addition, if any TZIDs are referenced by a component, but a VTIMEZONE does not exist, an attempt will be made to generate a VTIMEZONE using ICAL.TimezoneService.

Parameters:
NameTypeDescription
vcalICAL.Component

The top-level VCALENDAR component.

Returns:

The ICAL.Component that was passed in.

Type: 
ICAL.Component