File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+ const common = require ( './lib/common.js' ) ;
3
+
4
+ const factory = globals => {
5
+ return function ( price , locale ) {
6
+
7
+ if ( ! common . isObject ( price ) || ! common . isString ( price . currency ) || isNaN ( price . value ) ) {
8
+ // Return empty string if this does not appear to be a price object
9
+ return ''
10
+ }
11
+
12
+ if ( ! common . isString ( locale ) || locale . length < 2 ) {
13
+ // Valid browser language strings are at least two characters
14
+ // https://www.metamodpro.com/browser-language-codes
15
+ // If provided locale is less than two characters (or not a string),
16
+ // Default to 'en-US'
17
+ locale = 'en-US' ;
18
+ }
19
+
20
+ return new Intl . NumberFormat (
21
+ locale , { style : 'currency' , currency : price . currency }
22
+ ) . format ( price . value ) ;
23
+
24
+ } ;
25
+ } ;
26
+
27
+ module . exports = [ {
28
+ name : 'localizePrice' ,
29
+ factory : factory ,
30
+ } ] ;
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ describe('helper registration', () => {
39
39
'lang' ,
40
40
'langJson' ,
41
41
'limit' ,
42
+ 'localizePrice' ,
42
43
'money' ,
43
44
'nl2br' ,
44
45
'or' ,
You can’t perform that action at this time.
0 commit comments