Constructor
new Formatter(object)
Default values for the markers are ${
and }
Default values for the markers are ${
and }
Parameters:
Name | Type | Description |
---|---|---|
object | object |
- Since
- 1.26.0
- Copyright
- schukai GmbH
- License
- AGPLv3
Throws:
value is not a object
- Type
- TypeError
Example
import {Formatter} from '@schukai/monster/source/i18n/formatter.mjs';
import {Translations} from '@schukai/monster/source/i18n/translations.mjs';
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
PropertiesName | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
marker | object | Properties
| ||||||||||||
parameter | object | Properties
| ||||||||||||
callbacks | object | Properties
|
(static) instanceSymbol
This method is called by the
instanceof
operator.This method is called by the instanceof
operator.
- Since
- 3.27.0
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