number-to-locale-string
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "number-to-locale-string", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A polyfill to add support for Number.toLocaleString with locales to browsers that don't support it.", | ||
@@ -5,0 +5,0 @@ "main": "polyfill.number.toLocaleString.js", |
@@ -79,2 +79,11 @@ // polyfill.number.toLocaleDateString | ||
}; | ||
var apostrophThousDotDec = function(sNum) { | ||
var seperators = { | ||
decimal: '.', | ||
thousands: '\u0027' | ||
}; | ||
return replaceSeparators(sNum, seperators); | ||
}; | ||
@@ -88,7 +97,11 @@ var transformForLocale = { | ||
"de-AT": dotThousCommaDec, | ||
"de-CH": dotThousCommaDec, | ||
"de-LI": dotThousCommaDec, | ||
"de-CH": apostrophThousDotDec, | ||
"de-LI": apostrophThousDotDec, | ||
"de-BE": dotThousCommaDec, | ||
ro: dotThousCommaDec, | ||
"ro-RO": dotThousCommaDec, | ||
hu: spaceThousCommaDec, | ||
"hu-HU": spaceThousCommaDec, | ||
"da-DK": dotThousCommaDec, | ||
"nb-NO": spaceThousCommaDec | ||
}; | ||
@@ -107,10 +120,126 @@ | ||
ro: "post", | ||
"ro-RO": "post" | ||
"ro-RO": "post", | ||
hu: "post", | ||
"hu-HU": "post", | ||
"da-DK": "post", | ||
"nb-NO": "post" | ||
}; | ||
var currencySymbols = { | ||
"eur": "€", | ||
"usd": "$", | ||
"ron": "RON" | ||
} | ||
"afn": "؋", | ||
"ars": "$", | ||
"awg": "ƒ", | ||
"aud": "$", | ||
"azn": "₼", | ||
"bsd": "$", | ||
"bbd": "$", | ||
"byr": "p.", | ||
"bzd": "BZ$", | ||
"bmd": "$", | ||
"bob": "Bs.", | ||
"bam": "KM", | ||
"bwp": "P", | ||
"bgn": "лв", | ||
"brl": "R$", | ||
"bnd": "$", | ||
"khr": "៛", | ||
"cad": "$", | ||
"kyd": "$", | ||
"clp": "$", | ||
"cny": "¥", | ||
"cop": "$", | ||
"crc": "₡", | ||
"hrk": "kn", | ||
"cup": "₱", | ||
"czk": "Kč", | ||
"dkk": "kr", | ||
"dop": "RD$", | ||
"xcd": "$", | ||
"egp": "£", | ||
"svc": "$", | ||
"eek": "kr", | ||
"eur": "€", | ||
"fkp": "£", | ||
"fjd": "$", | ||
"ghc": "¢", | ||
"gip": "£", | ||
"gtq": "Q", | ||
"ggp": "£", | ||
"gyd": "$", | ||
"hnl": "L", | ||
"hkd": "$", | ||
"huf": "Ft", | ||
"isk": "kr", | ||
"inr": "₹", | ||
"idr": "Rp", | ||
"irr": "﷼", | ||
"imp": "£", | ||
"ils": "₪", | ||
"jmd": "J$", | ||
"jpy": "¥", | ||
"jep": "£", | ||
"kes": "KSh", | ||
"kzt": "лв", | ||
"kpw": "₩", | ||
"krw": "₩", | ||
"kgs": "лв", | ||
"lak": "₭", | ||
"lvl": "Ls", | ||
"lbp": "£", | ||
"lrd": "$", | ||
"ltl": "Lt", | ||
"mkd": "ден", | ||
"myr": "RM", | ||
"mur": "₨", | ||
"mxn": "$", | ||
"mnt": "₮", | ||
"mzn": "MT", | ||
"nad": "$", | ||
"npr": "₨", | ||
"ang": "ƒ", | ||
"nzd": "$", | ||
"nio": "C$", | ||
"ngn": "₦", | ||
"nok": "kr", | ||
"omr": "﷼", | ||
"pkr": "₨", | ||
"pab": "B/.", | ||
"pyg": "Gs", | ||
"pen": "S/.", | ||
"php": "₱", | ||
"pln": "zł", | ||
"qar": "﷼", | ||
"ron": "lei", | ||
"rub": "₽", | ||
"shp": "£", | ||
"sar": "﷼", | ||
"rsd": "Дин.", | ||
"scr": "₨", | ||
"sgd": "$", | ||
"sbd": "$", | ||
"sos": "S", | ||
"zar": "R", | ||
"lkr": "₨", | ||
"sek": "kr", | ||
"chf": "CHF", | ||
"srd": "$", | ||
"syp": "£", | ||
"tzs": "TSh", | ||
"twd": "NT$", | ||
"thb": "฿", | ||
"ttd": "TT$", | ||
"try": "", | ||
"trl": "₤", | ||
"tvd": "$", | ||
"ugx": "USh", | ||
"uah": "₴", | ||
"gbp": "£", | ||
"usd": "$", | ||
"uyu": "$U", | ||
"uzs": "лв", | ||
"vef": "Bs", | ||
"vnd": "₫", | ||
"yer": "﷼", | ||
"zwd": "Z$" | ||
}; | ||
@@ -139,3 +268,3 @@ var currencyFormats = { | ||
var format = currencyFormats[mapMatch(currencyFormatMap, locale)]; | ||
if(options.currencyDisplay === "code") { | ||
if(options.currencyDisplay === "code") { | ||
sNum = renderFormat(format, { | ||
@@ -145,3 +274,3 @@ num: sNum, | ||
}); | ||
} else { | ||
} else { | ||
sNum = renderFormat(format, { | ||
@@ -151,3 +280,3 @@ num: sNum, | ||
}); | ||
} | ||
} | ||
} | ||
@@ -154,0 +283,0 @@ |
@@ -14,3 +14,3 @@ // polyfill.number.toLocaleString | ||
} | ||
expect(testLocale).not.toThrow(); | ||
@@ -22,2 +22,3 @@ }); | ||
var locale = 'CA'; | ||
expect(typeof (num.toLocaleString(locale))).toBe('string'); | ||
@@ -46,2 +47,9 @@ }); | ||
}); | ||
it("returns a string formatted in de-CH style (1'234.5) when passed de-CH", function() { | ||
var num = 1234.5; | ||
var locale = 'de-CH'; | ||
expect(num.toLocaleString(locale)).toBe("1'234.5"); | ||
}); | ||
@@ -53,4 +61,26 @@ it('returns a formatted string based only on the language code in complex locale codes', function() { | ||
expect(num.toLocaleString(locale)).toBe('1.234,5'); | ||
}) | ||
}); | ||
it('returns a string formatted in KR style (1,234.5) when passed KR', function() { | ||
var num = 1234.5; | ||
var locale = 'KR'; | ||
expect(num.toLocaleString(locale)).toBe('1,234.5'); | ||
}); | ||
it('returns a string formatted in DK style (1.234,5) when passed da-DK', function() { | ||
var num = 1234.5; | ||
var locale = 'da-DK'; | ||
expect(num.toLocaleString(locale)).toBe('1.234,5'); | ||
}); | ||
it('returns a string formatted in NO style (1 234,5) when passed nb-NO', function() { | ||
var num = 1234.5; | ||
var locale = 'nb-NO'; | ||
expect(num.toLocaleString(locale)).toBe('1\u00A0234,5'); | ||
}); | ||
it('throws when the language tag does not conform to the standard', function() { | ||
@@ -83,3 +113,3 @@ var num = 1234.5; | ||
var num = 1234.5; | ||
expect(num.toLocaleString()).toBe('1,234.5'); | ||
@@ -90,2 +120,9 @@ expect(num.toLocaleString('MX')).toBe('1,234.5'); | ||
it('returns a string formatted in Hungarian style (1 234,56) by default', function() { | ||
var num = 1234.56; | ||
expect(num.toLocaleString('hu')).toBe('1\u00A0234,56'); | ||
expect(num.toLocaleString('hu-HU')).toBe('1\u00A0234,56'); | ||
}); | ||
it('returns currency properly formatted for the locale specified', function() { | ||
@@ -106,3 +143,43 @@ var num = 1234.56; | ||
})).toBe("1.234,56 $"); | ||
expect(num.toLocaleString("ko-KR", { | ||
style: style, | ||
currency: "krw" | ||
})).toBe("₩1,234.56"); | ||
expect(num.toLocaleString("ja-JP", { | ||
style: style, | ||
currency: "jpy" | ||
})).toBe("¥1,234.56"); | ||
expect(num.toLocaleString("hu", { | ||
style: style, | ||
currency: "huf" | ||
})).toBe("1\u00A0234,56 Ft"); | ||
expect(num.toLocaleString("hu-HU", { | ||
style: style, | ||
currency: "huf" | ||
})).toBe("1\u00A0234,56 Ft"); | ||
expect(num.toLocaleString("da-DK", { | ||
style: style, | ||
currency: "DKK" | ||
})).toBe("1.234,56 kr"); | ||
expect(num.toLocaleString("nb-NO", { | ||
style: style, | ||
currency: "NOK" | ||
})).toBe("1\u00A0234,56 kr"); | ||
expect(num.toLocaleString("ph-PH", { | ||
style: style, | ||
currency: "php" | ||
})).toBe("₱1,234.56"); | ||
expect(num.toLocaleString("vi-VN", { | ||
style: style, | ||
currency: "vnd" | ||
})).toBe("₫1,234.56"); | ||
}); | ||
}); |
polyfill-Number.toLocaleString-with-Locales | ||
=========================================== | ||
Published on NPM at number-to-locale-string | ||
A polyfill to allow locales to be passed to Number.toLocaleString. | ||
@@ -5,0 +7,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149730
12
3806
12
1