Package dev.gmitch215.bytebox.builtin
Class Intl
java.lang.Object
dev.gmitch215.bytebox.builtin.Intl
The platform's own locale data, exposed as itself.
The isolate already carries locale, currency and timezone data for Intl. Reaching it
costs nothing, while the class library's equivalent would compile CLDR tables into the binary:
String.format and its locale graph measure over 230 KB of wasm, against a hello world of
16 KB.
This is deliberately not the java.text API. It is the JavaScript one, named as such,
for the cases where a standard-looking Java surface would be a lie about which rules apply. Where
a Java API can be backed faithfully, it is, and that needs no separate name.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic intCompares two strings the way a locale sorts them.static StringFormats an amount of money.static StringFormats an instant with options.static StringFormats an instant in a timezone.static StringJoins a list the way a language does, such asa, b and c.static StringFormats a number for a locale.static StringFormats a number with options.static StringFormats a duration the way a person would say it, such as3 days ago.static booleanReports whether the runtime carries data for a locale.static StringtimeZone()Returns the timezone the runtime believes it is in, which on Workers is always UTC.
-
Method Details
-
number
Formats a number for a locale.- Parameters:
value- the numberlocale- a BCP 47 tag, such asen-US- Returns:
- the formatted number
-
number
Formats a number with options.- Parameters:
value- the numberlocale- a BCP 47 tagoptions-style,currency,minimumFractionDigitsand the rest- Returns:
- the formatted number
-
currency
Formats an amount of money.- Parameters:
value- the amountlocale- a BCP 47 tagcurrency- an ISO 4217 code, such asUSD- Returns:
- the formatted amount
-
dateTime
Formats an instant in a timezone.- Parameters:
millis- milliseconds since the epochlocale- a BCP 47 tagtimeZone- an IANA zone, such asEurope/London- Returns:
- the formatted instant
-
dateTime
Formats an instant with options.- Parameters:
millis- milliseconds since the epochlocale- a BCP 47 tagoptions-timeZone,dateStyle,timeStyleand the rest- Returns:
- the formatted instant
-
relative
Formats a duration the way a person would say it, such as3 days ago.- Parameters:
value- how many units, negative for the pastunit-second,minute,hour,day,month,yearlocale- a BCP 47 tag- Returns:
- the formatted duration
-
list
Joins a list the way a language does, such asa, b and c.- Parameters:
items- the itemslocale- a BCP 47 tag- Returns:
- the joined list
-
compare
Compares two strings the way a locale sorts them.- Parameters:
left- the first stringright- the second stringlocale- a BCP 47 tag- Returns:
- negative, zero or positive
-
timeZone
Returns the timezone the runtime believes it is in, which on Workers is always UTC.- Returns:
- the timezone the runtime believes it is in, which on Workers is always UTC
-
supports
Reports whether the runtime carries data for a locale.Worth checking once rather than assuming: a runtime built without full ICU falls back to a single locale, and every formatter then silently produces English.
- Parameters:
locale- a BCP 47 tag- Returns:
- whether the runtime resolves it to itself rather than falling back
-