From 65121fd9f74dbddc5c5b1f4b486c1bf2e3717ebd Mon Sep 17 00:00:00 2001 From: Manu Chambon Date: Fri, 9 Jul 2021 15:59:36 +0200 Subject: [PATCH] feat(use-i18n): add unit (byte/bit) formatter (#265) * feat(use-i18n): add unit (byte/bit) formatter * fix: correct bit(s)-per-second output * fix: remove console.log * feat: add minimumFractionDigits * docs: correct README --- packages/use-i18n/README.md | 122 ++ packages/use-i18n/package.json | 1 + .../__snapshots__/formatUnit.js.snap | 1143 +++++++++++++++++ packages/use-i18n/src/__tests__/formatUnit.js | 68 + packages/use-i18n/src/__tests__/index.js | 20 + packages/use-i18n/src/formatUnit.js | 188 +++ packages/use-i18n/src/index.js | 12 + yarn.lock | 5 + 8 files changed, 1559 insertions(+) create mode 100644 packages/use-i18n/src/__tests__/__snapshots__/formatUnit.js.snap create mode 100644 packages/use-i18n/src/__tests__/formatUnit.js create mode 100644 packages/use-i18n/src/formatUnit.js diff --git a/packages/use-i18n/README.md b/packages/use-i18n/README.md index 6ab9657bf..3e3c0f19a 100644 --- a/packages/use-i18n/README.md +++ b/packages/use-i18n/README.md @@ -159,3 +159,125 @@ const App = () => { ) } ``` + +### formatUnit + +This hook also exposes a `formatUnit` function which can be used to format bits/bytes until [ECMA-402 Unit Preferences](https://github.com/tc39/proposal-smart-unit-preferences) is standardised + +We follow the IEC standard (base 10) with SI units (kilo,mega,giga,...) [more info here](https://en.wikipedia.org/wiki/Binary_prefix) + +It accepts an `options` as second parameter: +- `unit`: Manadatory (see below) +- `maximumFractionDigits`: The maximum number of fraction digits to use +- `minimumFractionDigits`: The minimum number of fraction digits to use +- `short`: if it should output the short or long form of the unit (think `Kb` vs `kilobits`) + + +```js +import { useI18n } from '@scaleway/use-i18n' +import { DateInput } from '@scaleway/ui' + +const App = () => { + const { formatUnit } = useI18n() + + const units = [ + formatUnit(12 { unit: 'kilobyte' }) // "12 KB" or "12 Ko" in fr an ro + formatUnit(10 ** 8 { unit: 'bytes-humanized' }) // "100 MB" or "100 Mo" in fr an ro + formatUnit(10 ** 8 { unit: 'bits-per-second-humanized' }) // "100Mbs" + ] + + return ( +
+ {units} +
+ ) +} +``` + +We currently support two different unit: +- byte +- bit + +With each some variants : +- `(kilo|mega|giga|tera|peta|exa|zetta|yotta)(bit|byte)`: This is the bare unit + - `formatUnit(12, { unit: 'megabyte' })` => `"12 MB"` or `"12 Mo"` (in fr/ro) + - `formatUnit(12, { unit: 'kilobit' })` => `"12 Kb"` + - `formatUnit(12, { unit: 'gigabit' })` => `"12 Gb"` + - `formatUnit(12, { unit: 'byte' })` => `"12 B"` or `"12 o"` (in fr/ro) +- `(byte|bit)s-humanized`: This is an automated unit which will print a human readable value + - `formatUnit(1234567, { unit: 'bytes-humanized' })` => `"1.23 MB"` or `"1.23 Mo"` (in fr/ro) +- `(kilo|mega|giga|tera|peta|exa|zetta|yotta)(bit|byte)(byte|bit)-humanized`: This is also an automated unit which will print a human readable value but in the unit specified + - `formatUnit(123456789, { unit: 'gigabyte-humanized' })` => `"0.12 GB"` or `"0.12 Go"` (in fr/ro) + - `formatUnit(123456789, { unit: 'kilobyte-humanized' })` => `"123456.78 KB"` or `"123456.78 Ko"` (in fr/ro) + +There is also a compound variant which can only be used with bits: +- `(kilo|mega|giga|tera|peta|exa|zetta|yotta)bit-per-second` + - `formatUnit(1.6, { unit: 'gigabit-per-second' })` => `1.6 Gbps` + - `formatUnit(1.6, { unit: 'bit-per-second' })` => `1.6 bps` +- `bits-per-second-humanized`: Automated unit + - `formatUnit(123456789, { unit: 'bits-per-second-humanized' })` => `123.46 Mbps` +- `(kilo|mega|giga|tera|peta|exa|zetta|yotta)bit-per-second-humanized`: Humandreadable value in the unit specified + - `formatUnit(123456789, { unit: 'gigabit-per-second-humanized' })` => `0.12 Gbps` + - `formatUnit(123456789, { unit: 'kilobit-per-second-humanized' })` => `123456.78 Kbps` + + +Here is the full list of available units: +``` +bits-humanized +bits-per-second-humanized +bit +bit-per-second +bit-humanized +bit-per-second-humanized +kilobit +kilobit-per-second +kilobit-humanized +kilobit-per-second-humanized +megabit +megabit-per-second +megabit-humanized +megabit-per-second-humanized +gigabit +gigabit-per-second +gigabit-humanized +gigabit-per-second-humanized +terabit +terabit-per-second +terabit-humanized +terabit-per-second-humanized +petabit +petabit-per-second +petabit-humanized +petabit-per-second-humanized +exabit +exabit-per-second +exabit-humanized +exabit-per-second-humanized +zettabit +zettabit-per-second +zettabit-humanized +zettabit-per-second-humanized +yottabit +yottabit-per-second +yottabit-humanized +yottabit-per-second-humanized +bytes-humanized +byte +byte-humanized +kilobyte +kilobyte-humanized +megabyte +megabyte-humanized +gigabyte +gigabyte-humanized +terabyte +terabyte-humanized +petabyte +petabyte-humanized +exabyte +exabyte-humanized +zettabyte +zettabyte-humanized +yottabyte +yottabyte-humanized +``` diff --git a/packages/use-i18n/package.json b/packages/use-i18n/package.json index dca219af1..91ea07bfd 100644 --- a/packages/use-i18n/package.json +++ b/packages/use-i18n/package.json @@ -27,6 +27,7 @@ "license": "MIT", "dependencies": { "date-fns": "^2.19.0", + "filesize": "^6.4.0", "intl-format-cache": "^4.3.1", "intl-messageformat": "^9.5.3", "intl-pluralrules": "^1.2.2", diff --git a/packages/use-i18n/src/__tests__/__snapshots__/formatUnit.js.snap b/packages/use-i18n/src/__tests__/__snapshots__/formatUnit.js.snap new file mode 100644 index 000000000..165e4953b --- /dev/null +++ b/packages/use-i18n/src/__tests__/__snapshots__/formatUnit.js.snap @@ -0,0 +1,1143 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`formatUnit should return empty string for unknown unit 1`] = `""`; + +exports[`formatUnit should work with { unit: 'bit' } 1`] = `"12,56 b"`; + +exports[`formatUnit should work with { unit: 'bit-humanized' } 1`] = `"13 b"`; + +exports[`formatUnit should work with { unit: 'bit-per-second' } 1`] = `"12,56 bps"`; + +exports[`formatUnit should work with { unit: 'bit-per-second-humanized' } 1`] = `"13 bps"`; + +exports[`formatUnit should work with { unit: 'bits-humanized' } 1`] = `"13 b"`; + +exports[`formatUnit should work with { unit: 'bits-per-second-humanized' } 1`] = `"13 bps"`; + +exports[`formatUnit should work with { unit: 'byte' } 1`] = `"12,56 o"`; + +exports[`formatUnit should work with { unit: 'byte-humanized' } 1`] = `"13 o"`; + +exports[`formatUnit should work with { unit: 'bytes-humanized' } 1`] = `"13 o"`; + +exports[`formatUnit should work with { unit: 'exabit' } 1`] = `"12,56 Eb"`; + +exports[`formatUnit should work with { unit: 'exabit-humanized' } 1`] = `"0 Eb"`; + +exports[`formatUnit should work with { unit: 'exabit-per-second' } 1`] = `"12,56 Ebps"`; + +exports[`formatUnit should work with { unit: 'exabit-per-second-humanized' } 1`] = `"0 Ebps"`; + +exports[`formatUnit should work with { unit: 'exabyte' } 1`] = `"12,56 Eo"`; + +exports[`formatUnit should work with { unit: 'exabyte-humanized' } 1`] = `"0 Eo"`; + +exports[`formatUnit should work with { unit: 'gigabit' } 1`] = `"12,56 Gb"`; + +exports[`formatUnit should work with { unit: 'gigabit-humanized' } 1`] = `"0 Gb"`; + +exports[`formatUnit should work with { unit: 'gigabit-per-second' } 1`] = `"12,56 Gbps"`; + +exports[`formatUnit should work with { unit: 'gigabit-per-second-humanized' } 1`] = `"0 Gbps"`; + +exports[`formatUnit should work with { unit: 'gigabyte' } 1`] = `"12,56 Go"`; + +exports[`formatUnit should work with { unit: 'gigabyte-humanized' } 1`] = `"0 Go"`; + +exports[`formatUnit should work with { unit: 'kilobit' } 1`] = `"12,56 Kb"`; + +exports[`formatUnit should work with { unit: 'kilobit-humanized' } 1`] = `"0,01 Kb"`; + +exports[`formatUnit should work with { unit: 'kilobit-per-second' } 1`] = `"12,56 Kbps"`; + +exports[`formatUnit should work with { unit: 'kilobit-per-second-humanized' } 1`] = `"0,01 Kbps"`; + +exports[`formatUnit should work with { unit: 'kilobyte' } 1`] = `"12,56 Ko"`; + +exports[`formatUnit should work with { unit: 'kilobyte-humanized' } 1`] = `"0,01 Ko"`; + +exports[`formatUnit should work with { unit: 'megabit' } 1`] = `"12,56 Mb"`; + +exports[`formatUnit should work with { unit: 'megabit-humanized' } 1`] = `"0 Mb"`; + +exports[`formatUnit should work with { unit: 'megabit-per-second' } 1`] = `"12,56 Mbps"`; + +exports[`formatUnit should work with { unit: 'megabit-per-second-humanized' } 1`] = `"0 Mbps"`; + +exports[`formatUnit should work with { unit: 'megabyte' } 1`] = `"12,56 Mo"`; + +exports[`formatUnit should work with { unit: 'megabyte-humanized' } 1`] = `"0 Mo"`; + +exports[`formatUnit should work with { unit: 'petabit' } 1`] = `"12,56 Pb"`; + +exports[`formatUnit should work with { unit: 'petabit-humanized' } 1`] = `"0 Pb"`; + +exports[`formatUnit should work with { unit: 'petabit-per-second' } 1`] = `"12,56 Pbps"`; + +exports[`formatUnit should work with { unit: 'petabit-per-second-humanized' } 1`] = `"0 Pbps"`; + +exports[`formatUnit should work with { unit: 'petabyte' } 1`] = `"12,56 Po"`; + +exports[`formatUnit should work with { unit: 'petabyte-humanized' } 1`] = `"0 Po"`; + +exports[`formatUnit should work with { unit: 'terabit' } 1`] = `"12,56 Tb"`; + +exports[`formatUnit should work with { unit: 'terabit-humanized' } 1`] = `"0 Tb"`; + +exports[`formatUnit should work with { unit: 'terabit-per-second' } 1`] = `"12,56 Tbps"`; + +exports[`formatUnit should work with { unit: 'terabit-per-second-humanized' } 1`] = `"0 Tbps"`; + +exports[`formatUnit should work with { unit: 'terabyte' } 1`] = `"12,56 To"`; + +exports[`formatUnit should work with { unit: 'terabyte-humanized' } 1`] = `"0 To"`; + +exports[`formatUnit should work with { unit: 'yottabit' } 1`] = `"12,56 Yb"`; + +exports[`formatUnit should work with { unit: 'yottabit-humanized' } 1`] = `"0 Yb"`; + +exports[`formatUnit should work with { unit: 'yottabit-per-second' } 1`] = `"12,56 Ybps"`; + +exports[`formatUnit should work with { unit: 'yottabit-per-second-humanized' } 1`] = `"0 Ybps"`; + +exports[`formatUnit should work with { unit: 'yottabyte' } 1`] = `"12,56 Yo"`; + +exports[`formatUnit should work with { unit: 'yottabyte-humanized' } 1`] = `"0 Yo"`; + +exports[`formatUnit should work with { unit: 'zettabit' } 1`] = `"12,56 Zb"`; + +exports[`formatUnit should work with { unit: 'zettabit-humanized' } 1`] = `"0 Zb"`; + +exports[`formatUnit should work with { unit: 'zettabit-per-second' } 1`] = `"12,56 Zbps"`; + +exports[`formatUnit should work with { unit: 'zettabit-per-second-humanized' } 1`] = `"0 Zbps"`; + +exports[`formatUnit should work with { unit: 'zettabyte' } 1`] = `"12,56 Zo"`; + +exports[`formatUnit should work with { unit: 'zettabyte-humanized' } 1`] = `"0 Zo"`; + +exports[`formatUnit should work with large values { unit: 'bit' } 1`] = `"13 876 876 883 167 813 000 000 000 b"`; + +exports[`formatUnit should work with large values { unit: 'bit-humanized' } 1`] = `"13 876 876 883 167 813 000 000 000 b"`; + +exports[`formatUnit should work with large values { unit: 'bit-per-second' } 1`] = `"13 876 876 883 167 813 000 000 000 bps"`; + +exports[`formatUnit should work with large values { unit: 'bit-per-second-humanized' } 1`] = `"13 876 876 883 167 813 000 000 000 bps"`; + +exports[`formatUnit should work with large values { unit: 'bits-humanized' } 1`] = `"13,88 Yb"`; + +exports[`formatUnit should work with large values { unit: 'bits-per-second-humanized' } 1`] = `"13,88 Ybps"`; + +exports[`formatUnit should work with large values { unit: 'byte' } 1`] = `"13 876 876 883 167 813 000 000 000 o"`; + +exports[`formatUnit should work with large values { unit: 'byte-humanized' } 1`] = `"13 876 876 883 167 813 000 000 000 o"`; + +exports[`formatUnit should work with large values { unit: 'bytes-humanized' } 1`] = `"13,88 Yo"`; + +exports[`formatUnit should work with large values { unit: 'exabit' } 1`] = `"13 876 876 883 167 813 000 000 000 Eb"`; + +exports[`formatUnit should work with large values { unit: 'exabit-humanized' } 1`] = `"13 876 876,88 Eb"`; + +exports[`formatUnit should work with large values { unit: 'exabit-per-second' } 1`] = `"13 876 876 883 167 813 000 000 000 Ebps"`; + +exports[`formatUnit should work with large values { unit: 'exabit-per-second-humanized' } 1`] = `"13 876 876,88 Ebps"`; + +exports[`formatUnit should work with large values { unit: 'exabyte' } 1`] = `"13 876 876 883 167 813 000 000 000 Eo"`; + +exports[`formatUnit should work with large values { unit: 'exabyte-humanized' } 1`] = `"13 876 876,88 Eo"`; + +exports[`formatUnit should work with large values { unit: 'gigabit' } 1`] = `"13 876 876 883 167 813 000 000 000 Gb"`; + +exports[`formatUnit should work with large values { unit: 'gigabit-humanized' } 1`] = `"13 876 876 883 167 814 Gb"`; + +exports[`formatUnit should work with large values { unit: 'gigabit-per-second' } 1`] = `"13 876 876 883 167 813 000 000 000 Gbps"`; + +exports[`formatUnit should work with large values { unit: 'gigabit-per-second-humanized' } 1`] = `"13 876 876 883 167 814 Gbps"`; + +exports[`formatUnit should work with large values { unit: 'gigabyte' } 1`] = `"13 876 876 883 167 813 000 000 000 Go"`; + +exports[`formatUnit should work with large values { unit: 'gigabyte-humanized' } 1`] = `"13 876 876 883 167 814 Go"`; + +exports[`formatUnit should work with large values { unit: 'kilobit' } 1`] = `"13 876 876 883 167 813 000 000 000 Kb"`; + +exports[`formatUnit should work with large values { unit: 'kilobit-humanized' } 1`] = `"13 876 876 883 167 812 000 000 Kb"`; + +exports[`formatUnit should work with large values { unit: 'kilobit-per-second' } 1`] = `"13 876 876 883 167 813 000 000 000 Kbps"`; + +exports[`formatUnit should work with large values { unit: 'kilobit-per-second-humanized' } 1`] = `"13 876 876 883 167 812 000 000 Kbps"`; + +exports[`formatUnit should work with large values { unit: 'kilobyte' } 1`] = `"13 876 876 883 167 813 000 000 000 Ko"`; + +exports[`formatUnit should work with large values { unit: 'kilobyte-humanized' } 1`] = `"13 876 876 883 167 812 000 000 Ko"`; + +exports[`formatUnit should work with large values { unit: 'megabit' } 1`] = `"13 876 876 883 167 813 000 000 000 Mb"`; + +exports[`formatUnit should work with large values { unit: 'megabit-humanized' } 1`] = `"13 876 876 883 167 812 000 Mb"`; + +exports[`formatUnit should work with large values { unit: 'megabit-per-second' } 1`] = `"13 876 876 883 167 813 000 000 000 Mbps"`; + +exports[`formatUnit should work with large values { unit: 'megabit-per-second-humanized' } 1`] = `"13 876 876 883 167 812 000 Mbps"`; + +exports[`formatUnit should work with large values { unit: 'megabyte' } 1`] = `"13 876 876 883 167 813 000 000 000 Mo"`; + +exports[`formatUnit should work with large values { unit: 'megabyte-humanized' } 1`] = `"13 876 876 883 167 812 000 Mo"`; + +exports[`formatUnit should work with large values { unit: 'petabit' } 1`] = `"13 876 876 883 167 813 000 000 000 Pb"`; + +exports[`formatUnit should work with large values { unit: 'petabit-humanized' } 1`] = `"13 876 876 883,17 Pb"`; + +exports[`formatUnit should work with large values { unit: 'petabit-per-second' } 1`] = `"13 876 876 883 167 813 000 000 000 Pbps"`; + +exports[`formatUnit should work with large values { unit: 'petabit-per-second-humanized' } 1`] = `"13 876 876 883,17 Pbps"`; + +exports[`formatUnit should work with large values { unit: 'petabyte' } 1`] = `"13 876 876 883 167 813 000 000 000 Po"`; + +exports[`formatUnit should work with large values { unit: 'petabyte-humanized' } 1`] = `"13 876 876 883,17 Po"`; + +exports[`formatUnit should work with large values { unit: 'terabit' } 1`] = `"13 876 876 883 167 813 000 000 000 Tb"`; + +exports[`formatUnit should work with large values { unit: 'terabit-humanized' } 1`] = `"13 876 876 883 167,81 Tb"`; + +exports[`formatUnit should work with large values { unit: 'terabit-per-second' } 1`] = `"13 876 876 883 167 813 000 000 000 Tbps"`; + +exports[`formatUnit should work with large values { unit: 'terabit-per-second-humanized' } 1`] = `"13 876 876 883 167,81 Tbps"`; + +exports[`formatUnit should work with large values { unit: 'terabyte' } 1`] = `"13 876 876 883 167 813 000 000 000 To"`; + +exports[`formatUnit should work with large values { unit: 'terabyte-humanized' } 1`] = `"13 876 876 883 167,81 To"`; + +exports[`formatUnit should work with large values { unit: 'yottabit' } 1`] = `"13 876 876 883 167 813 000 000 000 Yb"`; + +exports[`formatUnit should work with large values { unit: 'yottabit-humanized' } 1`] = `"13,88 Yb"`; + +exports[`formatUnit should work with large values { unit: 'yottabit-per-second' } 1`] = `"13 876 876 883 167 813 000 000 000 Ybps"`; + +exports[`formatUnit should work with large values { unit: 'yottabit-per-second-humanized' } 1`] = `"13,88 Ybps"`; + +exports[`formatUnit should work with large values { unit: 'yottabyte' } 1`] = `"13 876 876 883 167 813 000 000 000 Yo"`; + +exports[`formatUnit should work with large values { unit: 'yottabyte-humanized' } 1`] = `"13,88 Yo"`; + +exports[`formatUnit should work with large values { unit: 'zettabit' } 1`] = `"13 876 876 883 167 813 000 000 000 Zb"`; + +exports[`formatUnit should work with large values { unit: 'zettabit-humanized' } 1`] = `"13 876,88 Zb"`; + +exports[`formatUnit should work with large values { unit: 'zettabit-per-second' } 1`] = `"13 876 876 883 167 813 000 000 000 Zbps"`; + +exports[`formatUnit should work with large values { unit: 'zettabit-per-second-humanized' } 1`] = `"13 876,88 Zbps"`; + +exports[`formatUnit should work with large values { unit: 'zettabyte' } 1`] = `"13 876 876 883 167 813 000 000 000 Zo"`; + +exports[`formatUnit should work with large values { unit: 'zettabyte-humanized' } 1`] = `"13 876,88 Zo"`; + +exports[`formatUnit should work with locale en and { unit: 'bit' } 1`] = `"12.56 b"`; + +exports[`formatUnit should work with locale en and { unit: 'bit-humanized' } 1`] = `"13 b"`; + +exports[`formatUnit should work with locale en and { unit: 'bit-per-second' } 1`] = `"12.56 bps"`; + +exports[`formatUnit should work with locale en and { unit: 'bit-per-second-humanized' } 1`] = `"13 bps"`; + +exports[`formatUnit should work with locale en and { unit: 'bits-humanized' } 1`] = `"13 b"`; + +exports[`formatUnit should work with locale en and { unit: 'bits-per-second-humanized' } 1`] = `"13 bps"`; + +exports[`formatUnit should work with locale en and { unit: 'byte' } 1`] = `"12.56 B"`; + +exports[`formatUnit should work with locale en and { unit: 'byte-humanized' } 1`] = `"13 B"`; + +exports[`formatUnit should work with locale en and { unit: 'bytes-humanized' } 1`] = `"13 B"`; + +exports[`formatUnit should work with locale en and { unit: 'exabit' } 1`] = `"12.56 Eb"`; + +exports[`formatUnit should work with locale en and { unit: 'exabit-humanized' } 1`] = `"0 Eb"`; + +exports[`formatUnit should work with locale en and { unit: 'exabit-per-second' } 1`] = `"12.56 Ebps"`; + +exports[`formatUnit should work with locale en and { unit: 'exabit-per-second-humanized' } 1`] = `"0 Ebps"`; + +exports[`formatUnit should work with locale en and { unit: 'exabyte' } 1`] = `"12.56 EB"`; + +exports[`formatUnit should work with locale en and { unit: 'exabyte-humanized' } 1`] = `"0 EB"`; + +exports[`formatUnit should work with locale en and { unit: 'gigabit' } 1`] = `"12.56 Gb"`; + +exports[`formatUnit should work with locale en and { unit: 'gigabit-humanized' } 1`] = `"0 Gb"`; + +exports[`formatUnit should work with locale en and { unit: 'gigabit-per-second' } 1`] = `"12.56 Gbps"`; + +exports[`formatUnit should work with locale en and { unit: 'gigabit-per-second-humanized' } 1`] = `"0 Gbps"`; + +exports[`formatUnit should work with locale en and { unit: 'gigabyte' } 1`] = `"12.56 GB"`; + +exports[`formatUnit should work with locale en and { unit: 'gigabyte-humanized' } 1`] = `"0 GB"`; + +exports[`formatUnit should work with locale en and { unit: 'kilobit' } 1`] = `"12.56 Kb"`; + +exports[`formatUnit should work with locale en and { unit: 'kilobit-humanized' } 1`] = `"0.01 Kb"`; + +exports[`formatUnit should work with locale en and { unit: 'kilobit-per-second' } 1`] = `"12.56 Kbps"`; + +exports[`formatUnit should work with locale en and { unit: 'kilobit-per-second-humanized' } 1`] = `"0.01 Kbps"`; + +exports[`formatUnit should work with locale en and { unit: 'kilobyte' } 1`] = `"12.56 KB"`; + +exports[`formatUnit should work with locale en and { unit: 'kilobyte-humanized' } 1`] = `"0.01 KB"`; + +exports[`formatUnit should work with locale en and { unit: 'megabit' } 1`] = `"12.56 Mb"`; + +exports[`formatUnit should work with locale en and { unit: 'megabit-humanized' } 1`] = `"0 Mb"`; + +exports[`formatUnit should work with locale en and { unit: 'megabit-per-second' } 1`] = `"12.56 Mbps"`; + +exports[`formatUnit should work with locale en and { unit: 'megabit-per-second-humanized' } 1`] = `"0 Mbps"`; + +exports[`formatUnit should work with locale en and { unit: 'megabyte' } 1`] = `"12.56 MB"`; + +exports[`formatUnit should work with locale en and { unit: 'megabyte-humanized' } 1`] = `"0 MB"`; + +exports[`formatUnit should work with locale en and { unit: 'petabit' } 1`] = `"12.56 Pb"`; + +exports[`formatUnit should work with locale en and { unit: 'petabit-humanized' } 1`] = `"0 Pb"`; + +exports[`formatUnit should work with locale en and { unit: 'petabit-per-second' } 1`] = `"12.56 Pbps"`; + +exports[`formatUnit should work with locale en and { unit: 'petabit-per-second-humanized' } 1`] = `"0 Pbps"`; + +exports[`formatUnit should work with locale en and { unit: 'petabyte' } 1`] = `"12.56 PB"`; + +exports[`formatUnit should work with locale en and { unit: 'petabyte-humanized' } 1`] = `"0 PB"`; + +exports[`formatUnit should work with locale en and { unit: 'terabit' } 1`] = `"12.56 Tb"`; + +exports[`formatUnit should work with locale en and { unit: 'terabit-humanized' } 1`] = `"0 Tb"`; + +exports[`formatUnit should work with locale en and { unit: 'terabit-per-second' } 1`] = `"12.56 Tbps"`; + +exports[`formatUnit should work with locale en and { unit: 'terabit-per-second-humanized' } 1`] = `"0 Tbps"`; + +exports[`formatUnit should work with locale en and { unit: 'terabyte' } 1`] = `"12.56 TB"`; + +exports[`formatUnit should work with locale en and { unit: 'terabyte-humanized' } 1`] = `"0 TB"`; + +exports[`formatUnit should work with locale en and { unit: 'yottabit' } 1`] = `"12.56 Yb"`; + +exports[`formatUnit should work with locale en and { unit: 'yottabit-humanized' } 1`] = `"0 Yb"`; + +exports[`formatUnit should work with locale en and { unit: 'yottabit-per-second' } 1`] = `"12.56 Ybps"`; + +exports[`formatUnit should work with locale en and { unit: 'yottabit-per-second-humanized' } 1`] = `"0 Ybps"`; + +exports[`formatUnit should work with locale en and { unit: 'yottabyte' } 1`] = `"12.56 YB"`; + +exports[`formatUnit should work with locale en and { unit: 'yottabyte-humanized' } 1`] = `"0 YB"`; + +exports[`formatUnit should work with locale en and { unit: 'zettabit' } 1`] = `"12.56 Zb"`; + +exports[`formatUnit should work with locale en and { unit: 'zettabit-humanized' } 1`] = `"0 Zb"`; + +exports[`formatUnit should work with locale en and { unit: 'zettabit-per-second' } 1`] = `"12.56 Zbps"`; + +exports[`formatUnit should work with locale en and { unit: 'zettabit-per-second-humanized' } 1`] = `"0 Zbps"`; + +exports[`formatUnit should work with locale en and { unit: 'zettabyte' } 1`] = `"12.56 ZB"`; + +exports[`formatUnit should work with locale en and { unit: 'zettabyte-humanized' } 1`] = `"0 ZB"`; + +exports[`formatUnit should work with locale fr and { unit: 'bit' } 1`] = `"12,56 b"`; + +exports[`formatUnit should work with locale fr and { unit: 'bit-humanized' } 1`] = `"13 b"`; + +exports[`formatUnit should work with locale fr and { unit: 'bit-per-second' } 1`] = `"12,56 bps"`; + +exports[`formatUnit should work with locale fr and { unit: 'bit-per-second-humanized' } 1`] = `"13 bps"`; + +exports[`formatUnit should work with locale fr and { unit: 'bits-humanized' } 1`] = `"13 b"`; + +exports[`formatUnit should work with locale fr and { unit: 'bits-per-second-humanized' } 1`] = `"13 bps"`; + +exports[`formatUnit should work with locale fr and { unit: 'byte' } 1`] = `"12,56 o"`; + +exports[`formatUnit should work with locale fr and { unit: 'byte-humanized' } 1`] = `"13 o"`; + +exports[`formatUnit should work with locale fr and { unit: 'bytes-humanized' } 1`] = `"13 o"`; + +exports[`formatUnit should work with locale fr and { unit: 'exabit' } 1`] = `"12,56 Eb"`; + +exports[`formatUnit should work with locale fr and { unit: 'exabit-humanized' } 1`] = `"0 Eb"`; + +exports[`formatUnit should work with locale fr and { unit: 'exabit-per-second' } 1`] = `"12,56 Ebps"`; + +exports[`formatUnit should work with locale fr and { unit: 'exabit-per-second-humanized' } 1`] = `"0 Ebps"`; + +exports[`formatUnit should work with locale fr and { unit: 'exabyte' } 1`] = `"12,56 Eo"`; + +exports[`formatUnit should work with locale fr and { unit: 'exabyte-humanized' } 1`] = `"0 Eo"`; + +exports[`formatUnit should work with locale fr and { unit: 'gigabit' } 1`] = `"12,56 Gb"`; + +exports[`formatUnit should work with locale fr and { unit: 'gigabit-humanized' } 1`] = `"0 Gb"`; + +exports[`formatUnit should work with locale fr and { unit: 'gigabit-per-second' } 1`] = `"12,56 Gbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'gigabit-per-second-humanized' } 1`] = `"0 Gbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'gigabyte' } 1`] = `"12,56 Go"`; + +exports[`formatUnit should work with locale fr and { unit: 'gigabyte-humanized' } 1`] = `"0 Go"`; + +exports[`formatUnit should work with locale fr and { unit: 'kilobit' } 1`] = `"12,56 Kb"`; + +exports[`formatUnit should work with locale fr and { unit: 'kilobit-humanized' } 1`] = `"0,01 Kb"`; + +exports[`formatUnit should work with locale fr and { unit: 'kilobit-per-second' } 1`] = `"12,56 Kbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'kilobit-per-second-humanized' } 1`] = `"0,01 Kbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'kilobyte' } 1`] = `"12,56 Ko"`; + +exports[`formatUnit should work with locale fr and { unit: 'kilobyte-humanized' } 1`] = `"0,01 Ko"`; + +exports[`formatUnit should work with locale fr and { unit: 'megabit' } 1`] = `"12,56 Mb"`; + +exports[`formatUnit should work with locale fr and { unit: 'megabit-humanized' } 1`] = `"0 Mb"`; + +exports[`formatUnit should work with locale fr and { unit: 'megabit-per-second' } 1`] = `"12,56 Mbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'megabit-per-second-humanized' } 1`] = `"0 Mbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'megabyte' } 1`] = `"12,56 Mo"`; + +exports[`formatUnit should work with locale fr and { unit: 'megabyte-humanized' } 1`] = `"0 Mo"`; + +exports[`formatUnit should work with locale fr and { unit: 'petabit' } 1`] = `"12,56 Pb"`; + +exports[`formatUnit should work with locale fr and { unit: 'petabit-humanized' } 1`] = `"0 Pb"`; + +exports[`formatUnit should work with locale fr and { unit: 'petabit-per-second' } 1`] = `"12,56 Pbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'petabit-per-second-humanized' } 1`] = `"0 Pbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'petabyte' } 1`] = `"12,56 Po"`; + +exports[`formatUnit should work with locale fr and { unit: 'petabyte-humanized' } 1`] = `"0 Po"`; + +exports[`formatUnit should work with locale fr and { unit: 'terabit' } 1`] = `"12,56 Tb"`; + +exports[`formatUnit should work with locale fr and { unit: 'terabit-humanized' } 1`] = `"0 Tb"`; + +exports[`formatUnit should work with locale fr and { unit: 'terabit-per-second' } 1`] = `"12,56 Tbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'terabit-per-second-humanized' } 1`] = `"0 Tbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'terabyte' } 1`] = `"12,56 To"`; + +exports[`formatUnit should work with locale fr and { unit: 'terabyte-humanized' } 1`] = `"0 To"`; + +exports[`formatUnit should work with locale fr and { unit: 'yottabit' } 1`] = `"12,56 Yb"`; + +exports[`formatUnit should work with locale fr and { unit: 'yottabit-humanized' } 1`] = `"0 Yb"`; + +exports[`formatUnit should work with locale fr and { unit: 'yottabit-per-second' } 1`] = `"12,56 Ybps"`; + +exports[`formatUnit should work with locale fr and { unit: 'yottabit-per-second-humanized' } 1`] = `"0 Ybps"`; + +exports[`formatUnit should work with locale fr and { unit: 'yottabyte' } 1`] = `"12,56 Yo"`; + +exports[`formatUnit should work with locale fr and { unit: 'yottabyte-humanized' } 1`] = `"0 Yo"`; + +exports[`formatUnit should work with locale fr and { unit: 'zettabit' } 1`] = `"12,56 Zb"`; + +exports[`formatUnit should work with locale fr and { unit: 'zettabit-humanized' } 1`] = `"0 Zb"`; + +exports[`formatUnit should work with locale fr and { unit: 'zettabit-per-second' } 1`] = `"12,56 Zbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'zettabit-per-second-humanized' } 1`] = `"0 Zbps"`; + +exports[`formatUnit should work with locale fr and { unit: 'zettabyte' } 1`] = `"12,56 Zo"`; + +exports[`formatUnit should work with locale fr and { unit: 'zettabyte-humanized' } 1`] = `"0 Zo"`; + +exports[`formatUnit should work with locale ro and { unit: 'bit' } 1`] = `"12,56 b"`; + +exports[`formatUnit should work with locale ro and { unit: 'bit-humanized' } 1`] = `"13 b"`; + +exports[`formatUnit should work with locale ro and { unit: 'bit-per-second' } 1`] = `"12,56 bps"`; + +exports[`formatUnit should work with locale ro and { unit: 'bit-per-second-humanized' } 1`] = `"13 bps"`; + +exports[`formatUnit should work with locale ro and { unit: 'bits-humanized' } 1`] = `"13 b"`; + +exports[`formatUnit should work with locale ro and { unit: 'bits-per-second-humanized' } 1`] = `"13 bps"`; + +exports[`formatUnit should work with locale ro and { unit: 'byte' } 1`] = `"12,56 o"`; + +exports[`formatUnit should work with locale ro and { unit: 'byte-humanized' } 1`] = `"13 o"`; + +exports[`formatUnit should work with locale ro and { unit: 'bytes-humanized' } 1`] = `"13 o"`; + +exports[`formatUnit should work with locale ro and { unit: 'exabit' } 1`] = `"12,56 Eb"`; + +exports[`formatUnit should work with locale ro and { unit: 'exabit-humanized' } 1`] = `"0 Eb"`; + +exports[`formatUnit should work with locale ro and { unit: 'exabit-per-second' } 1`] = `"12,56 Ebps"`; + +exports[`formatUnit should work with locale ro and { unit: 'exabit-per-second-humanized' } 1`] = `"0 Ebps"`; + +exports[`formatUnit should work with locale ro and { unit: 'exabyte' } 1`] = `"12,56 Eo"`; + +exports[`formatUnit should work with locale ro and { unit: 'exabyte-humanized' } 1`] = `"0 Eo"`; + +exports[`formatUnit should work with locale ro and { unit: 'gigabit' } 1`] = `"12,56 Gb"`; + +exports[`formatUnit should work with locale ro and { unit: 'gigabit-humanized' } 1`] = `"0 Gb"`; + +exports[`formatUnit should work with locale ro and { unit: 'gigabit-per-second' } 1`] = `"12,56 Gbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'gigabit-per-second-humanized' } 1`] = `"0 Gbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'gigabyte' } 1`] = `"12,56 Go"`; + +exports[`formatUnit should work with locale ro and { unit: 'gigabyte-humanized' } 1`] = `"0 Go"`; + +exports[`formatUnit should work with locale ro and { unit: 'kilobit' } 1`] = `"12,56 Kb"`; + +exports[`formatUnit should work with locale ro and { unit: 'kilobit-humanized' } 1`] = `"0,01 Kb"`; + +exports[`formatUnit should work with locale ro and { unit: 'kilobit-per-second' } 1`] = `"12,56 Kbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'kilobit-per-second-humanized' } 1`] = `"0,01 Kbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'kilobyte' } 1`] = `"12,56 Ko"`; + +exports[`formatUnit should work with locale ro and { unit: 'kilobyte-humanized' } 1`] = `"0,01 Ko"`; + +exports[`formatUnit should work with locale ro and { unit: 'megabit' } 1`] = `"12,56 Mb"`; + +exports[`formatUnit should work with locale ro and { unit: 'megabit-humanized' } 1`] = `"0 Mb"`; + +exports[`formatUnit should work with locale ro and { unit: 'megabit-per-second' } 1`] = `"12,56 Mbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'megabit-per-second-humanized' } 1`] = `"0 Mbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'megabyte' } 1`] = `"12,56 Mo"`; + +exports[`formatUnit should work with locale ro and { unit: 'megabyte-humanized' } 1`] = `"0 Mo"`; + +exports[`formatUnit should work with locale ro and { unit: 'petabit' } 1`] = `"12,56 Pb"`; + +exports[`formatUnit should work with locale ro and { unit: 'petabit-humanized' } 1`] = `"0 Pb"`; + +exports[`formatUnit should work with locale ro and { unit: 'petabit-per-second' } 1`] = `"12,56 Pbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'petabit-per-second-humanized' } 1`] = `"0 Pbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'petabyte' } 1`] = `"12,56 Po"`; + +exports[`formatUnit should work with locale ro and { unit: 'petabyte-humanized' } 1`] = `"0 Po"`; + +exports[`formatUnit should work with locale ro and { unit: 'terabit' } 1`] = `"12,56 Tb"`; + +exports[`formatUnit should work with locale ro and { unit: 'terabit-humanized' } 1`] = `"0 Tb"`; + +exports[`formatUnit should work with locale ro and { unit: 'terabit-per-second' } 1`] = `"12,56 Tbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'terabit-per-second-humanized' } 1`] = `"0 Tbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'terabyte' } 1`] = `"12,56 To"`; + +exports[`formatUnit should work with locale ro and { unit: 'terabyte-humanized' } 1`] = `"0 To"`; + +exports[`formatUnit should work with locale ro and { unit: 'yottabit' } 1`] = `"12,56 Yb"`; + +exports[`formatUnit should work with locale ro and { unit: 'yottabit-humanized' } 1`] = `"0 Yb"`; + +exports[`formatUnit should work with locale ro and { unit: 'yottabit-per-second' } 1`] = `"12,56 Ybps"`; + +exports[`formatUnit should work with locale ro and { unit: 'yottabit-per-second-humanized' } 1`] = `"0 Ybps"`; + +exports[`formatUnit should work with locale ro and { unit: 'yottabyte' } 1`] = `"12,56 Yo"`; + +exports[`formatUnit should work with locale ro and { unit: 'yottabyte-humanized' } 1`] = `"0 Yo"`; + +exports[`formatUnit should work with locale ro and { unit: 'zettabit' } 1`] = `"12,56 Zb"`; + +exports[`formatUnit should work with locale ro and { unit: 'zettabit-humanized' } 1`] = `"0 Zb"`; + +exports[`formatUnit should work with locale ro and { unit: 'zettabit-per-second' } 1`] = `"12,56 Zbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'zettabit-per-second-humanized' } 1`] = `"0 Zbps"`; + +exports[`formatUnit should work with locale ro and { unit: 'zettabyte' } 1`] = `"12,56 Zo"`; + +exports[`formatUnit should work with locale ro and { unit: 'zettabyte-humanized' } 1`] = `"0 Zo"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'bit' } 1`] = `"12.56 bits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'bit-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'bit-per-second' } 1`] = `"12.56 bits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'bit-per-second-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'bits-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'bits-per-second-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'byte' } 1`] = `"12.56 bytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'byte-humanized' } 1`] = `"13 bytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'bytes-humanized' } 1`] = `"13 bytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'exabit' } 1`] = `"12.56 exabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'exabit-humanized' } 1`] = `"0 exabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'exabit-per-second' } 1`] = `"12.56 exabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'exabit-per-second-humanized' } 1`] = `"0 exabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'exabyte' } 1`] = `"12.56 exabytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'exabyte-humanized' } 1`] = `"0 exabyte"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'gigabit' } 1`] = `"12.56 gigabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'gigabit-humanized' } 1`] = `"0 gigabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'gigabit-per-second' } 1`] = `"12.56 gigabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'gigabit-per-second-humanized' } 1`] = `"0 gigabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'gigabyte' } 1`] = `"12.56 gigabytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'gigabyte-humanized' } 1`] = `"0 gigabyte"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'kilobit' } 1`] = `"12.56 kilobits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'kilobit-humanized' } 1`] = `"0.01 kilobits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'kilobit-per-second' } 1`] = `"12.56 kilobits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'kilobit-per-second-humanized' } 1`] = `"0.01 kilobits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'kilobyte' } 1`] = `"12.56 kilobytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'kilobyte-humanized' } 1`] = `"0.01 kilobytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'megabit' } 1`] = `"12.56 megabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'megabit-humanized' } 1`] = `"0 megabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'megabit-per-second' } 1`] = `"12.56 megabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'megabit-per-second-humanized' } 1`] = `"0 megabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'megabyte' } 1`] = `"12.56 megabytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'megabyte-humanized' } 1`] = `"0 megabyte"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'petabit' } 1`] = `"12.56 petabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'petabit-humanized' } 1`] = `"0 petabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'petabit-per-second' } 1`] = `"12.56 petabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'petabit-per-second-humanized' } 1`] = `"0 petabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'petabyte' } 1`] = `"12.56 petabytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'petabyte-humanized' } 1`] = `"0 petabyte"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'terabit' } 1`] = `"12.56 terabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'terabit-humanized' } 1`] = `"0 terabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'terabit-per-second' } 1`] = `"12.56 terabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'terabit-per-second-humanized' } 1`] = `"0 terabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'terabyte' } 1`] = `"12.56 terabytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'terabyte-humanized' } 1`] = `"0 terabyte"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'yottabit' } 1`] = `"12.56 yottabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'yottabit-humanized' } 1`] = `"0 yottabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'yottabit-per-second' } 1`] = `"12.56 yottabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'yottabit-per-second-humanized' } 1`] = `"0 yottabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'yottabyte' } 1`] = `"12.56 yottabytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'yottabyte-humanized' } 1`] = `"0 yottabyte"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'zettabit' } 1`] = `"12.56 zettabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'zettabit-humanized' } 1`] = `"0 zettabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'zettabit-per-second' } 1`] = `"12.56 zettabits"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'zettabit-per-second-humanized' } 1`] = `"0 zettabit"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'zettabyte' } 1`] = `"12.56 zettabytes"`; + +exports[`formatUnit should work with long format, locale en and { short: false, unit: 'zettabyte-humanized' } 1`] = `"0 zettabyte"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'bit' } 1`] = `"12,56 bits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'bit-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'bit-per-second' } 1`] = `"12,56 bits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'bit-per-second-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'bits-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'bits-per-second-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'byte' } 1`] = `"12,56 octets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'byte-humanized' } 1`] = `"13 octets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'bytes-humanized' } 1`] = `"13 octets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'exabit' } 1`] = `"12,56 exabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'exabit-humanized' } 1`] = `"0 exabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'exabit-per-second' } 1`] = `"12,56 exabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'exabit-per-second-humanized' } 1`] = `"0 exabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'exabyte' } 1`] = `"12,56 exaoctets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'exabyte-humanized' } 1`] = `"0 exaoctet"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'gigabit' } 1`] = `"12,56 gigabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'gigabit-humanized' } 1`] = `"0 gigabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'gigabit-per-second' } 1`] = `"12,56 gigabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'gigabit-per-second-humanized' } 1`] = `"0 gigabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'gigabyte' } 1`] = `"12,56 gigaoctets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'gigabyte-humanized' } 1`] = `"0 gigaoctet"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'kilobit' } 1`] = `"12,56 kilobits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'kilobit-humanized' } 1`] = `"0,01 kilobits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'kilobit-per-second' } 1`] = `"12,56 kilobits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'kilobit-per-second-humanized' } 1`] = `"0,01 kilobits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'kilobyte' } 1`] = `"12,56 kilooctets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'kilobyte-humanized' } 1`] = `"0,01 kilooctets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'megabit' } 1`] = `"12,56 megabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'megabit-humanized' } 1`] = `"0 megabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'megabit-per-second' } 1`] = `"12,56 megabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'megabit-per-second-humanized' } 1`] = `"0 megabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'megabyte' } 1`] = `"12,56 megaoctets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'megabyte-humanized' } 1`] = `"0 megaoctet"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'petabit' } 1`] = `"12,56 petabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'petabit-humanized' } 1`] = `"0 petabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'petabit-per-second' } 1`] = `"12,56 petabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'petabit-per-second-humanized' } 1`] = `"0 petabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'petabyte' } 1`] = `"12,56 petaoctets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'petabyte-humanized' } 1`] = `"0 petaoctet"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'terabit' } 1`] = `"12,56 terabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'terabit-humanized' } 1`] = `"0 terabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'terabit-per-second' } 1`] = `"12,56 terabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'terabit-per-second-humanized' } 1`] = `"0 terabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'terabyte' } 1`] = `"12,56 teraoctets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'terabyte-humanized' } 1`] = `"0 teraoctet"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'yottabit' } 1`] = `"12,56 yottabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'yottabit-humanized' } 1`] = `"0 yottabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'yottabit-per-second' } 1`] = `"12,56 yottabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'yottabit-per-second-humanized' } 1`] = `"0 yottabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'yottabyte' } 1`] = `"12,56 yottaoctets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'yottabyte-humanized' } 1`] = `"0 yottaoctet"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'zettabit' } 1`] = `"12,56 zettabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'zettabit-humanized' } 1`] = `"0 zettabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'zettabit-per-second' } 1`] = `"12,56 zettabits"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'zettabit-per-second-humanized' } 1`] = `"0 zettabit"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'zettabyte' } 1`] = `"12,56 zettaoctets"`; + +exports[`formatUnit should work with long format, locale fr and { short: false, unit: 'zettabyte-humanized' } 1`] = `"0 zettaoctet"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'bit' } 1`] = `"12,56 bits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'bit-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'bit-per-second' } 1`] = `"12,56 bits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'bit-per-second-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'bits-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'bits-per-second-humanized' } 1`] = `"13 bits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'byte' } 1`] = `"12,56 octeți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'byte-humanized' } 1`] = `"13 octeți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'bytes-humanized' } 1`] = `"13 octeți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'exabit' } 1`] = `"12,56 exabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'exabit-humanized' } 1`] = `"0 exabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'exabit-per-second' } 1`] = `"12,56 exabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'exabit-per-second-humanized' } 1`] = `"0 exabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'exabyte' } 1`] = `"12,56 exaocteți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'exabyte-humanized' } 1`] = `"0 exaoctet"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'gigabit' } 1`] = `"12,56 gigabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'gigabit-humanized' } 1`] = `"0 gigabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'gigabit-per-second' } 1`] = `"12,56 gigabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'gigabit-per-second-humanized' } 1`] = `"0 gigabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'gigabyte' } 1`] = `"12,56 gigaocteți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'gigabyte-humanized' } 1`] = `"0 gigaoctet"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'kilobit' } 1`] = `"12,56 kilobits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'kilobit-humanized' } 1`] = `"0,01 kilobits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'kilobit-per-second' } 1`] = `"12,56 kilobits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'kilobit-per-second-humanized' } 1`] = `"0,01 kilobits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'kilobyte' } 1`] = `"12,56 kiloocteți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'kilobyte-humanized' } 1`] = `"0,01 kiloocteți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'megabit' } 1`] = `"12,56 megabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'megabit-humanized' } 1`] = `"0 megabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'megabit-per-second' } 1`] = `"12,56 megabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'megabit-per-second-humanized' } 1`] = `"0 megabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'megabyte' } 1`] = `"12,56 megaocteți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'megabyte-humanized' } 1`] = `"0 megaoctet"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'petabit' } 1`] = `"12,56 petabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'petabit-humanized' } 1`] = `"0 petabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'petabit-per-second' } 1`] = `"12,56 petabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'petabit-per-second-humanized' } 1`] = `"0 petabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'petabyte' } 1`] = `"12,56 petaocteți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'petabyte-humanized' } 1`] = `"0 petaoctet"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'terabit' } 1`] = `"12,56 terabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'terabit-humanized' } 1`] = `"0 terabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'terabit-per-second' } 1`] = `"12,56 terabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'terabit-per-second-humanized' } 1`] = `"0 terabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'terabyte' } 1`] = `"12,56 teraocteți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'terabyte-humanized' } 1`] = `"0 teraoctet"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'yottabit' } 1`] = `"12,56 yottabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'yottabit-humanized' } 1`] = `"0 yottabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'yottabit-per-second' } 1`] = `"12,56 yottabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'yottabit-per-second-humanized' } 1`] = `"0 yottabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'yottabyte' } 1`] = `"12,56 yottaocteți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'yottabyte-humanized' } 1`] = `"0 yottaoctet"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'zettabit' } 1`] = `"12,56 zettabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'zettabit-humanized' } 1`] = `"0 zettabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'zettabit-per-second' } 1`] = `"12,56 zettabits"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'zettabit-per-second-humanized' } 1`] = `"0 zettabit"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'zettabyte' } 1`] = `"12,56 zettaocteți"`; + +exports[`formatUnit should work with long format, locale ro and { short: false, unit: 'zettabyte-humanized' } 1`] = `"0 zettaoctet"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'bit' } 1`] = `"12,56 b"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'bit-humanized' } 1`] = `"13 b"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'bit-per-second' } 1`] = `"12,56 bps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'bit-per-second-humanized' } 1`] = `"13 bps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'bits-humanized' } 1`] = `"13 b"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'bits-per-second-humanized' } 1`] = `"13 bps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'byte' } 1`] = `"12,56 o"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'byte-humanized' } 1`] = `"13 o"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'bytes-humanized' } 1`] = `"13 o"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'exabit' } 1`] = `"12,56 Eb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'exabit-humanized' } 1`] = `"0 Eb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'exabit-per-second' } 1`] = `"12,56 Ebps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'exabit-per-second-humanized' } 1`] = `"0 Ebps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'exabyte' } 1`] = `"12,56 Eo"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'exabyte-humanized' } 1`] = `"0 Eo"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'gigabit' } 1`] = `"12,56 Gb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'gigabit-humanized' } 1`] = `"0 Gb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'gigabit-per-second' } 1`] = `"12,56 Gbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'gigabit-per-second-humanized' } 1`] = `"0 Gbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'gigabyte' } 1`] = `"12,56 Go"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'gigabyte-humanized' } 1`] = `"0 Go"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'kilobit' } 1`] = `"12,56 Kb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'kilobit-humanized' } 1`] = `"0,013 Kb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'kilobit-per-second' } 1`] = `"12,56 Kbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'kilobit-per-second-humanized' } 1`] = `"0,013 Kbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'kilobyte' } 1`] = `"12,56 Ko"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'kilobyte-humanized' } 1`] = `"0,013 Ko"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'megabit' } 1`] = `"12,56 Mb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'megabit-humanized' } 1`] = `"0 Mb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'megabit-per-second' } 1`] = `"12,56 Mbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'megabit-per-second-humanized' } 1`] = `"0 Mbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'megabyte' } 1`] = `"12,56 Mo"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'megabyte-humanized' } 1`] = `"0 Mo"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'petabit' } 1`] = `"12,56 Pb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'petabit-humanized' } 1`] = `"0 Pb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'petabit-per-second' } 1`] = `"12,56 Pbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'petabit-per-second-humanized' } 1`] = `"0 Pbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'petabyte' } 1`] = `"12,56 Po"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'petabyte-humanized' } 1`] = `"0 Po"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'terabit' } 1`] = `"12,56 Tb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'terabit-humanized' } 1`] = `"0 Tb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'terabit-per-second' } 1`] = `"12,56 Tbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'terabit-per-second-humanized' } 1`] = `"0 Tbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'terabyte' } 1`] = `"12,56 To"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'terabyte-humanized' } 1`] = `"0 To"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'yottabit' } 1`] = `"12,56 Yb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'yottabit-humanized' } 1`] = `"0 Yb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'yottabit-per-second' } 1`] = `"12,56 Ybps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'yottabit-per-second-humanized' } 1`] = `"0 Ybps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'yottabyte' } 1`] = `"12,56 Yo"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'yottabyte-humanized' } 1`] = `"0 Yo"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'zettabit' } 1`] = `"12,56 Zb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'zettabit-humanized' } 1`] = `"0 Zb"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'zettabit-per-second' } 1`] = `"12,56 Zbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'zettabit-per-second-humanized' } 1`] = `"0 Zbps"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'zettabyte' } 1`] = `"12,56 Zo"`; + +exports[`formatUnit should work with maximumFractionDigits { maximumFractionDigits: 3, unit: 'zettabyte-humanized' } 1`] = `"0 Zo"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'bit' } 1`] = `"12,000 b"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'bit-humanized' } 1`] = `"12,000 b"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'bit-per-second' } 1`] = `"12,000 bps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'bit-per-second-humanized' } 1`] = `"12,000 bps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'bits-humanized' } 1`] = `"12,000 b"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'bits-per-second-humanized' } 1`] = `"12,000 bps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'byte' } 1`] = `"12,000 o"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'byte-humanized' } 1`] = `"12,000 o"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'bytes-humanized' } 1`] = `"12,000 o"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'exabit' } 1`] = `"12,000 Eb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'exabit-humanized' } 1`] = `"0,000 Eb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'exabit-per-second' } 1`] = `"12,000 Ebps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'exabit-per-second-humanized' } 1`] = `"0,000 Ebps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'exabyte' } 1`] = `"12,000 Eo"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'exabyte-humanized' } 1`] = `"0,000 Eo"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'gigabit' } 1`] = `"12,000 Gb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'gigabit-humanized' } 1`] = `"0,000 Gb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'gigabit-per-second' } 1`] = `"12,000 Gbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'gigabit-per-second-humanized' } 1`] = `"0,000 Gbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'gigabyte' } 1`] = `"12,000 Go"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'gigabyte-humanized' } 1`] = `"0,000 Go"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'kilobit' } 1`] = `"12,000 Kb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'kilobit-humanized' } 1`] = `"0,010 Kb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'kilobit-per-second' } 1`] = `"12,000 Kbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'kilobit-per-second-humanized' } 1`] = `"0,010 Kbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'kilobyte' } 1`] = `"12,000 Ko"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'kilobyte-humanized' } 1`] = `"0,010 Ko"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'megabit' } 1`] = `"12,000 Mb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'megabit-humanized' } 1`] = `"0,000 Mb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'megabit-per-second' } 1`] = `"12,000 Mbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'megabit-per-second-humanized' } 1`] = `"0,000 Mbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'megabyte' } 1`] = `"12,000 Mo"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'megabyte-humanized' } 1`] = `"0,000 Mo"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'petabit' } 1`] = `"12,000 Pb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'petabit-humanized' } 1`] = `"0,000 Pb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'petabit-per-second' } 1`] = `"12,000 Pbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'petabit-per-second-humanized' } 1`] = `"0,000 Pbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'petabyte' } 1`] = `"12,000 Po"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'petabyte-humanized' } 1`] = `"0,000 Po"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'terabit' } 1`] = `"12,000 Tb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'terabit-humanized' } 1`] = `"0,000 Tb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'terabit-per-second' } 1`] = `"12,000 Tbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'terabit-per-second-humanized' } 1`] = `"0,000 Tbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'terabyte' } 1`] = `"12,000 To"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'terabyte-humanized' } 1`] = `"0,000 To"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'yottabit' } 1`] = `"12,000 Yb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'yottabit-humanized' } 1`] = `"0,000 Yb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'yottabit-per-second' } 1`] = `"12,000 Ybps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'yottabit-per-second-humanized' } 1`] = `"0,000 Ybps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'yottabyte' } 1`] = `"12,000 Yo"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'yottabyte-humanized' } 1`] = `"0,000 Yo"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'zettabit' } 1`] = `"12,000 Zb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'zettabit-humanized' } 1`] = `"0,000 Zb"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'zettabit-per-second' } 1`] = `"12,000 Zbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'zettabit-per-second-humanized' } 1`] = `"0,000 Zbps"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'zettabyte' } 1`] = `"12,000 Zo"`; + +exports[`formatUnit should work with minimumFractionDigits { minimumFractionDigits: 3, unit: 'zettabyte-humanized' } 1`] = `"0,000 Zo"`; diff --git a/packages/use-i18n/src/__tests__/formatUnit.js b/packages/use-i18n/src/__tests__/formatUnit.js new file mode 100644 index 000000000..9b4405ae5 --- /dev/null +++ b/packages/use-i18n/src/__tests__/formatUnit.js @@ -0,0 +1,68 @@ +import memoizeIntlConstructor from 'intl-format-cache' +import IntlTranslationFormat from 'intl-messageformat' +import formatUnit, { supportedUnits } from '../formatUnit' + +const locales = ['en', 'fr', 'ro'] + +const getTranslationFormat = memoizeIntlConstructor(IntlTranslationFormat) + +const tests = [ + ...Object.keys(supportedUnits).map(unit => [ + 'should work with', + { unit }, + 'fr', + 12.56, + ]), + ...Object.keys(supportedUnits) + .map(unit => + locales.map(locale => [ + `should work with locale ${locale} and`, + { unit }, + locale, + 12.56, + ]), + ) + .flat(), + ...Object.keys(supportedUnits) + .map(unit => + locales.map(locale => [ + `should work with long format, locale ${locale} and`, + { short: false, unit }, + locale, + 12.56, + ]), + ) + .flat(), + ...Object.keys(supportedUnits).map(unit => [ + 'should work with maximumFractionDigits', + { maximumFractionDigits: 3, unit }, + 'fr', + 12.56, + ]), + ...Object.keys(supportedUnits).map(unit => [ + 'should work with minimumFractionDigits', + { minimumFractionDigits: 3, unit }, + 'fr', + 12, + ]), + ...Object.keys(supportedUnits).map(unit => [ + 'should work with large values', + { unit }, + 'fr', + 13876876883167813487687341, + ]), +] + +describe('formatUnit', () => { + test('should return empty string for unknown unit', () => { + expect( + formatUnit('fr', 123, { unit: 'unknown' }, getTranslationFormat), + ).toMatchSnapshot() + }) + + test.each(tests)('%s %o', (_, options, locale, amount) => { + expect( + formatUnit(locale, amount, options, getTranslationFormat), + ).toMatchSnapshot() + }) +}) diff --git a/packages/use-i18n/src/__tests__/index.js b/packages/use-i18n/src/__tests__/index.js index fff5919a9..050e34a19 100644 --- a/packages/use-i18n/src/__tests__/index.js +++ b/packages/use-i18n/src/__tests__/index.js @@ -501,6 +501,26 @@ describe('i18n hook', () => { expect(result.current.relativeTimeStrict(date)).toEqual('il y a 3499 jours') }) + it('should formatUnit', async () => { + const { result, waitForNextUpdate } = renderHook(() => useI18n(), { + wrapper: wrapper({ + defaultLocale: 'en', + }), + }) + + expect( + result.current.formatUnit(12, { short: false, unit: 'byte' }), + ).toEqual('12 bytes') + act(() => { + result.current.switchLocale('fr') + }) + await waitForNextUpdate() + + expect( + result.current.formatUnit(12, { short: false, unit: 'byte' }), + ).toEqual('12 octets') + }) + it('should load default datefns locales', async () => { const { result, waitForNextUpdate } = renderHook(() => useI18n(), { wrapper: wrapper({ diff --git a/packages/use-i18n/src/formatUnit.js b/packages/use-i18n/src/formatUnit.js new file mode 100644 index 000000000..da898fcc1 --- /dev/null +++ b/packages/use-i18n/src/formatUnit.js @@ -0,0 +1,188 @@ +import filesize from 'filesize' + +// We are on base 10, so we should use IEC standard here ... +const exponents = [ + { name: '', symbol: '' }, + { name: 'kilo', symbol: 'K' }, + { name: 'mega', symbol: 'M' }, + { name: 'giga', symbol: 'G' }, + { name: 'tera', symbol: 'T' }, + { name: 'peta', symbol: 'P' }, + { name: 'exa', symbol: 'E' }, + { name: 'zetta', symbol: 'Z' }, + { name: 'yotta', symbol: 'Y' }, +] + +const frOctet = { + plural: 'octets', + singular: 'octet', +} + +const localesWhoFavorOctetOverByte = { + fr: frOctet, + 'fr-ca': frOctet, + 'fr-fr': frOctet, + ro: { + plural: 'octeți', + singular: 'octet', + }, +} + +const symbols = { + long: { + bit: { + plural: 'bits', + singular: 'bit', + }, + byte: { + plural: 'bytes', + singular: 'byte', + }, + }, + short: { + bit: 'b', + byte: 'B', + octet: 'o', + }, +} + +const compoundUnitsSymbols = { + second: 'ps', +} + +const formatShortUnit = (locale, exponent, unit, compoundUnit) => { + let shortenedUnit = symbols.short[unit] + + if ( + unit === 'byte' && + Object.keys(localesWhoFavorOctetOverByte).includes(locale) + ) { + shortenedUnit = symbols.short.octet + } + + return `${exponent.symbol}${shortenedUnit}${ + compoundUnit ? compoundUnitsSymbols[compoundUnit] : '' + }` +} + +const formatLongUnit = (locale, exponent, unit, number, messageFormat) => { + let translation = symbols.long[unit] + + if ( + unit === 'byte' && + Object.keys(localesWhoFavorOctetOverByte).includes(locale) + ) { + translation = localesWhoFavorOctetOverByte[locale] + } + + return `${exponent.name}${messageFormat( + `{amount, plural, + =0 {${translation.singular}} + =1 {${translation.singular}} + other {${translation.plural}} + }`, + locale, + ).format({ amount: number })}` +} + +const format = + ({ compoundUnit, exponent, unit, humanize = false }) => + ( + locale, + number, + { maximumFractionDigits, minimumFractionDigits, short = true }, + messageFormat, + ) => { + let computedExponent = exponent + let computedValue = number + + if (humanize) { + if (!exponent) { + const value = filesize(number, { + base: 10, + output: 'object', + round: maximumFractionDigits, + }) + computedExponent = exponents[value.exponent] + computedValue = value.value + } else { + const value = filesize(number, { + base: 10, + exponent: exponents.findIndex( + exp => exp.name === computedExponent.name, + ), + output: 'object', + round: maximumFractionDigits, + }) + computedValue = value.value + } + } + + return `${new Intl.NumberFormat(locale, { + maximumFractionDigits, + minimumFractionDigits, + }).format(computedValue)} ${ + short + ? formatShortUnit(locale, computedExponent, unit, compoundUnit) + : formatLongUnit( + locale, + computedExponent, + unit, + computedValue, + messageFormat, + ) + }` + } + +export const supportedUnits = { + // bits + 'bits-humanized': format({ humanize: true, unit: 'bit' }), + 'bits-per-second-humanized': format({ + compoundUnit: 'second', + humanize: true, + unit: 'bit', + }), + ...exponents.reduce( + (acc, exponent) => ({ + ...acc, + [`${exponent.name}bit`]: format({ exponent, unit: 'bit' }), + [`${exponent.name}bit-per-second`]: format({ + compoundUnit: 'second', + exponent, + unit: 'bit', + }), + [`${exponent.name}bit-humanized`]: format({ + exponent, + humanize: true, + unit: 'bit', + }), + [`${exponent.name}bit-per-second-humanized`]: format({ + compoundUnit: 'second', + exponent, + humanize: true, + unit: 'bit', + }), + }), + {}, + ), + + // bytes + 'bytes-humanized': format({ humanize: true, unit: 'byte' }), + ...exponents.reduce( + (acc, exponent) => ({ + ...acc, + [`${exponent.name}byte`]: format({ exponent, unit: 'byte' }), + [`${exponent.name}byte-humanized`]: format({ + exponent, + humanize: true, + unit: 'byte', + }), + }), + {}, + ), +} + +const formatUnit = (locale, number, { unit, ...options }, messageFormat) => + supportedUnits?.[unit]?.(locale, number, options, messageFormat) ?? '' + +export default formatUnit diff --git a/packages/use-i18n/src/index.js b/packages/use-i18n/src/index.js index 58dc02d61..c95619e70 100644 --- a/packages/use-i18n/src/index.js +++ b/packages/use-i18n/src/index.js @@ -12,6 +12,7 @@ import React, { } from 'react' import ReactDOM from 'react-dom' import 'intl-pluralrules' +import unitFormat from './formatUnit' const LOCALE_ITEM_STORAGE = 'locale' @@ -173,6 +174,15 @@ const I18nContextProvider = ({ [currentLocale], ) + // This a temporary method + // Once https://github.com/tc39/proposal-smart-unit-preferences is stable we should + // be able to use formatNumber directly + const formatUnit = useCallback( + (value, options) => + unitFormat(currentLocale, value, options, getTranslationFormat), + [currentLocale], + ) + const datetime = useCallback( (date, options) => getDateTimeFormat(currentLocale, options).format(date), [currentLocale], @@ -235,6 +245,7 @@ const I18nContextProvider = ({ datetime, formatList, formatNumber, + formatUnit, loadTranslations, locales: supportedLocales, namespaces, @@ -252,6 +263,7 @@ const I18nContextProvider = ({ datetime, formatList, formatNumber, + formatUnit, loadTranslations, namespaceTranslation, namespaces, diff --git a/yarn.lock b/yarn.lock index 3f8c788a6..d709a0f68 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4315,6 +4315,11 @@ file-entry-cache@^6.0.1: dependencies: flat-cache "^3.0.4" +filesize@^6.4.0: + version "6.4.0" + resolved "https://registry.yarnpkg.com/filesize/-/filesize-6.4.0.tgz#914f50471dd66fdca3cefe628bd0cde4ef769bcd" + integrity sha512-mjFIpOHC4jbfcTfoh4rkWpI31mF7viw9ikj/JyLoKzqlwG/YsefKfvYlYhdYdg/9mtK2z1AzgN/0LvVQ3zdlSQ== + fill-range@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"