nmce-func 0.0.4 → 0.0.8
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/_func/addressFunc.d.ts +31 -0
- package/_func/authentication.service.d.ts +27 -0
- package/_func/currencyFunc.d.ts +20 -0
- package/_func/dateFunc.d.ts +121 -0
- package/_func/htmlPrintFunc.d.ts +18 -0
- package/_func/index.d.ts +10 -0
- package/_func/javascriptFunc.d.ts +9 -0
- package/_func/jsonFunc.d.ts +31 -0
- package/_func/stringAusFunc.d.ts +40 -0
- package/_func/stringFunc.d.ts +41 -0
- package/_func/uuidFunc.d.ts +7 -0
- package/esm2020/_func/addressFunc.mjs +49 -0
- package/esm2020/_func/authentication.service.mjs +43 -0
- package/esm2020/_func/currencyFunc.mjs +72 -0
- package/esm2020/_func/dateFunc.mjs +316 -0
- package/esm2020/_func/htmlPrintFunc.mjs +45 -0
- package/esm2020/_func/index.mjs +11 -0
- package/esm2020/_func/javascriptFunc.mjs +17 -0
- package/esm2020/_func/jsonFunc.mjs +67 -0
- package/esm2020/_func/stringAusFunc.mjs +200 -0
- package/esm2020/_func/stringFunc.mjs +93 -0
- package/esm2020/_func/uuidFunc.mjs +17 -0
- package/esm2020/nmce-func.mjs +5 -0
- package/esm2020/public-api.mjs +5 -0
- package/fesm2015/nmce-func.mjs +931 -0
- package/fesm2015/nmce-func.mjs.map +1 -0
- package/fesm2020/nmce-func.mjs +929 -0
- package/fesm2020/nmce-func.mjs.map +1 -0
- package/nmce-func.d.ts +5 -0
- package/package.json +33 -7
- package/public-api.d.ts +1 -0
- package/karma.conf.js +0 -44
- package/ng-package.json +0 -11
- package/src/_func/addressFunc.spec.ts +0 -12
- package/src/_func/addressFunc.ts +0 -54
- package/src/_func/authentication.service.ts +0 -47
- package/src/_func/currencyFunc.ts +0 -71
- package/src/_func/dateFunc.spec.ts +0 -191
- package/src/_func/dateFunc.ts +0 -385
- package/src/_func/helperFunc.ts +0 -27
- package/src/_func/htmlFunc.ts +0 -46
- package/src/_func/index.ts +0 -9
- package/src/_func/jsFunc.ts +0 -48
- package/src/_func/stringFunc.spec.ts +0 -142
- package/src/_func/stringFunc.ts +0 -337
- package/src/public-api.ts +0 -5
- package/src/test.ts +0 -26
- package/tsconfig.lib.json +0 -25
- package/tsconfig.lib.prod.json +0 -11
- package/tsconfig.spec.json +0 -17
- package/tslint.json +0 -17
package/src/_func/dateFunc.ts
DELETED
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
import moment from 'moment';
|
|
2
|
-
|
|
3
|
-
export class DateFunc {
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Transform UTC DateTime to local date without H, M and S. For example, the month day of 2018-01-23T22:00:00Z is 24 in Australia.
|
|
7
|
-
* @param dtUtc
|
|
8
|
-
* @param offsetMinutes if not defined, it will be new Date().getTimezoneOffset(). //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
|
|
9
|
-
*/
|
|
10
|
-
static dateTimeUtcToLocalDateNumber(dtUtc: Date): number {
|
|
11
|
-
if (!dtUtc) {
|
|
12
|
-
return 0; //0 is better for calculation by the clients.
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const localDt = DateFunc.dateTimeUtcToLocalDateTime(dtUtc);
|
|
16
|
-
const localDNum = localDt.setHours(0, 0, 0, 0);
|
|
17
|
-
|
|
18
|
-
return localDNum;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Date only. However, the date may still be in UTC.
|
|
23
|
-
* @param dtUtc
|
|
24
|
-
*/
|
|
25
|
-
static dateTimeUtcToLocalDate(dtUtc: Date): Date {
|
|
26
|
-
if (!dtUtc) {
|
|
27
|
-
return dtUtc;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const localDt = DateFunc.dateTimeUtcToLocalDateTime(dtUtc);
|
|
31
|
-
const localD = localDt.setHours(0, 0, 0, 0);
|
|
32
|
-
return new Date(localD);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static localISODateString(dtUtc: Date): string {
|
|
36
|
-
const dt = moment(dtUtc).local();
|
|
37
|
-
return dt.format('YYYY-MM-DD');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* locate date ONLY (no time) to UTC date.
|
|
42
|
-
* @param dt if dt contain time info, it will become dt.setHours(0, 0, 0, 0)
|
|
43
|
-
*/
|
|
44
|
-
static localDateToUtc(d: Date | number | string): Date | undefined {
|
|
45
|
-
if (!d) {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const dt = moment(d).toDate();
|
|
50
|
-
const n = dt.setHours(0, 0, 0, 0);
|
|
51
|
-
const offset = dt.getTimezoneOffset() * 60000;
|
|
52
|
-
return new Date(n + offset);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static getTimezoneOffset(): number {
|
|
56
|
-
const dt = this.today;
|
|
57
|
-
return dt.getTimezoneOffset();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Transform UTC DateTime to local dateTime.
|
|
62
|
-
* @param dtUtc
|
|
63
|
-
* @param offsetMinutes if not defined, it will be new Date().getTimezoneOffset(). //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
|
|
64
|
-
*/
|
|
65
|
-
static dateTimeUtcToLocalDateTime(dtUtc: Date): Date {
|
|
66
|
-
if (!dtUtc) {
|
|
67
|
-
return dtUtc;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const stillUtc = moment.utc(dtUtc).toDate();
|
|
71
|
-
return moment(stillUtc).local().toDate();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
static dateTimeUtcToLocaMoment(dtUtc: Date): moment.Moment {
|
|
75
|
-
if (!dtUtc) {
|
|
76
|
-
return dtUtc;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const stillUtc = moment.utc(dtUtc);
|
|
80
|
-
return stillUtc.local();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
static getEndOfWeek(dt: Date | number) {
|
|
84
|
-
// return new Date(dt.getFullYear(), dt.getMonth(), dt.getDate() + 6 - dt.getDay(), 23, 59, 59, 999);
|
|
85
|
-
return moment(dt).endOf('isoWeek').toDate();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static getStartOfWeek(dt: Date | number) {
|
|
89
|
-
return moment(dt).startOf('isoWeek').toDate();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static getEndOfMonth(dt: Date | number) {
|
|
93
|
-
// return new Date(dt.getFullYear(), dt.getMonth() + 1, 0, 23, 59, 59, 999);
|
|
94
|
-
return moment(dt).endOf('month').toDate();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
static getStartOfMonth(dt: Date | number) {
|
|
98
|
-
return moment(dt).startOf('month').toDate();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
static getDaysBetweenDates(dt1: Date, dt2: Date) {
|
|
102
|
-
//const timeDiff = Math.abs(dt2.getTime() - dt1.getTime());
|
|
103
|
-
//return Math.trunc(timeDiff / (1000 * 3600 * 24));
|
|
104
|
-
return this.getDaysBetween(dt1, dt2);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
static getEndOfDate(dt: Date): Date {
|
|
108
|
-
return new Date(dt.setHours(23, 59, 59, 999));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
static getStartOfDate(dt: Date): Date {
|
|
112
|
-
return moment(dt).startOf('day').toDate();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
static getEndOfToday(): Date {
|
|
116
|
-
// return new Date((new Date(Date.now())).setHours(23, 59, 59, 999));
|
|
117
|
-
return moment(Date.now()).endOf('day').toDate();
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
static getStartOfToday(): Date {
|
|
122
|
-
// return new Date((new Date(Date.now())).setHours(0, 0, 0, 0));
|
|
123
|
-
return moment(Date.now()).startOf('day').toDate();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
//inspired https://stackoverflow.com/questions/563406/add-days-to-javascript-date
|
|
127
|
-
static addDays(dt: Date, days: number) {
|
|
128
|
-
const dat = moment(dt);
|
|
129
|
-
dat.add(days, 'days');
|
|
130
|
-
return dat.toDate();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
static subtractDays(dt: Date, days: number) {
|
|
134
|
-
const dat = moment(dt);
|
|
135
|
-
dat.subtract(days, 'days');
|
|
136
|
-
return dat.toDate();
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Start of today
|
|
141
|
-
*/
|
|
142
|
-
static get today(): Date {
|
|
143
|
-
return this.getStartOfToday();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
static get now(): Date {
|
|
147
|
-
return new Date(Date.now());
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
static getNext5MinuteMark(): Date {
|
|
151
|
-
const m = moment().set('second', 0).set('millisecond', 0);
|
|
152
|
-
const minute = m.minute();
|
|
153
|
-
const mod = minute % 5;
|
|
154
|
-
if (mod) {
|
|
155
|
-
const delta = 5 - mod;
|
|
156
|
-
return m.add(delta, 'm').toDate();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return m.toDate();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
static getYMD(d: Date) {
|
|
163
|
-
return moment(d).format('YYYYMMDD');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
static getDMYWithSlash(d: Date) {
|
|
167
|
-
return moment(d).format('DD/MM/YYYY');
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
static getDMYHmWithSlash(d: Date) {
|
|
171
|
-
return moment(d).format('DD/MM/YYYY HH:mm');
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
static getMcpTime(dt: Date) {
|
|
175
|
-
return moment(dt).format('HH:mm:ss.SSSZ');
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* In 24 hour format
|
|
180
|
-
* @param dtUtc
|
|
181
|
-
*/
|
|
182
|
-
static getLocalDMYHmWithSlash(dtUtc: Date) {
|
|
183
|
-
const d = DateFunc.dateTimeUtcToLocalDateTime(dtUtc);
|
|
184
|
-
return moment(d).format('DD/MM/YYYY HH:mm');
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Offset minutes comparing with today
|
|
189
|
-
*/
|
|
190
|
-
static getOffsetMinutes(dtUtc: Date | number): number {
|
|
191
|
-
const dm1 = moment(dtUtc);
|
|
192
|
-
const dm2 = moment(new Date().setHours(0, 0, 0, 0));
|
|
193
|
-
return dm1.diff(dm2, 'minutes');
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
static getDaysBetween(d1: Date | number, d2: Date | number): number {
|
|
197
|
-
const dm1 = moment(d1);
|
|
198
|
-
const dm2 = moment(d2);
|
|
199
|
-
return dm2.diff(dm1, 'days');
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Get hour of the date. If Date is not defined, the hour will be current hour.
|
|
204
|
-
* @param dtUtc
|
|
205
|
-
*/
|
|
206
|
-
static getHour(dtUtc: Date | number): number {
|
|
207
|
-
const m = moment(dtUtc);
|
|
208
|
-
return m.hours();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
static getMinute(dtUtc: Date | number): number {
|
|
212
|
-
const m = moment(dtUtc);
|
|
213
|
-
return m.minutes();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
static composeDateTime(dt: Date, h: number, minute?: number): Date {
|
|
217
|
-
if (!dt) {
|
|
218
|
-
return dt;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const mt = moment(dt);
|
|
222
|
-
return new Date(mt.toDate().setHours(h, minute, 0, 0));
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
static olderThan24Hours(d: Date): boolean {
|
|
226
|
-
const m = moment(d);
|
|
227
|
-
return moment().diff(m, 'hours') >= 24;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
static olderThan24HoursUtc(dtUtc: Date): boolean {
|
|
231
|
-
return DateFunc.getHourAgeUtc(dtUtc) >= 24;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
static olderThanHours(d: Date, hours: number) {
|
|
235
|
-
const m = moment(d);
|
|
236
|
-
return moment().diff(m, 'hours') >= hours;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
static olderThanHoursUtc(dtUtc: Date, hours: number): boolean {
|
|
240
|
-
return DateFunc.getHourAgeUtc(dtUtc) >= hours;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
static olderThanMinutes(d: Date, minutes: number) {
|
|
244
|
-
const m = moment(d);
|
|
245
|
-
return moment().diff(m, 'minutes') >= minutes;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* It could be 11PM yesterday, and 1 AM today. Actually based on local today.
|
|
250
|
-
*/
|
|
251
|
-
static olderThan1Day(dtUtc: Date): boolean {
|
|
252
|
-
return DateFunc.getDayAgeUtc(dtUtc) > 0;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
static getHourAge(d: Date) {
|
|
256
|
-
const m = moment(d);
|
|
257
|
-
return moment().diff(m, 'hours');
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
static getHourAgeUtc(dtUtc: Date) {
|
|
261
|
-
const m = moment.utc(dtUtc);
|
|
262
|
-
return moment.utc().diff(m, 'hours');
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Compare utc date with utc now.
|
|
267
|
-
* @param dtUtc
|
|
268
|
-
*/
|
|
269
|
-
static getDayAgeUtc(dtUtc: Date) {
|
|
270
|
-
const m = moment.utc(dtUtc);
|
|
271
|
-
return moment.utc().diff(m, 'days');
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
static getAge(d: Date) {
|
|
275
|
-
const m = moment(d);
|
|
276
|
-
return moment().diff(m, 'years');
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
static getYear(d: Date) {
|
|
280
|
-
const m = moment(d);
|
|
281
|
-
return m.year();
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
static getUtcNow(): Date {
|
|
285
|
-
return moment.utc().toDate();
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
static addMinutes(d: Date, m: number): Date {
|
|
289
|
-
return moment(d).add(m, 'm').toDate();
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
static addMonth(d: Date, m: number): Date {
|
|
293
|
-
return moment(d).add(m, 'M').toDate();
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
static getDuration(d1: Date, d2: Date) {
|
|
297
|
-
const md1 = moment(d1);
|
|
298
|
-
const md2 = moment(d2);
|
|
299
|
-
return moment.duration(md2.diff(md1));
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Convert minutes from midnight to HH:mm text
|
|
304
|
-
* @param mins
|
|
305
|
-
*/
|
|
306
|
-
static getHMFromMins(mins: number): string {
|
|
307
|
-
// do not include the first validation check if you want, for example,
|
|
308
|
-
// getTimeFromMins(1530) to equal getTimeFromMins(90) (i.e. mins rollover)
|
|
309
|
-
if (mins >= 24 * 60 || mins < 0) {
|
|
310
|
-
throw new RangeError('Valid input should be greater than or equal to 0 and less than 1440.');
|
|
311
|
-
}
|
|
312
|
-
const h = mins / 60 | 0,
|
|
313
|
-
m = mins % 60 | 0;
|
|
314
|
-
return moment.utc().hours(h).minutes(m).format('HH:mm');
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
static getMinutesSinceMidnight(d: Date) {
|
|
318
|
-
const m = moment(d);
|
|
319
|
-
const midnight = moment(d).startOf('day'); //Mutates the original moment by setting it to the start of a unit of time. So I have better not to use m which wil be changed by calling this function
|
|
320
|
-
return m.diff(midnight, 'minutes');
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
static getMinutesBetween(start: Date, end: Date) {
|
|
324
|
-
const m = moment(start);
|
|
325
|
-
const m2 = moment(end);
|
|
326
|
-
return m2.diff(m, 'minutes');
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Parse json string with date serialized into string, and get proper date object back
|
|
331
|
-
* @param s
|
|
332
|
-
*/
|
|
333
|
-
static dateSafeJsonParse(s: string) {
|
|
334
|
-
return JSON.parse(s, this.dateReviver);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
private static dateReviver(key: string, value: any) {
|
|
338
|
-
if (DateFunc.isSerializedDate(value)) {
|
|
339
|
-
return (new Date(value));
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// If it's not a date-string, we want to return the value as-is. If we fail to return
|
|
343
|
-
// a value, it will be omitted from the resultant data structure.
|
|
344
|
-
return (value);
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
// I determine if the given value is a string that matches the serialized-date pattern.
|
|
350
|
-
private static isSerializedDate(value: any): boolean {
|
|
351
|
-
// Dates are serialized in TZ format, example: '1981-12-20T04:00:14.000Z'.
|
|
352
|
-
const datePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
353
|
-
return (DateFunc.isString(value) && datePattern.test(value));
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
// I determine if the given value is a String.
|
|
358
|
-
private static isString(value: any): boolean {
|
|
359
|
-
return ({}.toString.call(value) === '[object String]');
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
static dateSafeParse(s: string | Date) {
|
|
363
|
-
const m = moment(s);
|
|
364
|
-
return m.toDate();
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
static composeDateWithMinutes(d: Date, minute: number): Date {
|
|
368
|
-
const m = moment(d);
|
|
369
|
-
const midnight = moment(d).startOf('day'); // Mutates the original moment by setting it to the start of a unit of time. So I have better not to use m which wil be changed by calling this function
|
|
370
|
-
midnight.add(minute, 'minutes');
|
|
371
|
-
return midnight.toDate();
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Safe compare since date data may be considered as string rather than date.
|
|
376
|
-
* @param d1
|
|
377
|
-
* @param d2
|
|
378
|
-
*/
|
|
379
|
-
static compare(d1: Date, d2: Date): number {
|
|
380
|
-
const dd1 = (new Date(d1)).valueOf();
|
|
381
|
-
const dd2 = (new Date(d2)).valueOf();
|
|
382
|
-
return dd1 - dd2;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
package/src/_func/helperFunc.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { v4 as uuid } from 'uuid'; //todo: somehow the system could not recognize v5.
|
|
2
|
-
// import { v5 as uuid } from 'uuid/v5 causes ERROR in src / app / _func / helperFunc.ts(1, 10): error TS2305: Module '"C:/VSProjects/ApsCloudTrunk/APS.WebPos.NGCli/NGSource/node_modules/@types/uuid/v5"' has no exported member 'v5'
|
|
3
|
-
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/28439
|
|
4
|
-
|
|
5
|
-
export class HelperFunc {
|
|
6
|
-
static loadExternalScript(scriptUrl: string) {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
const scriptElement = document.createElement('script');
|
|
9
|
-
scriptElement.src = scriptUrl;
|
|
10
|
-
scriptElement.onload = resolve;
|
|
11
|
-
document.body.appendChild(scriptElement);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 36 UUID string including 4 hyphens. MySql stores GUID as 36 bytes anyway rather than 16bytes.
|
|
17
|
-
*/
|
|
18
|
-
static newUUID(): string {
|
|
19
|
-
// return uuid('medilink.com.au', 'apscloud');
|
|
20
|
-
return uuid();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static newUUIDStartWith0() {
|
|
24
|
-
const s = uuid();
|
|
25
|
-
return '0000' + s.slice(4);
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/_func/htmlFunc.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export class HtmlFunc {
|
|
2
|
-
/**
|
|
3
|
-
* Print with buillt-in CSS for internal reports
|
|
4
|
-
* @param htmlTags
|
|
5
|
-
* @param baseRef
|
|
6
|
-
*/
|
|
7
|
-
static printWithCSS(htmlTags: string, baseRef: string) {
|
|
8
|
-
if (window) {
|
|
9
|
-
const htmlToPrint = `<html><head>
|
|
10
|
-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
|
|
11
|
-
<link rel="stylesheet" type="text/css" href="${baseRef}scripts/print190826.css" media="screen,print"/>
|
|
12
|
-
</head><body onload="window.print()">${htmlTags}</body></html>`;
|
|
13
|
-
|
|
14
|
-
const popup = window.open('', '_blank', 'width=1024,height=768');
|
|
15
|
-
popup?.document.open();
|
|
16
|
-
popup?.document.write(htmlToPrint);
|
|
17
|
-
|
|
18
|
-
popup?.document.close();
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Print for external documents.
|
|
25
|
-
* @param htmlTags
|
|
26
|
-
*/
|
|
27
|
-
static print(htmlTags: string) {
|
|
28
|
-
if (window) {
|
|
29
|
-
const htmlToPrint = `<html><head>
|
|
30
|
-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
|
|
31
|
-
</head><body onload="window.print()">${htmlTags}</body></html>`;
|
|
32
|
-
|
|
33
|
-
const popup = window.open('', '_blank', 'width=1024,height=768');
|
|
34
|
-
popup?.document.open();
|
|
35
|
-
popup?.document.write(htmlToPrint);
|
|
36
|
-
|
|
37
|
-
popup?.document.close();
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static printImage(url: string) {
|
|
43
|
-
const imageTags = `<img src="${url}" alt="Image from URL"/>`;
|
|
44
|
-
HtmlFunc.print(imageTags);
|
|
45
|
-
}
|
|
46
|
-
}
|
package/src/_func/index.ts
DELETED
package/src/_func/jsFunc.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { DateFunc} from './dateFunc';
|
|
2
|
-
|
|
3
|
-
export class JSFunc {
|
|
4
|
-
static groupBy<T>(array: Array<T>, propertyName: string) {
|
|
5
|
-
return array.reduce(function(acc: any, obj: any) {
|
|
6
|
-
const key = obj[propertyName];
|
|
7
|
-
if (!acc[key]) {
|
|
8
|
-
acc[key] = [];
|
|
9
|
-
}
|
|
10
|
-
acc[key].push(obj);
|
|
11
|
-
return acc;
|
|
12
|
-
}, {});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Group by a date property. The key is always of string type and representing milliseconds. The client should convert the string to number.
|
|
17
|
-
* Angular date pipe could actually consume such string without explicitly converting to number.
|
|
18
|
-
* @param array
|
|
19
|
-
* @param propertyName
|
|
20
|
-
*/
|
|
21
|
-
static groupByDate<T>(array: Array<T>, propertyName: string) {
|
|
22
|
-
return array.reduce(function(acc: any, obj: any) {
|
|
23
|
-
const key = DateFunc.dateTimeUtcToLocalDateNumber(obj[propertyName]);
|
|
24
|
-
if (!acc[key]) {
|
|
25
|
-
acc[key] = [];
|
|
26
|
-
}
|
|
27
|
-
acc[key].push(obj);
|
|
28
|
-
return acc;
|
|
29
|
-
}, {});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static removeNullOrEmptyFields(obj: any) {
|
|
33
|
-
for (const f in obj) {
|
|
34
|
-
if (obj[f] === null || obj[f]==='') {
|
|
35
|
-
delete obj[f];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static removeNullFields(obj: any) {
|
|
41
|
-
for (const f in obj) {
|
|
42
|
-
if (obj[f] === null) {
|
|
43
|
-
delete obj[f];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { StringFunc } from './stringFunc';
|
|
2
|
-
|
|
3
|
-
class MyStatus {
|
|
4
|
-
static description = '12AB';
|
|
5
|
-
static integer = 8;
|
|
6
|
-
static something: string; //without instance, this does not count
|
|
7
|
-
static something2: string=undefined!; //this count
|
|
8
|
-
|
|
9
|
-
private static _currentCalendarView = '';
|
|
10
|
-
static get currentCalendarView(): string {
|
|
11
|
-
const v = MyStatus._currentCalendarView;
|
|
12
|
-
return v ? v : 'month';
|
|
13
|
-
}
|
|
14
|
-
static set currentCalendarView(v: string) {
|
|
15
|
-
MyStatus._currentCalendarView = v;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static clear() {
|
|
19
|
-
for (const key in MyStatus) {
|
|
20
|
-
const p =key as keyof MyStatus;
|
|
21
|
-
{/*
|
|
22
|
-
// @ts-ignore */}
|
|
23
|
-
MyStatus[p] = undefined;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('1st tests', () => {
|
|
29
|
-
it('true is true', () => expect(true).toBe(true));
|
|
30
|
-
|
|
31
|
-
it('static variable', () => {
|
|
32
|
-
const staticKeys = Object.keys(MyStatus);
|
|
33
|
-
expect(staticKeys.length).toEqual(4); // something is not counted.
|
|
34
|
-
const p = staticKeys[0] as keyof MyStatus;
|
|
35
|
-
expect(MyStatus[p]).toEqual('12AB');
|
|
36
|
-
expect(MyStatus.something).toBeUndefined();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('static variable clear', () => {
|
|
40
|
-
const staticKeys = Object.keys(MyStatus);
|
|
41
|
-
MyStatus.currentCalendarView = 'kkkkk';
|
|
42
|
-
|
|
43
|
-
MyStatus.clear();
|
|
44
|
-
|
|
45
|
-
expect(MyStatus.description).toBeUndefined();
|
|
46
|
-
expect(staticKeys.length).toEqual(4); // something is not counted
|
|
47
|
-
const p = staticKeys[0] as keyof MyStatus;
|
|
48
|
-
expect(MyStatus[p]).toBeUndefined();
|
|
49
|
-
expect(MyStatus.currentCalendarView).toEqual('month');
|
|
50
|
-
|
|
51
|
-
MyStatus.description = '12AB'; // sometimes this test runs first, causing the first test failed.
|
|
52
|
-
})
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('stringFunc', () => {
|
|
56
|
-
it('getAbbr', () => {
|
|
57
|
-
expect(StringFunc.getAbbr('John Smith')).toEqual('JS');
|
|
58
|
-
expect(StringFunc.getAbbr('Huang, Zijian')).toEqual('ZH');
|
|
59
|
-
expect(StringFunc.getAbbr('')).toEqual('');
|
|
60
|
-
expect(StringFunc.getAbbr('John')).toEqual('J');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('getOneLineDigest', () => {
|
|
64
|
-
expect(StringFunc.getOneLineDigest('', 32)).toEqual('');
|
|
65
|
-
expect(StringFunc.getOneLineDigest(undefined, 32)).toBe('');
|
|
66
|
-
expect(StringFunc.getOneLineDigest(null, 32)).toBe('');
|
|
67
|
-
expect(StringFunc.getOneLineDigest('Abcd efg', 32)).toEqual('Abcd efg');
|
|
68
|
-
expect(StringFunc.getOneLineDigest('Abcd\nefg', 32)).toEqual('Abcd efg');
|
|
69
|
-
expect(StringFunc.getOneLineDigest('123456789 123456789 123456789 123456789 ', 32)).toEqual('123456789 123456789 123456789 12...');
|
|
70
|
-
expect(StringFunc.getOneLineDigest('123456789\n123456789\n123456789\n123456789 ', 32)).toEqual('123456789 123456789 123456789 12...');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('capitalize', () => {
|
|
74
|
-
expect(StringFunc.capitalizeWords('some thing')).toBe('Some Thing');
|
|
75
|
-
expect(StringFunc.capitalizeWords('3ome thing')).toBe('3ome Thing');
|
|
76
|
-
expect(StringFunc.capitalizeWords('località àtilacol')).toBe('Località Àtilacol');
|
|
77
|
-
expect(StringFunc.capitalizeWords('中文 好')).toBe('中文 好');
|
|
78
|
-
expect(StringFunc.capitalizeWords('')).toBe('');
|
|
79
|
-
expect(StringFunc.capitalizeWords(undefined)).toBeUndefined();
|
|
80
|
-
expect(StringFunc.capitalizeWords(null)).toBeNull();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('validateMedicare', () => {
|
|
84
|
-
expect(StringFunc.validateMedicare('2950974202')).toBeNull();
|
|
85
|
-
expect(StringFunc.validateMedicare('3950386862')).toBeNull();
|
|
86
|
-
expect(StringFunc.validateMedicare('2950974392')).toBeNull();
|
|
87
|
-
expect(StringFunc.validateMedicare('3950386952')).toBeNull();
|
|
88
|
-
|
|
89
|
-
expect(StringFunc.validateMedicare('950386952')?.code).toBe(1);
|
|
90
|
-
expect(StringFunc.validateMedicare('33950386952')?.code).toBe(1);
|
|
91
|
-
expect(StringFunc.validateMedicare('aaaaaaaaaa')?.code).toBe(2);
|
|
92
|
-
expect(StringFunc.validateMedicare('3333333333')?.code).toBe(3);
|
|
93
|
-
expect(StringFunc.validateMedicare('3950386923')?.code).toBe(3);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('validateProviderCode', () => {
|
|
97
|
-
expect(StringFunc.validateMedicareProviderNumber('2426591T')).toBeNull();
|
|
98
|
-
expect(StringFunc.validateMedicareProviderNumber('2426601H')).toBeNull();
|
|
99
|
-
expect(StringFunc.validateMedicareProviderNumber('2423391B')).toBeNull();
|
|
100
|
-
expect(StringFunc.validateMedicareProviderNumber('3323391B')?.code).toBe(2);
|
|
101
|
-
expect(StringFunc.validateMedicareProviderNumber('3391B')?.code).toBe(1);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('validateTFN', () => {
|
|
105
|
-
expect(StringFunc.validateTFN('123456782')).toBeNull();
|
|
106
|
-
expect(StringFunc.validateTFN('123 456-782')).toBeNull();
|
|
107
|
-
expect(StringFunc.validateTFN('a3323391B')?.code).toBe(1);
|
|
108
|
-
expect(StringFunc.validateTFN('3391')?.code).toBe(2);
|
|
109
|
-
expect(StringFunc.validateTFN('123456783')?.code).toBe(3);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('validateABN', () => {
|
|
113
|
-
expect(StringFunc.validateABN('51824753556')).toBeNull();
|
|
114
|
-
expect(StringFunc.validateABN('51 824 753 556')).toBeNull();
|
|
115
|
-
expect(StringFunc.validateABN('51-824 753 556')).toBeNull();
|
|
116
|
-
expect(StringFunc.validateABN('5182475355')?.code).toBe(1);
|
|
117
|
-
expect(StringFunc.validateABN('51824753557')?.code).toBe(2);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('validateACN', () => {
|
|
121
|
-
expect(StringFunc.validateACN('003 249 992')).toBeNull();
|
|
122
|
-
expect(StringFunc.validateACN('005999977')).toBeNull();
|
|
123
|
-
expect(StringFunc.validateACN('010.499-966')).toBeNull();
|
|
124
|
-
expect(StringFunc.validateACN('00599997')?.code).toBe(1);
|
|
125
|
-
expect(StringFunc.validateACN('005999979')?.code).toBe(2);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('validateDVAFileNumber', () => {
|
|
129
|
-
expect(StringFunc.validateDVAFileNumber('QX901533')).toBeNull();
|
|
130
|
-
expect(StringFunc.validateDVAFileNumber('W 1')).toBeNull();
|
|
131
|
-
expect(StringFunc.validateDVAFileNumber('SCGW1234')).toBeNull();
|
|
132
|
-
expect(StringFunc.validateDVAFileNumber('SCGW1234B')).toBeNull();
|
|
133
|
-
expect(StringFunc.validateDVAFileNumber('ZX901533')?.code).toBe(1);
|
|
134
|
-
expect(StringFunc.validateDVAFileNumber('QX90153C')).toBeNull();
|
|
135
|
-
expect(StringFunc.validateDVAFileNumber('NKKK1533')?.code).toBe(3);
|
|
136
|
-
expect(StringFunc.validateDVAFileNumber('WK153344')?.code).toBe(3);
|
|
137
|
-
expect(StringFunc.validateDVAFileNumber('TX1533444')?.code).toBe(4);
|
|
138
|
-
expect(StringFunc.validateDVAFileNumber('VXabcde')?.code).toBe(2);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|