Module wolsey

Generates numerals as words and ordinals

var Wolsey = require("wolsey");
var cardinal = new Wolsey();
Returns
Type
object
Source:

Members

(private, inner) defaults :object

Type:
  • object
Properties:
Name Type Default Description
conjoin string and

String to conjoin word parts together

conjoinfloor number 100

Amount above which conjoining should not occur

separator string ,

String to use as separator between unit phrases

Source:

Methods

(static) Constructor(langopt, methodsopt)

Create an instance of Wolsey

 var foo = {
     numeral: function (num, options) { … },
     ordinal: function (num, options) { … },
     ordinalAsNumber: function (num, options) { … }
 };
 var cardinal = new Wolsey("foo", foo);

Or using one of the additional supplied languages

 require("wolsey/lang/fr");
 var cardinal = new Wolsey("fr", Wolsey.FR());
Parameters
Name Type Attributes Default Description
lang string <optional>
en-gb

Default lang

methods object <optional>
en-gb methods

Lang methods

Source:

(static) EN(optionsopt, powersopt, longscaleopt, lowestopt, numeralsopt, ordinalopt, ordinalAsNumberopt) → {object}

Generic English lang number generator

Calls wolsey.LANG

Parameters
Name Type Attributes Default Description
options object <optional>
powers object <optional>
powers

Powers to use as units

longscale boolean <optional>
false

Whether to use longscale units

lowest function <optional>
lowestEN

Method to handle non-power units

numerals object <optional>
numerals

Lookup map of numerals

ordinal function <optional>
ordinal

Ordinal method

ordinalAsNumber function <optional>
ordinalAsNumber

Ordinal as number method

Source:
Returns

LANG instance

Type
object

(static) LANG(optionsopt) → {object}

Generic lang number generator

Parameters
Name Type Attributes Description
options object <optional>
Properties
Name Type Attributes Default Description
numerals object <optional>

Digits and irregualr numbers to use

powers array | object <optional>

Powers of 10 considered to be increments by language

lowest function <optional>

Method to handle non-powers

ordinal function <optional>

Method to handle ordinals

ordinalAsNumber function <optional>

Method to handle ordinals as numbers

space string <optional>
" "

Character to use for generic spaces between number words

unitone string <optional>

Value to use when unit quotient is one

pluralizeunitexact boolean <optional>
false

Pluralize unit only if no remnant

hyphenatecompound boolean <optional>
false

Whether to hyphenate unit phrases

oneconjoin string <optional>

Value to use when final part of remnant is one

Source:
Returns

methods instance

Type
object

addLang(lang, methods)

Adds language to Wolsey instance

Parameters
Name Type Description
lang string
methods object
Source:

numeral(num, options) → {string}

Parameters
Name Type Description
num number
options object
Source:
Returns

numeral

Type
string

ordinal(num, options) → {string}

Parameters
Name Type Description
num number
options object
Source:
Returns

ordinal

Type
string

ordinalAsNumber(num, options) → {string}

Parameters
Name Type Description
num number
options object
Source:
Returns

ordinalAsNUmber

Type
string

resetDefault()

Resets default language to Wolsey instance’s original default

Source:

setDefault(lang)

Sets language as Wolsey instance’s default

Parameters
Name Type Description
lang string
Source:

(private, inner) convert(num, optionsopt) → {string}

Tries to retrieve an explicit lookup value or else invokes the highest power method

Parameters
Name Type Attributes Description
num number

Number to be converted

options object <optional>

Specific conversion options

Source:
Returns

Converted number as string

Type
string

(private, inner) convertLowest(num, optionsopt) → {string}

Method for converting any non-powers numbers

Parameters
Name Type Attributes Description
num number

Number to be converted

options object <optional>

Specific conversion options

Source:
Returns

Converted number as string

Type
string

(private, inner) convertMethod(num, poptions, moptionsopt) → {function}

Generates a string by determing the quotient for the current power unit and joining it with its remnant along with spaces, conjoins and separators as required.

The remant is generated by calling the next method, passing it the remainder and the same moptions.

NB. options are the options passed to the lang generating method

Parameters
Name Type Attributes Default Description
num number

Number to be converted

poptions object

Describes options for the power level

poptions.​nextmethod function

Method to call for remnant

poptions.​highestmethod function

Method to call for quotient

poptions.​floor number

The power’s value

poptions.​unitspace string <optional>
" "

Character to use between quotient, unit and remnant

poptions.​skiponeunit boolean <optional>
false

Whether to suppress number when the unit’s quotient is one

poptions.​plural string <optional>

Plural form of power

poptions.​pluralizeunitexact boolean <optional>

Pluralize unit only if no remnant

poptions.​invariable boolean <optional>

Unit should not be pluralized

poptions.​{{moptions.​unitkind}} object

Unit (or alternative kind) conversion is handling

moptions object <optional>

Specific options for the conversion

moptions.​lookup object <optional>
numerals

Object to perform numeric lookups

moptions.​unitkind string <optional>
unit

Allows a different unit kind to be specified, eg. ordinal, which allows the numeral method to be reused as is

Source:
Returns

Method that converts the number at that power level and then moves to the next power level

Type
function

(private, inner) createPowerMethod(poptions) → {function}

Parameters
Name Type Description
poptions object

Describes options for the power level

Source:
Returns

Method that converts the number at that power level and then moves to the next power level

Type
function

(inner) genericMethod(method, num, options) → {string}

Parameters
Name Type Description
method string

Method to be invoked

num number

Number to be converted

options object

Options for the method

Source:
Returns

converted number

Type
string

(inner) lowestEN(num, numerals, numeral) → {string}

Parameters
Name Type Description
num number

Number to be converted

numerals object

Object representing digits and irregular instances

numeral object

Wolsey instance’s numeral object

Source:
Returns

converted Numeral string

Type
string