- Description:
- Does string formatting and translation given a locale.
Because method names are going to be used in templates, we keep them short, but descriptive.
Method names are nouns describing what they return (rather than verbs), e.g..month()and.upper(), unless they are made for modifying variables, like.addMonths().
Date/time related methods take their input as date/time strings (e.g. "2018-01-01") or Javascript date objects, unless something else is explicitly stated in the method name (an exception is for instance.monthFromNumber()). For time methods, a fragment of a date/time string is fine (e.g. '20:14:00')
Methods ususally take one argument, and an additional options dictionary. See options for full documentation of available options.
Some methods can be chained, for readability:month().upper()is equivalent toupper(month()).
If you let your data live in the same namespace as the methods, we recommend using PascalCase for variables, as all textfunctions methods are lowerCamelCase.
Language support vary by method, but most of our data is from CLDR.
See https://www.unicode.org/cldr/charts/latest/supplemental/locale_coverage.html for approximate coverage by language.
- Does string formatting and translation given a locale.
Does string formatting and translation given a locale.
Because method names are going to be used in templates, we keep them short, but descriptive.
Method names are nouns describing what they return (rather than verbs), e.g.
Date/time related methods take their input as date/time strings (e.g. "2018-01-01") or Javascript date objects, unless something else is explicitly stated in the method name (an exception is for instance
Methods ususally take one argument, and an additional options dictionary. See options for full documentation of available options.
Some methods can be chained, for readability:
If you let your data live in the same namespace as the methods, we recommend using PascalCase for variables, as all textfunctions methods are lowerCamelCase.
Language support vary by method, but most of our data is from CLDR.
See https://www.unicode.org/cldr/charts/latest/supplemental/locale_coverage.html for approximate coverage by language.
Because method names are going to be used in templates, we keep them short, but descriptive.
Method names are nouns describing what they return (rather than verbs), e.g.
.month() and .upper(),
unless they are made for modifying variables, like .addMonths().Date/time related methods take their input as date/time strings (e.g. "2018-01-01") or Javascript date objects, unless something else is explicitly stated in the method name (an exception is for instance
.monthFromNumber()).
For time methods, a fragment of a date/time string is fine (e.g. '20:14:00')Methods ususally take one argument, and an additional options dictionary. See options for full documentation of available options.
Some methods can be chained, for readability:
month().upper()
is equivalent to upper(month()).If you let your data live in the same namespace as the methods, we recommend using PascalCase for variables, as all textfunctions methods are lowerCamelCase.
Language support vary by method, but most of our data is from CLDR.
See https://www.unicode.org/cldr/charts/latest/supplemental/locale_coverage.html for approximate coverage by language.
Example
// returns 'istanbul'
import tF from "text-functions"
const t = tF("sv")
t.lower("İstanbul")
Members
(static) lang :Array.<string>
- Description:
- Read-only property holding the current template language/locale(s).
Read-only property holding the current template language/locale(s).
Type:
- Array.<string>
Example
sv-SE
// returns ['sv-SE']
lang
(static) localeTerritory :Array.<string>
- Description:
- Read-only property holding the current locale territory/-ies. Throws an error if no explicit territory is set for a locale.
Read-only property holding the current locale territory/-ies.
Throws an error if no explicit territory is set for a locale.
Type:
- Array.<string>
Examples
sv-AX
// returns ['AX']
// localeTerritory
sv
// throws an error
// localeTerritory
(inner) optionDefaults :object
- Description:
- This property can be used to override default values for all options. This may reduce the efficiency of the method cache.
This property can be used to override default values for all options.
This may reduce the efficiency of the method cache.
Type:
- object
Example
en
number(0.001) # '0'
optionDefaults.decimalDigits = 4
number(0.001) # '0.001'
number(0.001, {decimalDigits: 1}) # '0'
Methods
(static) Var(value, vocab, _error) → {object}
- Description:
- Factory method for creating a chainable variable. Variable type can be string, number or array. All other value type will be returned as-is.
Example
let foo = textFunctions.Var("foo")
foo.upper() // 'FOO'
Parameters:
| Name | Type | Description |
|---|---|---|
value |
* | Value |
vocab |
object | Lexical data for dictionary methods |
_error |
string | [internal] Error message to forward to future function calls. |
Returns:
textFunctions Var object
- Type
- object