Constructor
# new Formatter(object)
Default values for the markers are ${
and }
Parameters:
Name | Type | Description |
---|---|---|
object |
object |
- Since:
- 1.26.0
- Copyright:
- schukai GmbH
Throws:
-
value is not a object
- Type
- TypeError
Example
import {Formatter} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/i18n/formatter.js';
import {Translations} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.27.0/dist/modules/i18n/translations.js';
const translations = new Translations('en')
.assignTranslations({
thekey: "${animal} has eaten the ${food}!"
});
new Formatter({}, translations).format("thekey:animal=dog::food=cake")
// ↦ dog has eaten the cake!
Members
# defaults
Properties
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
marker |
object |
Properties
|
||||||||||||
parameter |
object |
Properties
|
||||||||||||
callbacks |
object |
Properties
|
Methods
# format(text) → {string}
Parameters:
Name | Type | Description |
---|---|---|
text |
string |
Throws:
-
-
value is not a string
- Type
- TypeError
-
-
-
too deep nesting
- Type
- Error
-
-
-
key not found
- Type
- Error
-
-
-
the closing marker is missing
- Type
- Error
-
Returns:
- Type
- string