Global

Methods

# CalendarFactory(optionsopt) → {Calendar}

Factory method to create a new instance of a calendar subclass.

The options parameter can be an object that contains the following properties:

  • type - specify the type of the calendar desired. The list of valid values changes depending on which calendars are defined. When assembling your iliball.js, include those calendars you wish to use in your program or web page, and they will register themselves with this factory method. The "official", "gregorian", and "julian" calendars are all included by default, as they are the standard calendars for much of the world.
  • locale - some calendars vary depending on the locale. For example, the "official" calendar transitions from a Julian-style calendar to a Gregorian-style calendar on a different date for each country, as the governments of those countries decided to adopt the Gregorian calendar at different times.
  • onLoad - a callback function to call when the calendar object is fully loaded. When the onLoad option is given, the calendar factory will attempt to load any missing locale data using the ilib loader callback. When the constructor is done (even if the data is already preassembled), the onLoad function is called with the current instance as a parameter, so this callback can be used with preassembled or dynamic loading or a mix of the two.
  • sync - tell whether to load any missing locale data synchronously or asynchronously. If this option is given as "false", then the "onLoad" callback must be given, as the instance returned from this constructor will not be usable for a while.
  • loadParams - an object containing parameters to pass to the loader callback function when locale data is missing. The parameters are not interpretted or modified in any way. They are simply passed along. The object may contain any property/value pairs as long as the calling code is in agreement with the loader callback function as to what those parameters mean.

If a locale is specified, but no type, then the calendar that is default for the locale will be instantiated and returned. If neither the type nor the locale are specified, then the calendar for the default locale will be used.

Parameters:
Name Type Attributes Description
options Object <optional>

options controlling the construction of this instance, or undefined to use the default options

View Source CalendarFactory.js, line 74

an instance of a calendar object of the appropriate type

Calendar

# CharmapFactory(optionsopt) → {Charmap|undefined}

Factory method to create a new instance of a character set mapping (charmap) subclass that is appropriate for the requested charset. Charmap instances map strings to other character sets. The charsets can be of any type, single-byte, multi-byte, shifting, etc.

All mappings are done to or from Unicode in the UTF-16 encoding, which is the base character set and encoding used by Javascript itself. In order to convert between two non-Unicode character sets, you must chain two charmap instances together to first map to Unicode and then back to the second charset.

The options parameter controls which mapping is constructed and its behaviours. The current list of supported options are:

  • name - the name of the native charset to map to or from. This can be given as an Charset instance or as a string that contains any commonly used name for the character set, which is normalized to a standard IANA name. If a name is not given, this class will default to the Western European character set called ISO-8859-15.
  • missing - specify what to do if a mapping is missing for a particular character. For example, if you are mapping Unicode characters to a particular native character set that does not support particular Unicode characters, the mapper will follow the behaviour specified in this property. Valid values are:
    • skip - skip any characters that do not exist in the target charset
    • placeholder - put a static placeholder character in the output string wherever there is an unknown character in the input string. Use the placeholder parameter to specify which character to use in this case
    • escape - use an escape sequence to represent the unknown character
    The default value for the missing property if not otherwise specified is "escape" so that information is not lost.
  • placeholder - specify the placeholder character to use when the mapper cannot map a particular input character to the output string. If this option is not specified, then the '?' (question mark) character is used where possible.
  • escapeStyle - what style of escape sequences should be used to escape unknown characters in the input when mapping to native, and what style of espcae sequences should be parsed when mapping to Unicode. Valid values are:
    • html - Escape the characters as HTML entities. This would use the standard HTML 5.0 (or later) entity names where possible, and numeric entities in all other cases. Eg. an "e" with an acute accent would be "é"
    • js - Use the Javascript escape style. Eg. an "e" with an acute accent would be "\u00E9". This can also be specified as "c#" as it uses a similar escape syntax.
    • c - Use the C/C++ escape style, which is similar to the the Javascript style, but uses an "x" in place of the "u". Eg. an "e" with an acute accent would be "\x00E9". This can also be specified as "c++".
    • java - Use the Java escape style. This is very similar to the the Javascript style, but the backslash has to be escaped twice. Eg. an "e" with an acute accent would be "\\u00E9". This can also be specified as "ruby", as Ruby uses a similar escape syntax with double backslashes.
    • perl - Use the Perl escape style. Eg. an "e" with an acute accent would be "\N{U+00E9}"
    The default if this style is not specified is "js" for Javascript.
  • onLoad - a callback function to call when this object is fully loaded. When the onLoad option is given, this class will attempt to load any missing data using the ilib loader callback. When the constructor is done (even if the data is already preassembled), the onLoad function is called with the current instance as a parameter, so this callback can be used with preassembled or dynamic loading or a mix of the two.
  • sync - tell whether to load any missing data synchronously or asynchronously. If this option is given as "false", then the "onLoad" callback must be given, because the instance returned from this constructor will not be usable for a while.
  • loadParams - an object containing parameters to pass to the loader callback function when data is missing. The parameters are not interpretted or modified in any way. They are simply passed along. The object may contain any property/value pairs as long as the calling code is in agreement with the loader callback function as to what those parameters mean.

If this copy of ilib is pre-assembled and all the data is already available, or if the data was already previously loaded, then this constructor will call the onLoad callback immediately when the initialization is done. If the onLoad option is not given, this class will only attempt to load any missing data synchronously.

Parameters:
Name Type Attributes Description
options Object <optional>

options controlling the construction of this instance, or undefined to use the default options

View Source CharmapFactory.js, line 127

an instance of a character set mapping class appropriate for the requested charset, or undefined if no mapper could be found that supports the requested charset

Charmap | undefined

# DateFactory(optionsopt) → {IDate}

Factory method to create a new instance of a date subclass.

The options parameter can be an object that contains the following properties:

  • type - specify the type/calendar of the date desired. The list of valid values changes depending on which calendars are defined. When assembling your iliball.js, include those date type you wish to use in your program or web page, and they will register themselves with this factory method. The "gregorian", and "julian" calendars are all included by default, as they are the standard calendars for much of the world. If not specified, the type of the date returned is the one that is appropriate for the locale. This property may also be given as "calendar" instead of "type".
  • onLoad - a callback function to call when the date object is fully loaded. When the onLoad option is given, the date factory will attempt to load any missing locale data using the ilib loader callback. When the constructor is done (even if the data is already preassembled), the onLoad function is called with the current instance as a parameter, so this callback can be used with preassembled or dynamic loading or a mix of the two.
  • sync - tell whether to load any missing locale data synchronously or asynchronously. If this option is given as "false", then the "onLoad" callback must be given, as the instance returned from this constructor will not be usable for a while.
  • loadParams - an object containing parameters to pass to the loader callback function when locale data is missing. The parameters are not interpretted or modified in any way. They are simply passed along. The object may contain any property/value pairs as long as the calling code is in agreement with the loader callback function as to what those parameters mean.

The options object is also passed down to the date constructor, and thus can contain the the properties as the date object being instantiated. See the documentation for GregorianDate, and other subclasses for more details on other parameter that may be passed in.

Please note that if you do not give the type parameter, this factory method will create a date object that is appropriate for the calendar that is most commonly used in the specified or current ilib locale. For example, in Thailand, the most common calendar is the Thai solar calendar. If the current locale is "th-TH" (Thai for Thailand) and you use this factory method to construct a new date without specifying the type, it will automatically give you back an instance of ThaiSolarDate. This is convenient because you do not need to know which locales use which types of dates. In fact, you should always use this factory method to make new date instances unless you know that you specifically need a date in a particular calendar.

Also note that when you pass in the date components such as year, month, day, etc., these components should be appropriate for the given date being instantiated. That is, in our Thai example in the previous paragraph, the year and such should be given as a Thai solar year, not the Gregorian year that you get from the Javascript Date class. In order to initialize a date instance when you don't know what subclass will be instantiated for the locale, use a parameter such as "unixtime" or "julianday" which are unambiguous and based on UTC time, instead of the year/month/date date components. The date components for that UTC time will be calculated and the time zone offset will be automatically factored in.

Parameters:
Name Type Attributes Description
options Object <optional>

options controlling the construction of this instance, or undefined to use the default options

View Source DateFactory.js, line 103

an instance of a calendar object of the appropriate type

IDate

# MeasurementFactory(optionsopt)

Create a measurement subclass instance based on a particular measure required. The measurement is immutable once it is created, but it can be converted to other measurements later.

The options may contain any of the following properties:

  • amount - either a numeric amount for this measurement given as a number of the specified units, or another Measurement instance to convert to the requested units. If converting to new units, the type of measure between the other instance's units and the current units must be the same. That is, you can only convert one unit of mass to another. You cannot convert a unit of mass into a unit of length.
  • unit - units of this measurement. Use the static call MeasurementFactory.getAvailableUnits to find out what units this version of ilib supports. If the given unit is not a base unit, the amount will be normalized to the number of base units and stored as that number of base units. For example, if an instance is constructed with 1 kg, this will be converted automatically into 1000 g, as grams are the base unit and kg is merely a commonly used scale of grams.

Here are some examples of converting a length into new units. The first method is via this factory function by passing the old measurement in as the "amount" property.

var measurement1 = MeasurementFactory({
  amount: 5,
  units: "kilometers"
});
var measurement2 = MeasurementFactory({
  amount: measurement1,
  units: "miles"
});

The value in measurement2 will end up being about 3.125 miles.

The second method uses the convert method.

var measurement1 = MeasurementFactory({
  amount: 5,
  units: "kilometers"
});
var measurement2 = measurement1.convert("miles");
});

The value in measurement2 will again end up being about 3.125 miles.

Parameters:
Name Type Attributes Description
options Object <optional>

options that control the construction of this instance

View Source MeasurementFactory.js, line 117

# isAlnum(ch) → {boolean}

Return whether or not the first character is alphabetic or numeric.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isAlnum.js, line 31

true if the first character is alphabetic or numeric

boolean

# isAlpha(ch) → {boolean}

Return whether or not the first character is alphabetic.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isAlpha.js, line 33

true if the first character is alphabetic.

boolean

# isAscii(ch) → {boolean}

Return whether or not the first character is in the ASCII range.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isAscii.js, line 33

true if the first character is in the ASCII range.

boolean

# isBlank(ch) → {boolean}

Return whether or not the first character is a blank character.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isBlank.js, line 34

true if the first character is a blank character.

boolean

# isCntrl(ch) → {boolean}

Return whether or not the first character is a control character.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isCntrl.js, line 33

true if the first character is a control character.

boolean

# isDigit(ch) → {boolean}

Return whether or not the first character is a digit character in the Latin script.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isDigit.js, line 35

true if the first character is a digit character in the Latin script.

boolean

# isGraph(ch) → {boolean}

Return whether or not the first character is any printable character other than space.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isGraph.js, line 33

true if the first character is any printable character other than space.

boolean

# isIdeo(ch) → {boolean}

Return whether or not the first character is an ideographic character.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isIdeo.js, line 33

true if the first character is an ideographic character.

boolean

# isLower(ch) → {boolean}

Return whether or not the first character is lower-case. For alphabetic characters in scripts that do not make a distinction between upper- and lower-case, this function always returns true.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isLower.js, line 36

true if the first character is lower-case.

boolean

# isPrint(ch) → {boolean}

Return whether or not the first character is any printable character, including space.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isPrint.js, line 30

true if the first character is printable.

boolean

# isPunct(ch) → {boolean}

Return whether or not the first character is punctuation.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isPunct.js, line 34

true if the first character is punctuation.

boolean

# isScript(ch, script) → {boolean}

Return whether or not the first character in the given string is in the given script. The script is given as the 4-letter ISO 15924 script code.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

script string

the 4-letter ISO 15924 to query against

View Source isScript.js, line 38

true if the first character is in the given script, and false otherwise

boolean

# isSpace(ch) → {boolean}

Return whether or not the first character is a whitespace character.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isSpace.js, line 34

true if the first character is a whitespace character.

boolean

# isUpper(ch) → {boolean}

Return whether or not the first character is upper-case. For alphabetic characters in scripts that do not make a distinction between upper- and lower-case, this function always returns true.

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isUpper.js, line 36

true if the first character is upper-case.

boolean

# isXdigit(ch) → {boolean}

Return whether or not the first character is a hexadecimal digit written in the Latin script. (0-9 or A-F)

Parameters:
Name Type Description
ch string | IString | number

character or code point to examine

View Source isXdigit.js, line 36

true if the first character is a hexadecimal digit written in the Latin script.

boolean