ui-formatter 0.0.3 → 0.0.5
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 +6 -21
- package/package.json +1 -1
- package/src/index.ts +9 -22
package/lib/index.js
CHANGED
|
@@ -157,7 +157,7 @@ function pad3(n) {
|
|
|
157
157
|
return n < 10 ? "00" + n : "0" + n.toString();
|
|
158
158
|
}
|
|
159
159
|
function formatNumber(v, scale, d, g) {
|
|
160
|
-
if (
|
|
160
|
+
if (v == null) {
|
|
161
161
|
return "";
|
|
162
162
|
}
|
|
163
163
|
if (!d && !g) {
|
|
@@ -190,28 +190,12 @@ exports.formatNumber = formatNumber;
|
|
|
190
190
|
var formatter = (function () {
|
|
191
191
|
function formatter() {
|
|
192
192
|
}
|
|
193
|
-
formatter.removePhoneFormat = function (phone) {
|
|
194
|
-
if (phone) {
|
|
195
|
-
return phone.replace(formatter.phone, "");
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
return phone;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
formatter.removeFaxFormat = function (fax) {
|
|
202
|
-
if (fax) {
|
|
203
|
-
return fax.replace(formatter.phone, "");
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
return fax;
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
193
|
formatter.formatPhone = function (phone) {
|
|
210
194
|
if (!phone) {
|
|
211
195
|
return "";
|
|
212
196
|
}
|
|
213
197
|
var s = phone;
|
|
214
|
-
var x =
|
|
198
|
+
var x = removePhoneFormat(phone);
|
|
215
199
|
if (x.length === 10) {
|
|
216
200
|
var USNumber = x.match(formatter.usPhone);
|
|
217
201
|
if (USNumber != null) {
|
|
@@ -238,7 +222,7 @@ var formatter = (function () {
|
|
|
238
222
|
return "";
|
|
239
223
|
}
|
|
240
224
|
var s = fax;
|
|
241
|
-
var x =
|
|
225
|
+
var x = removePhoneFormat(fax);
|
|
242
226
|
var l = x.length;
|
|
243
227
|
if (l <= 6) {
|
|
244
228
|
s = x;
|
|
@@ -263,17 +247,18 @@ var formatter = (function () {
|
|
|
263
247
|
}
|
|
264
248
|
return s;
|
|
265
249
|
};
|
|
250
|
+
formatter.fax = / |\-|\.|\(|\)/g;
|
|
266
251
|
formatter.phone = / |\-|\.|\(|\)/g;
|
|
267
252
|
formatter.usPhone = /(\d{3})(\d{3})(\d{4})/;
|
|
268
253
|
return formatter;
|
|
269
254
|
}());
|
|
270
255
|
exports.formatter = formatter;
|
|
271
256
|
function removePhoneFormat(phone) {
|
|
272
|
-
return formatter.
|
|
257
|
+
return phone ? phone.replace(formatter.phone, "") : "";
|
|
273
258
|
}
|
|
274
259
|
exports.removePhoneFormat = removePhoneFormat;
|
|
275
260
|
function removeFaxFormat(fax) {
|
|
276
|
-
return formatter.
|
|
261
|
+
return fax ? fax.replace(formatter.fax, "") : "";
|
|
277
262
|
}
|
|
278
263
|
exports.removeFaxFormat = removeFaxFormat;
|
|
279
264
|
function formatPhone(phone) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -145,8 +145,8 @@ function pad3(n: number): string {
|
|
|
145
145
|
return n < 10 ? "00" + n : "0" + n.toString()
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
export function formatNumber(v
|
|
149
|
-
if (
|
|
148
|
+
export function formatNumber(v?: number | null, scale?: number, d?: string | null, g?: string): any {
|
|
149
|
+
if (v == null) {
|
|
150
150
|
return ""
|
|
151
151
|
}
|
|
152
152
|
if (!d && !g) {
|
|
@@ -177,22 +177,9 @@ export function formatNumber(v: number, scale?: number, d?: string | null, g?: s
|
|
|
177
177
|
// tslint:disable-next-line:class-name
|
|
178
178
|
export class formatter {
|
|
179
179
|
// private static _preg = / |\+|\-|\.|\(|\)/g;
|
|
180
|
+
static fax = / |\-|\.|\(|\)/g
|
|
180
181
|
static phone = / |\-|\.|\(|\)/g
|
|
181
182
|
static usPhone = /(\d{3})(\d{3})(\d{4})/
|
|
182
|
-
static removePhoneFormat(phone: string): string {
|
|
183
|
-
if (phone) {
|
|
184
|
-
return phone.replace(formatter.phone, "")
|
|
185
|
-
} else {
|
|
186
|
-
return phone
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
static removeFaxFormat(fax: string): string {
|
|
190
|
-
if (fax) {
|
|
191
|
-
return fax.replace(formatter.phone, "")
|
|
192
|
-
} else {
|
|
193
|
-
return fax
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
183
|
static formatPhone(phone?: string | null): string {
|
|
197
184
|
if (!phone) {
|
|
198
185
|
return ""
|
|
@@ -200,7 +187,7 @@ export class formatter {
|
|
|
200
187
|
// reformat phone number
|
|
201
188
|
// 555 123-4567 or (+1) 555 123-4567
|
|
202
189
|
let s = phone
|
|
203
|
-
const x =
|
|
190
|
+
const x = removePhoneFormat(phone)
|
|
204
191
|
if (x.length === 10) {
|
|
205
192
|
const USNumber = x.match(formatter.usPhone)
|
|
206
193
|
if (USNumber != null) {
|
|
@@ -226,7 +213,7 @@ export class formatter {
|
|
|
226
213
|
// reformat phone number
|
|
227
214
|
// 035-456745 or 02-1234567
|
|
228
215
|
let s = fax
|
|
229
|
-
const x =
|
|
216
|
+
const x = removePhoneFormat(fax)
|
|
230
217
|
const l = x.length
|
|
231
218
|
if (l <= 6) {
|
|
232
219
|
s = x
|
|
@@ -248,11 +235,11 @@ export class formatter {
|
|
|
248
235
|
return s
|
|
249
236
|
}
|
|
250
237
|
}
|
|
251
|
-
export function removePhoneFormat(phone
|
|
252
|
-
return formatter.
|
|
238
|
+
export function removePhoneFormat(phone?: string): string {
|
|
239
|
+
return phone ? phone.replace(formatter.phone, "") : ""
|
|
253
240
|
}
|
|
254
|
-
export function removeFaxFormat(fax
|
|
255
|
-
return formatter.
|
|
241
|
+
export function removeFaxFormat(fax?: string): string {
|
|
242
|
+
return fax ? fax.replace(formatter.fax, "") : ""
|
|
256
243
|
}
|
|
257
244
|
export function formatPhone(phone?: string | null): string {
|
|
258
245
|
return formatter.formatPhone(phone)
|