locale-service 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -33,7 +33,7 @@ function getLocaleFromResources(i) {
33
33
  }
34
34
  return lr[i];
35
35
  }
36
- function locale(l) {
36
+ function getLocale(l) {
37
37
  var lc = getLocaleFromResources(l);
38
38
  if (!lc) {
39
39
  var newId = map_1.map[l];
@@ -44,12 +44,12 @@ function locale(l) {
44
44
  }
45
45
  return lc;
46
46
  }
47
- exports.locale = locale;
48
- function id(lang) {
47
+ exports.getLocale = getLocale;
48
+ function getLocaleId(lang) {
49
49
  var i = map_1.map[lang];
50
50
  return i;
51
51
  }
52
- exports.id = id;
52
+ exports.getLocaleId = getLocaleId;
53
53
  var initCurrency = false;
54
54
  var cr = {};
55
55
  function initCurrencyResources() {
@@ -65,7 +65,7 @@ function initCurrencyResources() {
65
65
  cr[key] = c;
66
66
  }
67
67
  }
68
- function currency(currencyCode) {
68
+ function getCurrency(currencyCode) {
69
69
  if (!currencyCode) {
70
70
  return undefined;
71
71
  }
@@ -77,4 +77,48 @@ function currency(currencyCode) {
77
77
  var c = cr[code];
78
78
  return c;
79
79
  }
80
- exports.currency = currency;
80
+ exports.getCurrency = getCurrency;
81
+ exports.enLocale = {
82
+ id: "en-US",
83
+ countryCode: "US",
84
+ dateFormat: "M/d/yyyy",
85
+ firstDayOfWeek: 1,
86
+ decimalSeparator: ".",
87
+ groupSeparator: ",",
88
+ decimalDigits: 2,
89
+ currencyCode: "USD",
90
+ currencySymbol: "$",
91
+ currencyPattern: 0,
92
+ };
93
+ exports.usd = {
94
+ code: "USD",
95
+ symbol: "$",
96
+ decimalDigits: 2
97
+ };
98
+ var resources = (function () {
99
+ function resources() {
100
+ }
101
+ resources.defaultLocale = exports.enLocale;
102
+ resources.defaultCurrency = exports.usd;
103
+ return resources;
104
+ }());
105
+ exports.resources = resources;
106
+ function getDateFormat(lang) {
107
+ var locale = getLocale(lang);
108
+ if (locale) {
109
+ return locale.dateFormat;
110
+ }
111
+ return resources.defaultLocale.dateFormat;
112
+ }
113
+ exports.getDateFormat = getDateFormat;
114
+ function getCurrencyDecimalDigits(currencyCode) {
115
+ if (!currencyCode) {
116
+ return resources.defaultCurrency.decimalDigits;
117
+ }
118
+ var currency = getCurrency(currencyCode);
119
+ if (currency) {
120
+ return currency.decimalDigits;
121
+ }
122
+ return resources.defaultCurrency.decimalDigits;
123
+ }
124
+ exports.getCurrencyDecimalDigits = getCurrencyDecimalDigits;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locale-service",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Locale Service",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import {currencies} from './currencies';
2
- import {locales} from './locales';
3
- import {map} from './map';
1
+ import { currencies } from './currencies';
2
+ import { locales } from './locales';
3
+ import { map } from './map';
4
4
 
5
5
  let initLocale = false;
6
6
 
@@ -64,7 +64,7 @@ function getLocaleFromResources(i: string): Locale|undefined {
64
64
  }
65
65
  return lr[i];
66
66
  }
67
- export function locale(l: string): Locale|undefined {
67
+ export function getLocale(l: string): Locale|undefined {
68
68
  let lc = getLocaleFromResources(l);
69
69
  if (!lc) {
70
70
  const newId = map[l];
@@ -75,7 +75,7 @@ export function locale(l: string): Locale|undefined {
75
75
  }
76
76
  return lc;
77
77
  }
78
- export function id(lang: string): string|undefined {
78
+ export function getLocaleId(lang: string): string|undefined {
79
79
  const i = map[lang];
80
80
  return i;
81
81
  }
@@ -112,7 +112,7 @@ function initCurrencyResources(): void {
112
112
  }
113
113
  }
114
114
 
115
- export function currency(currencyCode: string): Currency|undefined {
115
+ export function getCurrency(currencyCode: string): Currency|undefined {
116
116
  if (!currencyCode) {
117
117
  return undefined;
118
118
  }
@@ -124,3 +124,46 @@ export function currency(currencyCode: string): Currency|undefined {
124
124
  const c = cr[code];
125
125
  return c;
126
126
  }
127
+
128
+ export const enLocale: Locale = {
129
+ id: "en-US",
130
+ countryCode: "US",
131
+ dateFormat: "M/d/yyyy",
132
+ firstDayOfWeek: 1,
133
+ decimalSeparator: ".",
134
+ groupSeparator: ",",
135
+ decimalDigits: 2,
136
+ currencyCode: "USD",
137
+ currencySymbol: "$",
138
+ currencyPattern: 0,
139
+ }
140
+
141
+ export const usd: Currency = {
142
+ code: "USD",
143
+ symbol: "$",
144
+ decimalDigits: 2
145
+ }
146
+
147
+ // tslint:disable-next-line:class-name
148
+ export class resources {
149
+ static defaultLocale = enLocale
150
+ static defaultCurrency = usd
151
+ }
152
+
153
+ export function getDateFormat(lang: string): string {
154
+ const locale = getLocale(lang)
155
+ if (locale) {
156
+ return locale.dateFormat
157
+ }
158
+ return resources.defaultLocale.dateFormat
159
+ }
160
+ export function getCurrencyDecimalDigits(currencyCode?: string): number {
161
+ if (!currencyCode) {
162
+ return resources.defaultCurrency.decimalDigits
163
+ }
164
+ const currency = getCurrency(currencyCode)
165
+ if (currency) {
166
+ return currency.decimalDigits
167
+ }
168
+ return resources.defaultCurrency.decimalDigits
169
+ }