Generates numerals as words and ordinals
var Wolsey = require("wolsey");
var cardinal = new Wolsey();
Returns
Wolsey wolsey.Constructor
- Type
- object
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 |
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 |
(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 |
Returns
LANG instance
- Type
- object
(static) LANG(optionsopt) → {object}
Generic lang number generator
Parameters
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Properties
|
Returns
methods instance
- Type
- object
addLang(lang, methods)
Adds language to Wolsey instance
Parameters
Name | Type | Description |
---|---|---|
lang |
string | |
methods |
object |
numeral(num, options) → {string}
Calls wolsey~genericMethod
Parameters
Name | Type | Description |
---|---|---|
num |
number | |
options |
object |
Returns
numeral
- Type
- string
ordinal(num, options) → {string}
Calls wolsey~genericMethod
Parameters
Name | Type | Description |
---|---|---|
num |
number | |
options |
object |
Returns
ordinal
- Type
- string
ordinalAsNumber(num, options) → {string}
Calls wolsey~genericMethod
Parameters
Name | Type | Description |
---|---|---|
num |
number | |
options |
object |
Returns
ordinalAsNUmber
- Type
- string
resetDefault()
Resets default language to Wolsey instance’s original default
setDefault(lang)
Sets language as Wolsey instance’s default
Parameters
Name | Type | Description |
---|---|---|
lang |
string |
(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 |
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 |
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 |
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 |
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 |
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 |
Returns
converted Numeral string
- Type
- string