JSDoc: Class: Runtime

# Class: Runtime

## Runtime

#### new Runtime(localeopt, pluralFuncopt, formattersopt)

A set of utility functions that are called by the compiled Javascript functions, these are included locally in the output of compile().

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`locale` | string | <optional> | The parsed locale
`pluralFunc` | function | <optional> | Pluralization function for the locale
`formatters` | Array.<function()> | <optional> | Optional custom formatting functions

Source:
  - messageformat.js, line 213

### Members

#### fmt :Object.<string, function()>

Custom formatting functions called by `{var, fn[, args]*}` syntax

For examples, see MessageFormat.formatters

##### Type:

- Object.<string, function()>

Source:
  - messageformat.js, line 229
See:
  - MessageFormat.formatters

#### pluralFuncs :Object.<string, function()>

Pluralization functions included in compiled output

##### Type:

- Object.<string, function()>

Source:
  - messageformat.js, line 219

### Methods

#### number(value, offsetopt)

Utility function for `#` in plural rules

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`value` | number |  |  | The value to operate on
`offset` | number | <optional> | 0 | An optional offset, set by the surrounding context

Source:
  - messageformat.js, line 241

#### plural(value, offset, lcfunc, data, isOrdinalnullable) → {string}

Utility function for `{N, plural|selectordinal, ...}`

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`value` | number |  | The key to use to find a pluralization rule
`offset` | number |  | An offset to apply to `value`
`lcfunc` | function |  | A locale function from `pluralFuncs`
`data` | Object.<string, string> |  | The object from which results are looked up
`isOrdinal` | boolean | <nullable> | If true, use ordinal rather than cardinal rules

Source:
  - messageformat.js, line 254

##### Returns:

The result of the pluralization

Type
  string

#### select(value, data) → {string}

Utility function for `{N, select, ...}`

##### Parameters:

Name | Type | Description
--- | --- | ---
`value` | number | The key to use to find a selection
`data` | Object.<string, string> | The object from which results are looked up

Source:
  - messageformat.js, line 267

##### Returns:

The result of the select statement

Type
  string

#### toString()

Custom stringifier

Source:
  - messageformat.js, line 304

##### Example

    var mf = new MessageFormat('en');
    console.log(mf.runtime.toString())
    > var pluralFuncs = {
    >   en: function (n, ord) {
    >     var s = String(n).split('.'), v0 = !s[1], t0 = Number(s[0]) == n,
    >         n10 = t0 && s[0].slice(-1), n100 = t0 && s[0].slice(-2);
    >     if (ord) return (n10 == 1 && n100 != 11) ? 'one'
    >         : (n10 == 2 && n100 != 12) ? 'two'
    >         : (n10 == 3 && n100 != 13) ? 'few'
    >         : 'other';
    >     return (n == 1 && v0) ? 'one' : 'other';
    >   }
    > };
    > var fmt = {};
    > var number = function (value, offset) {
    >   if (isNaN(value)) throw new Error("'" + value + "' isn't a number.");
    >   return value - (offset || 0);
    > };
    > var plural = function (value, offset, lcfunc, data, isOrdinal) {
    >   if ({}.hasOwnProperty.call(data, value)) return data[value]();
    >   if (offset) value -= offset;
    >   var key = lcfunc(value, isOrdinal);
    >   if (key in data) return data[key]();
    >   return data.other();
    > };
    > var select = function (value, data) {
    >   if ({}.hasOwnProperty.call(data, value)) return data[value]();
    >   return data.other()
    > };