currencies-accepted-by-DisplayNames.js (1833B)
1 // Copyright (C) 2021 André Bargull. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-intl.supportedvaluesof 6 description: > 7 The returned "currency" values can be used with DisplayNames. 8 info: | 9 Intl.supportedValuesOf ( key ) 10 11 1. Let key be ? ToString(key). 12 ... 13 4. Else if key is "currency", then 14 a. Let list be ! AvailableCurrencies( ). 15 ... 16 9. Return ! CreateArrayFromList( list ). 17 18 AvailableCurrencies ( ) 19 The AvailableCurrencies abstract operation returns a List, ordered as if an 20 Array of the same values had been sorted using %Array.prototype.sort% using 21 undefined as comparefn, that contains unique, well-formed, and upper case 22 canonicalized 3-letter ISO 4217 currency codes, identifying the currencies 23 for which the implementation provides the functionality of Intl.DisplayNames 24 and Intl.NumberFormat objects. 25 locale: [en] 26 features: [Intl-enumeration, Intl.DisplayNames, Array.prototype.includes] 27 ---*/ 28 29 const currencies = Intl.supportedValuesOf("currency"); 30 31 const obj = new Intl.DisplayNames("en", {type: "currency", fallback: "none"}); 32 33 for (let currency of currencies) { 34 assert.sameValue(typeof obj.of(currency), "string", 35 `${currency} is supported by DisplayNames`); 36 } 37 38 for (let i = 0x41; i <= 0x5A; ++i) { 39 for (let j = 0x41; j <= 0x5A; ++j) { 40 for (let k = 0x41; k <= 0x5A; ++k) { 41 let currency = String.fromCharCode(i, j, k); 42 if (typeof obj.of(currency) === "string") { 43 assert(currencies.includes(currency), 44 `${currency} supported but not returned by supportedValuesOf`); 45 } else { 46 assert(!currencies.includes(currency), 47 `${currency} not supported but returned by supportedValuesOf`); 48 } 49 } 50 } 51 } 52 53 reportCompare(0, 0);