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.
- package/_func/addressFunc.d.ts +31 -0
- package/_func/authentication.service.d.ts +24 -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/bundles/nmce-func.umd.js +1294 -0
- package/bundles/nmce-func.umd.js.map +1 -0
- package/bundles/nmce-func.umd.min.js +2 -0
- package/bundles/nmce-func.umd.min.js.map +1 -0
- package/esm2015/_func/addressFunc.js +49 -0
- package/esm2015/_func/authentication.service.js +41 -0
- package/esm2015/_func/currencyFunc.js +72 -0
- package/esm2015/_func/dateFunc.js +316 -0
- package/esm2015/_func/htmlPrintFunc.js +45 -0
- package/esm2015/_func/index.js +11 -0
- package/esm2015/_func/javascriptFunc.js +17 -0
- package/esm2015/_func/jsonFunc.js +67 -0
- package/esm2015/_func/stringAusFunc.js +200 -0
- package/esm2015/_func/stringFunc.js +93 -0
- package/esm2015/_func/uuidFunc.js +17 -0
- package/esm2015/nmce-func.js +5 -0
- package/esm2015/public-api.js +5 -0
- package/fesm2015/nmce-func.js +927 -0
- package/fesm2015/nmce-func.js.map +1 -0
- package/nmce-func.d.ts +4 -0
- package/nmce-func.metadata.json +1 -0
- package/package.json +18 -4
- 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
|
@@ -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
|
-
});
|
package/src/_func/stringFunc.ts
DELETED
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
export class StringFunc {
|
|
2
|
-
;
|
|
3
|
-
;
|
|
4
|
-
|
|
5
|
-
//thanks to https://github.com/sidorares/australian-business-number/blob/0591475f5978fd122b472edcdc7efe6d96d56f26/index.js
|
|
6
|
-
private static acnWeights = [8, 7, 6, 5, 4, 3, 2, 1];
|
|
7
|
-
private static weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
|
|
8
|
-
|
|
9
|
-
private static suggestLookup: number[] = StringFunc.generateLookup();
|
|
10
|
-
/**
|
|
11
|
-
* Up to 2 letters. For John Smith, returns JS, for Huang, Zijian, returns ZH
|
|
12
|
-
* @param s
|
|
13
|
-
*/
|
|
14
|
-
static getAbbr(s: string) {
|
|
15
|
-
if (!s) {
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const sArray = s.split(/[\s,]+/);
|
|
20
|
-
const comma = s.indexOf(',') >= 0;
|
|
21
|
-
|
|
22
|
-
if (sArray.length === 1) {
|
|
23
|
-
return sArray[0][0];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return comma ? sArray[1][0] + sArray[0][0] : sArray[0][0] + sArray[1][0];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* A substring with line breaks replaced by space.
|
|
31
|
-
* @param s
|
|
32
|
-
* @param length
|
|
33
|
-
* @returns result, or empty string if the input is empty, null or undefined
|
|
34
|
-
*/
|
|
35
|
-
static getOneLineDigest(s: string | undefined | null, length: number) {
|
|
36
|
-
if (!s) {
|
|
37
|
-
return '';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const ss = s.substring(0, length);
|
|
41
|
-
const st = ss.replace(new RegExp('\n', 'g'), ' ') + ((s.length > length) ? '...' : '');
|
|
42
|
-
return st.trim();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 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.
|
|
47
|
-
* @param s
|
|
48
|
-
* @param length
|
|
49
|
-
* @returns result, or empty string if the input is empty, null or undefined
|
|
50
|
-
*/
|
|
51
|
-
static getOneLineDigestOfHtml(s: string | null, length: number) {
|
|
52
|
-
if (!s) {
|
|
53
|
-
return '';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const ss = s.substring(0, length);
|
|
57
|
-
const st = ss.replace(new RegExp('\n', 'g'), ' ') + ((s.length > length) ? '...' : '');
|
|
58
|
-
return encodeURI(st.trim()); //need to encode in order to save as meta in Azure.
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
static pad(num: number, size: number): string {
|
|
62
|
-
let s = num + '';
|
|
63
|
-
while (s.length < size) { s = '0' + s; }
|
|
64
|
-
return s;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* get plain text of HTML content
|
|
69
|
-
* @param s
|
|
70
|
-
* @returns result. If input is empty, null, or undefined, return the same.
|
|
71
|
-
*/
|
|
72
|
-
static getHtmlPlainText(s: string | null): string | null {
|
|
73
|
-
if (!s) {
|
|
74
|
-
return s;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const parser = new DOMParser();
|
|
78
|
-
const html = parser.parseFromString(s, 'text/html');
|
|
79
|
-
return html.body.textContent;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* @param s
|
|
85
|
-
* @returns result. If input is empty, null, or undefined, return the same.
|
|
86
|
-
*/
|
|
87
|
-
static capitalizeWords(s: string | undefined | null): string | undefined | null { // thanks to https://stackoverflow.com/questions/2332811/capitalize-words-in-string
|
|
88
|
-
if (!s) {
|
|
89
|
-
return s;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return s.replace(/(?:^|\s)\S/g, (a) => a.toUpperCase());
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Validate medicare number
|
|
97
|
-
* @param n
|
|
98
|
-
* @returns validation error message
|
|
99
|
-
*/
|
|
100
|
-
static validateMedicare(n: string | undefined | null): { code: number, message: string } | null {
|
|
101
|
-
if (!n) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (n && n.length === 10) {
|
|
106
|
-
const matches = n.match(/^(\d{8})(\d)/);
|
|
107
|
-
|
|
108
|
-
if (!matches) {
|
|
109
|
-
return {
|
|
110
|
-
code: 2, message: 'Medicare number should be all digit.'
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const base = matches[1];
|
|
115
|
-
const checkDigit = matches[2];
|
|
116
|
-
const weights = [1, 3, 7, 9, 1, 3, 7, 9];
|
|
117
|
-
|
|
118
|
-
let sum = 0;
|
|
119
|
-
for (let i = 0; i < weights.length; i++) {
|
|
120
|
-
sum += parseInt(base[i], 10) * weights[i];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
//console.debug(`sum: ${sum} checkDigits: ${checkDigit}`);
|
|
124
|
-
const isValid = sum % 10 === parseInt(checkDigit, 10);
|
|
125
|
-
if (!isValid) {
|
|
126
|
-
return {
|
|
127
|
-
code: 3, message: 'Checksum is incorrect.'
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
return { code: 1, message: 'Length should be 10.' };
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
static validateMedicareProviderNumber(providerNumber: string): { code: number, message: string } | null {
|
|
138
|
-
if (!providerNumber) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!/^[0-9]{6}[0-9ABCDEFGHJKLMNPQRTUVWXY][ABFHJKLTWXY]/.test(providerNumber)) {
|
|
143
|
-
return { code: 1, message: 'Not matching provider number format.' };
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const practiceLocationValues = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'V', 'W', 'X', 'Y'];
|
|
147
|
-
const remainderValues = ['Y', 'X', 'W', 'T', 'L', 'K', 'J', 'H', 'F', 'B', 'A'];
|
|
148
|
-
const stemWeights = [3, 5, 8, 4, 2, 1];
|
|
149
|
-
|
|
150
|
-
const stemNumbers = providerNumber.substr(0, 6).split('').map((char) => parseInt(char));
|
|
151
|
-
const practiceLoc = practiceLocationValues.findIndex((e) => e === providerNumber[6]);
|
|
152
|
-
const checksum = providerNumber[7];
|
|
153
|
-
|
|
154
|
-
const zipped = stemWeights.map((x, i) => [x, stemNumbers[i]]);
|
|
155
|
-
const sumWeights = zipped.map((y) => y[1] * y[0]).reduce((total, num) => total + num);
|
|
156
|
-
const remainder = (sumWeights + practiceLoc * 6) % 11;
|
|
157
|
-
|
|
158
|
-
const result = remainderValues[remainder];
|
|
159
|
-
|
|
160
|
-
const valid = result === checksum;
|
|
161
|
-
if (!valid) {
|
|
162
|
-
return { code: 2, message: 'Checksum is incorrect.' };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
static validateDVAFileNumber(dva: string): { code: number, message: string } | null{
|
|
169
|
-
if (!dva) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const states = ['N', 'V', 'Q', 'S', 'W', 'T'];
|
|
174
|
-
const warCodes = [' ', 'X', 'KM', 'SR', 'SS', 'SM', 'SWP', 'AGX', 'BW', 'GW', 'CGW', //Australian Forces
|
|
175
|
-
'P', 'PX', 'PAD', 'PAM', 'PCA', 'PCR', 'PCV', 'PMS', 'PSW', 'PWO', 'HKX', 'MAL', //British Administration Group
|
|
176
|
-
'CN', 'CNX', 'IV', 'NF', 'NG', 'RD', 'RDX', 'SA', 'SAX', 'A', //Other Overseas Forces
|
|
177
|
-
'N', 'NX', 'NSW', 'NSM', //New Zealand Administration Group
|
|
178
|
-
'BUR', 'CNK', 'CNS', 'FIJ', 'GHA', 'HKS', 'IND', 'KYA', 'MAU', 'MLS', 'MTX', 'MWI', 'NK', 'NGR', 'NRD', 'NSS', 'PK']//British Commonwealth Countries - SP Eligibility
|
|
179
|
-
|
|
180
|
-
if (!states.includes(dva.charAt(0))) {
|
|
181
|
-
return { code: 1, message: 'State incorrect.' };
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const ns = dva.match(/\d+/);
|
|
185
|
-
if (!ns) {
|
|
186
|
-
return { code: 2, message: 'No number.' };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const n = ns[0];
|
|
190
|
-
const idxOfN = dva.indexOf(n);
|
|
191
|
-
const warCode = dva.substring(1, idxOfN);
|
|
192
|
-
if (!warCodes.includes(warCode)) {
|
|
193
|
-
return { code: 3, message: 'War code invalid.' }
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const lenOfN = n.length;
|
|
197
|
-
const lenOfWc = warCode.length;
|
|
198
|
-
if (lenOfN + lenOfWc > 7) {
|
|
199
|
-
return { code: 4, message: 'File number length should not be greater 7.' }
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
static validateTFN(n: string): { code: number, message: string } | null {
|
|
206
|
-
if (!n) {
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const tfn = n.replace(/\s+/g, '').replace(/[-]/g, '');
|
|
211
|
-
|
|
212
|
-
const isNumber = /^[0-9]+$/.test(tfn);
|
|
213
|
-
if (!isNumber) {
|
|
214
|
-
return { code: 1, message: 'Invalid TFN, only numbers are allowed.' };
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const length = tfn.length;
|
|
218
|
-
if (length !== 9) {
|
|
219
|
-
return {
|
|
220
|
-
code: 2, message: 'Invalid TFN, must have 9 digits.'
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const digits = tfn.split('').map(d => parseInt(d));
|
|
225
|
-
|
|
226
|
-
const sum = (digits[0] * 1)
|
|
227
|
-
+ (digits[1] * 4)
|
|
228
|
-
+ (digits[2] * 3)
|
|
229
|
-
+ (digits[3] * 7)
|
|
230
|
-
+ (digits[4] * 5)
|
|
231
|
-
+ (digits[5] * 8)
|
|
232
|
-
+ (digits[6] * 6)
|
|
233
|
-
+ (digits[7] * 9)
|
|
234
|
-
+ (digits[8] * 10);
|
|
235
|
-
|
|
236
|
-
const remainder = sum % 11;
|
|
237
|
-
const valid = remainder === 0;
|
|
238
|
-
if (!valid) {
|
|
239
|
-
return { code: 3, message: 'Checksum is incorrect.' };
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
private static addWeighted(p: number, v: number, i: number) {
|
|
246
|
-
return p + v * StringFunc.weights[i];
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
private static addAcnWeighted(p: number, v: number, i: number) {
|
|
250
|
-
return p + v * StringFunc.acnWeights[i];
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
private static generateLookup(): number[] {
|
|
254
|
-
const ns: number[] = [];
|
|
255
|
-
for (let i = 0; i < 10; ++i) {
|
|
256
|
-
ns[i * 19 % 89] = i;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return ns;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
static validateABN(abn: string): { code: number, message: string } | null {
|
|
263
|
-
if (!abn) {
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const digits = abn.replace(/[^\d]/g, '').split('').map(Number);
|
|
268
|
-
if (digits.length !== 11) {
|
|
269
|
-
return { code: 1, message: 'Expect 11-digit.' };
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
digits[0] -= 1;
|
|
273
|
-
|
|
274
|
-
const sum = digits.reduce(this.addWeighted, 0);
|
|
275
|
-
|
|
276
|
-
if (sum % 89 === 0) {
|
|
277
|
-
return null;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
digits[0] += 1;
|
|
281
|
-
|
|
282
|
-
let sum1 = sum - digits[10] * StringFunc.weights[10];
|
|
283
|
-
let digit = StringFunc.suggestLookup[89 - sum1 % 89];
|
|
284
|
-
if (digit !== undefined) {
|
|
285
|
-
return {
|
|
286
|
-
code: 2,
|
|
287
|
-
message: 'Checksum1 is incorrect.'
|
|
288
|
-
}
|
|
289
|
-
} else {
|
|
290
|
-
const sum2 = sum1 - digits[9] * StringFunc.weights[9];
|
|
291
|
-
for (let i = 0; i < 10; ++i) {
|
|
292
|
-
sum1 = sum2 + i * StringFunc.weights[9];
|
|
293
|
-
digit = StringFunc.suggestLookup[89 - sum1 % 89];
|
|
294
|
-
if (digit !== undefined) {
|
|
295
|
-
return {
|
|
296
|
-
code: 3,
|
|
297
|
-
message: 'Checksum2 is incorrect.'
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return null
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
static validateACN(acn: string): { code: number, message: string } | null {
|
|
307
|
-
if (!acn) {
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const digits = acn.replace(/[^\d]/g, '').split('').map(Number);
|
|
312
|
-
console.log(digits);
|
|
313
|
-
if (digits.length !== 9) {
|
|
314
|
-
return { code: 1, message: 'Expect 9-digit.' };
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const sum = digits.slice(0, 8).reduce(StringFunc.addAcnWeighted, 0);
|
|
319
|
-
const lastDigit = 10 - sum % 10;
|
|
320
|
-
if (lastDigit === digits[8]) {
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
return {
|
|
325
|
-
code: 2,
|
|
326
|
-
message: 'Checksum is incorrect.'
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
validateEmail(email: string) : boolean {
|
|
331
|
-
if (!email) {
|
|
332
|
-
return true;
|
|
333
|
-
}
|
|
334
|
-
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
335
|
-
return re.test(email.toLowerCase());
|
|
336
|
-
}
|
|
337
|
-
}
|
package/src/public-api.ts
DELETED
package/src/test.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
-
|
|
3
|
-
import 'zone.js/dist/zone';
|
|
4
|
-
import 'zone.js/dist/zone-testing';
|
|
5
|
-
import { getTestBed } from '@angular/core/testing';
|
|
6
|
-
import {
|
|
7
|
-
BrowserDynamicTestingModule,
|
|
8
|
-
platformBrowserDynamicTesting
|
|
9
|
-
} from '@angular/platform-browser-dynamic/testing';
|
|
10
|
-
|
|
11
|
-
declare const require: {
|
|
12
|
-
context(path: string, deep?: boolean, filter?: RegExp): {
|
|
13
|
-
keys(): string[];
|
|
14
|
-
<T>(id: string): T;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// First, initialize the Angular testing environment.
|
|
19
|
-
getTestBed().initTestEnvironment(
|
|
20
|
-
BrowserDynamicTestingModule,
|
|
21
|
-
platformBrowserDynamicTesting()
|
|
22
|
-
);
|
|
23
|
-
// Then we find all the tests.
|
|
24
|
-
const context = require.context('./', true, /\.spec\.ts$/);
|
|
25
|
-
// And load the modules.
|
|
26
|
-
context.keys().map(context);
|
package/tsconfig.lib.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/lib",
|
|
6
|
-
"target": "es2015",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"inlineSources": true,
|
|
10
|
-
"types": [],
|
|
11
|
-
"lib": [
|
|
12
|
-
"dom",
|
|
13
|
-
"es2018"
|
|
14
|
-
]
|
|
15
|
-
},
|
|
16
|
-
"angularCompilerOptions": {
|
|
17
|
-
"skipTemplateCodegen": true,
|
|
18
|
-
"strictMetadataEmit": true,
|
|
19
|
-
"enableResourceInlining": true
|
|
20
|
-
},
|
|
21
|
-
"exclude": [
|
|
22
|
-
"src/test.ts",
|
|
23
|
-
"**/*.spec.ts"
|
|
24
|
-
]
|
|
25
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "./tsconfig.lib.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"declarationMap": false
|
|
6
|
-
},
|
|
7
|
-
"angularCompilerOptions": {
|
|
8
|
-
"enableIvy": false,
|
|
9
|
-
"strictMetadataEmit": false
|
|
10
|
-
}
|
|
11
|
-
}
|
package/tsconfig.spec.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/spec",
|
|
6
|
-
"types": [
|
|
7
|
-
"jasmine"
|
|
8
|
-
]
|
|
9
|
-
},
|
|
10
|
-
"files": [
|
|
11
|
-
"src/test.ts"
|
|
12
|
-
],
|
|
13
|
-
"include": [
|
|
14
|
-
"**/*.spec.ts",
|
|
15
|
-
"**/*.d.ts"
|
|
16
|
-
]
|
|
17
|
-
}
|