nmce-func 0.0.3 → 0.0.7

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.
Files changed (54) hide show
  1. package/_func/addressFunc.d.ts +31 -0
  2. package/_func/authentication.service.d.ts +24 -0
  3. package/_func/currencyFunc.d.ts +20 -0
  4. package/_func/dateFunc.d.ts +121 -0
  5. package/_func/htmlPrintFunc.d.ts +18 -0
  6. package/_func/index.d.ts +10 -0
  7. package/_func/javascriptFunc.d.ts +9 -0
  8. package/_func/jsonFunc.d.ts +31 -0
  9. package/_func/stringAusFunc.d.ts +40 -0
  10. package/_func/stringFunc.d.ts +41 -0
  11. package/_func/uuidFunc.d.ts +7 -0
  12. package/bundles/nmce-func.umd.js +1294 -0
  13. package/bundles/nmce-func.umd.js.map +1 -0
  14. package/bundles/nmce-func.umd.min.js +2 -0
  15. package/bundles/nmce-func.umd.min.js.map +1 -0
  16. package/esm2015/_func/addressFunc.js +49 -0
  17. package/esm2015/_func/authentication.service.js +41 -0
  18. package/esm2015/_func/currencyFunc.js +72 -0
  19. package/esm2015/_func/dateFunc.js +316 -0
  20. package/esm2015/_func/htmlPrintFunc.js +45 -0
  21. package/esm2015/_func/index.js +11 -0
  22. package/esm2015/_func/javascriptFunc.js +17 -0
  23. package/esm2015/_func/jsonFunc.js +67 -0
  24. package/esm2015/_func/stringAusFunc.js +200 -0
  25. package/esm2015/_func/stringFunc.js +93 -0
  26. package/esm2015/_func/uuidFunc.js +17 -0
  27. package/esm2015/nmce-func.js +5 -0
  28. package/esm2015/public-api.js +5 -0
  29. package/fesm2015/nmce-func.js +927 -0
  30. package/fesm2015/nmce-func.js.map +1 -0
  31. package/nmce-func.d.ts +4 -0
  32. package/nmce-func.metadata.json +1 -0
  33. package/package.json +18 -4
  34. package/public-api.d.ts +1 -0
  35. package/karma.conf.js +0 -44
  36. package/ng-package.json +0 -11
  37. package/src/_func/addressFunc.spec.ts +0 -12
  38. package/src/_func/addressFunc.ts +0 -54
  39. package/src/_func/authentication.service.ts +0 -47
  40. package/src/_func/currencyFunc.ts +0 -71
  41. package/src/_func/dateFunc.spec.ts +0 -191
  42. package/src/_func/dateFunc.ts +0 -385
  43. package/src/_func/helperFunc.ts +0 -27
  44. package/src/_func/htmlFunc.ts +0 -46
  45. package/src/_func/index.ts +0 -9
  46. package/src/_func/jsFunc.ts +0 -48
  47. package/src/_func/stringFunc.spec.ts +0 -142
  48. package/src/_func/stringFunc.ts +0 -337
  49. package/src/public-api.ts +0 -5
  50. package/src/test.ts +0 -26
  51. package/tsconfig.lib.json +0 -25
  52. package/tsconfig.lib.prod.json +0 -11
  53. package/tsconfig.spec.json +0 -17
  54. package/tslint.json +0 -17
@@ -0,0 +1,31 @@
1
+ export declare class AddressFunc {
2
+ /**
3
+ * Compose to one line separated by comma
4
+ * @param st1
5
+ * @param st2
6
+ * @param city
7
+ * @param state
8
+ * @param postcode
9
+ */
10
+ static composeOneLineAddress(st1: string | undefined, st2: string | undefined, city: string | undefined, state: string | undefined, postcode: string | undefined): string;
11
+ /**
12
+ * Compose to multiple separated by \n
13
+ * @param st1
14
+ * @param st2
15
+ * @param city
16
+ * @param state
17
+ * @param postcode
18
+ */
19
+ static composeMultiLineAddress(st1: string | undefined, st2: string | undefined, city: string | undefined, state: string | undefined, postcode: string | undefined): string;
20
+ /**
21
+ * Compose with separator
22
+ * @param st1
23
+ * @param st2
24
+ * @param city
25
+ * @param state
26
+ * @param postcode
27
+ * @param sep
28
+ */
29
+ static composeAddress(st1: string | undefined, st2: string | undefined, city: string | undefined, state: string | undefined, postcode: string | undefined, sep: string | undefined): string;
30
+ static composeGoogleMapsAuUrl(st1: string | undefined, st2: string | undefined, city: string | undefined, state: string | undefined, country: string | undefined): string;
31
+ }
@@ -0,0 +1,24 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ /**
3
+ * Login and saving tokens in sessionStorage.
4
+ * App needs to provide constant 'auth.tokenUrl'.
5
+ */
6
+ export declare class AuthenticationService {
7
+ private authUri;
8
+ private http;
9
+ userName: string;
10
+ constructor(authUri: string, http: HttpClient);
11
+ /**
12
+ * Login and save tokens to sessionStorage then return an observable.
13
+ * @param username
14
+ * @param password
15
+ */
16
+ login(username: string, password: string): import("rxjs").Observable<{
17
+ access_token?: string | undefined;
18
+ expires?: string | undefined;
19
+ expires_in?: number | undefined;
20
+ issued?: string | undefined;
21
+ token_type?: string | undefined;
22
+ username: string;
23
+ }>;
24
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Currency calculations. Undefined input of number is considered zero, just like null.
3
+ */
4
+ export declare class CurrencyFunc {
5
+ private static DECIMAL_SEPARATOR;
6
+ private static THOUSANDS_SEPARATOR;
7
+ private static PADDING;
8
+ /**
9
+ *
10
+ * @param num
11
+ * @param decimalPlaces default 0
12
+ */
13
+ static bankerRound(num: number | null | undefined, decimalPlaces?: number): number;
14
+ static bankerRoundTo5cents(num: number | null | undefined): number;
15
+ static ceilTo5cents(num: number | null | undefined): number;
16
+ static transformCurrency(value: number | string | undefined, fractionSize?: number): string;
17
+ static parseCurrency(value: string | undefined, fractionSize?: number): string;
18
+ static pad(num: number | null | undefined, size: number): string;
19
+ static sum(ns: (number | null | undefined)[]): number;
20
+ }
@@ -0,0 +1,121 @@
1
+ import moment from 'moment';
2
+ export declare class DateFunc {
3
+ /**
4
+ * 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.
5
+ * @param dtUtc
6
+ * @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
7
+ */
8
+ static dateTimeUtcToLocalDateNumber(dtUtc: Date | null | undefined): number;
9
+ /**
10
+ * Date only. However, the date may still be in UTC.
11
+ * @param dtUtc
12
+ */
13
+ static dateTimeUtcToLocalDate(dtUtc: Date | null | undefined): Date;
14
+ static localISODateString(dtUtc: Date | null | undefined): string;
15
+ /**
16
+ * locate date ONLY (no time) to UTC date.
17
+ * @param dt if dt contain time info, it will become dt.setHours(0, 0, 0, 0)
18
+ */
19
+ static localDateToUtc(d: Date | number | null | undefined | string): Date;
20
+ static getTimezoneOffset(): number;
21
+ /**
22
+ * Transform UTC DateTime to local dateTime.
23
+ * @param dtUtc
24
+ * @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
25
+ */
26
+ static dateTimeUtcToLocalDateTime(dtUtc: Date | null | undefined): Date;
27
+ static dateTimeUtcToLocaMoment(dtUtc: Date | null | undefined): moment.Moment;
28
+ static getEndOfWeek(dt: Date | null | undefined | number): Date;
29
+ static getStartOfWeek(dt: Date | null | undefined | number): Date;
30
+ static getEndOfMonth(dt: Date | null | undefined | number): Date;
31
+ static getStartOfMonth(dt: Date | null | undefined | number): Date;
32
+ static getDaysBetweenDates(dt1: Date | null | undefined, dt2: Date | null | undefined): number;
33
+ static getEndOfDate(dt: Date | null | undefined): Date;
34
+ static getStartOfDate(dt: Date | null | undefined): Date;
35
+ static getEndOfToday(): Date;
36
+ static getStartOfToday(): Date;
37
+ static addDays(dt: Date | null | undefined, days?: number): Date;
38
+ static subtractDays(dt: Date | null | undefined, days?: number): Date;
39
+ /**
40
+ * Start of today
41
+ */
42
+ static get today(): Date;
43
+ static get now(): Date;
44
+ static getNext5MinuteMark(): Date;
45
+ static getYMD(d: Date): string;
46
+ static getDMYWithSlash(d: Date): string;
47
+ static getDMYHmWithSlash(d: Date): string;
48
+ static getMcpTime(dt: Date | null | undefined): string;
49
+ /**
50
+ * In 24 hour format
51
+ * @param dtUtc
52
+ */
53
+ static getLocalDMYHmWithSlash(dtUtc: Date | null | undefined): string;
54
+ /**
55
+ * Offset minutes comparing with today
56
+ */
57
+ static getOffsetMinutes(dtUtc: Date | null | undefined | number): number;
58
+ static getDaysBetween(d1?: Date | number | null | undefined, d2?: Date | number | null | undefined): number;
59
+ /**
60
+ * Get hour of the date. If Date is not defined, the hour will be current hour.
61
+ * @param dtUtc
62
+ */
63
+ static getHour(dtUtc: Date | null | undefined | number): number;
64
+ static getMinute(dtUtc: Date | null | undefined | number): number;
65
+ static composeDateTime(dt: Date | null | undefined, h?: number, minute?: number): Date;
66
+ static olderThan24Hours(d: Date | null | undefined): boolean;
67
+ static olderThan24HoursUtc(dtUtc: Date | null | undefined): boolean;
68
+ static olderThanHours(d: Date, hours: number): boolean;
69
+ static olderThanHoursUtc(dtUtc: Date | null | undefined, hours: number): boolean;
70
+ static olderThanMinutes(d: Date, minutes: number): boolean;
71
+ /**
72
+ * It could be 11PM yesterday, and 1 AM today. Actually based on local today.
73
+ */
74
+ static olderThan1Day(dtUtc: Date | null | undefined): boolean;
75
+ static getHourAge(d: Date): number;
76
+ static getHourAgeUtc(dtUtc: Date | null | undefined): number;
77
+ /**
78
+ * Compare utc date with utc now.
79
+ * @param dtUtc
80
+ */
81
+ static getDayAgeUtc(dtUtc: Date | null | undefined): number;
82
+ /**
83
+ * How many years from now.
84
+ * @param d
85
+ * @returns
86
+ */
87
+ static getAge(d: Date): number;
88
+ /**
89
+ * Year of date.
90
+ * @param d
91
+ * @returns
92
+ */
93
+ static getYear(d: Date): number;
94
+ static getUtcNow(): Date;
95
+ static addMinutes(d: Date, m: number): Date;
96
+ static addMonth(d: Date, m: number): Date;
97
+ static getDuration(d1: Date, d2: Date): moment.Duration;
98
+ /**
99
+ * Convert minutes from midnight to HH:mm text
100
+ * @param mins
101
+ */
102
+ static getHMFromMins(mins: number): string;
103
+ static getMinutesSinceMidnight(d: Date | null | undefined): number;
104
+ static getMinutesBetween(start: Date | null | undefined, end: Date | null | undefined): number;
105
+ /**
106
+ * Parse json string with date serialized into string, and get proper date object back
107
+ * @param s
108
+ */
109
+ static dateSafeJsonParse(s: string): any;
110
+ private static dateReviver;
111
+ private static isSerializedDate;
112
+ private static isString;
113
+ static dateSafeParse(s: string | Date): Date;
114
+ static composeDateWithMinutes(d: Date, minute: number): Date;
115
+ /**
116
+ * Safe compare since date data may be considered as string rather than date.
117
+ * @param d1
118
+ * @param d2
119
+ */
120
+ static compare(d1: Date | undefined, d2: Date | undefined): number;
121
+ }
@@ -0,0 +1,18 @@
1
+ export declare class HtmlPrintFunc {
2
+ /**
3
+ * Print with CSS for internal reports
4
+ * @param htmlTags
5
+ * @param cssUrl
6
+ */
7
+ static printWithCSS(htmlTags: string, cssUrl: string): boolean;
8
+ /**
9
+ * Print for external documents.
10
+ * @param htmlTags
11
+ */
12
+ static print(htmlTags: string): boolean;
13
+ /**
14
+ * Print image url through html img.
15
+ * @param url
16
+ */
17
+ static printImage(url: string): void;
18
+ }
@@ -0,0 +1,10 @@
1
+ export * from './addressFunc';
2
+ export * from './authentication.service';
3
+ export * from './currencyFunc';
4
+ export * from './dateFunc';
5
+ export * from './htmlPrintFunc';
6
+ export * from './javascriptFunc';
7
+ export * from './jsonFunc';
8
+ export * from './stringAusFunc';
9
+ export * from './stringFunc';
10
+ export * from './uuidFunc';
@@ -0,0 +1,9 @@
1
+ export declare class JavaScriptFunc {
2
+ /**
3
+ * Some business functions depend on external JavaScript libraries. Lazy loading of respective business modules is good,
4
+ * and this function supports lazy loading of JS libraries.
5
+ * @param scriptUrl
6
+ * @returns Promise for subsequent JS function calls.
7
+ */
8
+ static loadExternalScript(scriptUrl: string): Promise<unknown>;
9
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Basic JSON functions
3
+ */
4
+ export declare class JsonFunc {
5
+ /**
6
+ *
7
+ * @param array Group by a property of array element.
8
+ * @param propertyName
9
+ * @returns
10
+ */
11
+ static groupBy<T>(array: Array<T>, propertyName: string): any;
12
+ /**
13
+ * Group by a date property. The key is always of string type and representing milliseconds.
14
+ * The client should convert the string to number.
15
+ * Angular date pipe could actually consume such string without explicitly converting to number.
16
+ * @param array
17
+ * @param propertyName
18
+ */
19
+ static groupByDate<T>(array: Array<T>, propertyName: string): any;
20
+ /**
21
+ * Remove null or empty fields including those in nested objects.
22
+ * This is useful for reducing payload of AJAX serialization.
23
+ * @param obj
24
+ */
25
+ static removeNullOrEmptyFields(obj: any): void;
26
+ /**
27
+ *
28
+ * @param obj Remove null fields of object at only the 1st level.
29
+ */
30
+ static removeNullFields(obj: any): void;
31
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * String functions specific to Australia
3
+ */
4
+ export declare class StringAusFunc {
5
+ private static acnWeights;
6
+ private static weights;
7
+ private static suggestLookup;
8
+ /**
9
+ * Validate medicare number
10
+ * @param n
11
+ * @returns validation error message
12
+ */
13
+ static validateMedicare(n: string | null | undefined): {
14
+ code: number;
15
+ message: string;
16
+ } | null;
17
+ static validateMedicareProviderNumber(providerNumber: string | null | undefined): {
18
+ code: number;
19
+ message: string;
20
+ } | null;
21
+ static validateDVAFileNumber(dva: string | null | undefined): {
22
+ code: number;
23
+ message: string;
24
+ } | null;
25
+ static validateTFN(n: string | null | undefined): {
26
+ code: number;
27
+ message: string;
28
+ } | null;
29
+ private static addWeighted;
30
+ private static addAcnWeighted;
31
+ private static generateLookup;
32
+ static validateABN(abn: string | null | undefined): {
33
+ code: number;
34
+ message: string;
35
+ } | null;
36
+ static validateACN(acn: string | null | undefined): {
37
+ code: number;
38
+ message: string;
39
+ } | null;
40
+ }
@@ -0,0 +1,41 @@
1
+ export declare class StringFunc {
2
+ /**
3
+ * Up to 2 letters. For John Smith, returns JS, for Huang, Zijian, returns ZH
4
+ * @param s
5
+ */
6
+ static getAbbr(s: string | null | undefined): string;
7
+ /**
8
+ * A substring with line breaks replaced by space.
9
+ * @param s
10
+ * @param length
11
+ * @returns result, or empty string if the input is empty, null or undefined
12
+ */
13
+ static getOneLineDigest(s: string | null | undefined, length: number): string;
14
+ /**
15
+ * Remove line breaks and econde with encodeURI() so the data could be saved in Azure as meta. If the string is truncated, the return will have ... suffix.
16
+ * @param s
17
+ * @param length
18
+ * @returns result, or empty string if the input is empty, null or undefined
19
+ */
20
+ static getOneLineDigestOfHtml(s: string | null | undefined, length: number): string;
21
+ /**
22
+ * Pad number with zero
23
+ * @param num
24
+ * @param size
25
+ * @returns
26
+ */
27
+ static pad(num: number | undefined, size: number): string;
28
+ /**
29
+ * get plain text of HTML content
30
+ * @param s
31
+ * @returns result. If input is empty, null, or undefined, return the same.
32
+ */
33
+ static getHtmlPlainText(s: string | null | undefined): string | null;
34
+ /**
35
+ *
36
+ * @param s
37
+ * @returns result. If input is empty, null, or undefined, return the same.
38
+ */
39
+ static capitalizeWords(s: string | null | undefined): string | null | undefined;
40
+ static validateEmail(email: string | null | undefined): boolean;
41
+ }
@@ -0,0 +1,7 @@
1
+ export declare class UuidFunc {
2
+ /**
3
+ * 36 UUID string including 4 hyphens. MySql stores GUID as 36 bytes anyway rather than 16bytes.
4
+ */
5
+ static newUUID(): string;
6
+ static newUUIDStartWith0(): string;
7
+ }