currencies.js (1826B)
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 are sorted, unique, and upper-case canonicalised. 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 includes: [compareArray.js] 26 features: [Intl-enumeration] 27 ---*/ 28 29 const currencies = Intl.supportedValuesOf("currency"); 30 31 assert(Array.isArray(currencies), "Returns an Array object."); 32 assert.sameValue(Object.getPrototypeOf(currencies), Array.prototype, 33 "The array prototype is Array.prototype"); 34 35 const otherCurrencies = Intl.supportedValuesOf("currency"); 36 assert.notSameValue(otherCurrencies, currencies, 37 "Returns a new array object for each call."); 38 39 assert.compareArray(currencies, otherCurrencies.sort(), 40 "The array is sorted."); 41 42 assert.sameValue(new Set(currencies).size, currencies.length, 43 "The array doesn't contain duplicates."); 44 45 const codeRE = /^[A-Z]{3}$/; 46 for (let currency of currencies) { 47 assert(codeRE.test(currency), `${currency} is a 3-letter ISO 4217 currency code`); 48 } 49 50 reportCompare(0, 0);