@medipass/utils 11.72.0 → 11.73.1-chore-remove-is-mobile-number-lib.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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [11.73.0](https://github.com/medipass/web-medicules/compare/@medipass/utils@11.72.0...@medipass/utils@11.73.0) (2022-11-04)
7
+
8
+
9
+ ### Features
10
+
11
+ * **web-sdk, utils:** abr resource and abn validators ([#704](https://github.com/medipass/web-medicules/issues/704)) ([531b969](https://github.com/medipass/web-medicules/commit/531b969))
12
+
13
+
14
+
15
+
16
+
6
17
  # [11.72.0](https://github.com/medipass/web-medicules/compare/@medipass/utils@11.71.0...@medipass/utils@11.72.0) (2022-10-30)
7
18
 
8
19
 
package/abn.js ADDED
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var ABN_LENGTH = 11;
6
+ var ACN_LENGTH = 9;
7
+ var normaliseAbn = function normaliseAbn(abn) {
8
+ var trimmedABN = abn == null ? void 0 : abn.replace(/\s/g, ''); // The input is an ABN, in which case the format should be 99 999 999 999
9
+
10
+ if (trimmedABN.length === ABN_LENGTH) {
11
+ return trimmedABN.substring(0, 2) + ' ' + trimmedABN.substring(2, 5) + ' ' + trimmedABN.substring(5, 8) + ' ' + trimmedABN.substring(8);
12
+ } //The input is an ACN, in which case the format should be 999 999 999
13
+
14
+
15
+ if (trimmedABN.length === ACN_LENGTH) {
16
+ return trimmedABN.substring(0, 3) + ' ' + trimmedABN.substring(3, 6) + ' ' + trimmedABN.substring(6);
17
+ }
18
+
19
+ return abn;
20
+ };
21
+ var isValidAbn = function isValidAbn(abn) {
22
+ var VALID_ABN_LENGTH = 11; // strip whitespace from value
23
+
24
+ abn = String(abn).replace(/\s+/g, '');
25
+
26
+ if (abn.length === VALID_ABN_LENGTH) {
27
+ var weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
28
+ var abnArray = [];
29
+
30
+ for (var i = 0; i < abn.length; i++) {
31
+ abnArray[i] = abn.charAt(i);
32
+ } // subtract 1 from the left-most digit
33
+
34
+
35
+ abnArray[0] -= 1; // multiply each of the digits by its weighting factor
36
+
37
+ for (var _i = 0; _i < abnArray.length; _i++) {
38
+ abnArray[_i] *= weights[_i];
39
+ } // sum all the digits
40
+
41
+
42
+ var abnSum = 0;
43
+
44
+ for (var _i2 = 0; _i2 < abnArray.length; _i2++) {
45
+ abnSum += abnArray[_i2];
46
+ }
47
+
48
+ return abnSum % 89 === 0;
49
+ } else {
50
+ return false;
51
+ }
52
+ };
53
+ var isValidAcn = function isValidAcn(acn) {
54
+ var VALID_ACN_LENGTH = 9; // strip whitespace from value
55
+
56
+ acn = String(acn).replace(/\s+/g, '');
57
+
58
+ if (acn.length === VALID_ACN_LENGTH) {
59
+ var weights = [8, 7, 6, 5, 4, 3, 2, 1];
60
+ var acnArray = [];
61
+
62
+ for (var i = 0; i < acn.length; i++) {
63
+ acnArray[i] = parseInt(acn.charAt(i));
64
+ }
65
+
66
+ var acnSum = 0; // sum the digits 1-8
67
+
68
+ for (var _i3 = 0; _i3 < weights.length; _i3++) {
69
+ acnSum = acnSum + acnArray[_i3] * weights[_i3];
70
+ } // divide by 10 and take remainder
71
+
72
+
73
+ var remainder = acnSum % 10; // complement the remainder to 10
74
+
75
+ var complement = 10 - remainder; // if the complement equals 10, set it to 0
76
+
77
+ if (complement === 10) {
78
+ complement = 0;
79
+ }
80
+
81
+ return acnArray[8] === complement;
82
+ } else {
83
+ return false;
84
+ }
85
+ };
86
+
87
+ exports.isValidAbn = isValidAbn;
88
+ exports.isValidAcn = isValidAcn;
89
+ exports.normaliseAbn = normaliseAbn;
@@ -6,7 +6,10 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty'));
8
8
  var yup = require('yup');
9
- var isMobileNumber = _interopDefault(require('is-mobile-number'));
9
+ require('core-js/es6/promise');
10
+ require('core-js/es6/set');
11
+ require('google-libphonenumber');
12
+ var validate = require('./validate.js');
10
13
  var _get = _interopDefault(require('lodash/get'));
11
14
 
12
15
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -992,7 +995,7 @@ var FIELD_VALIDATORS = {
992
995
  type: 'test',
993
996
  message: 'Please enter a valid Australian mobile number',
994
997
  fn: function fn(value) {
995
- return value ? isMobileNumber(value, 'AU') : true;
998
+ return value ? validate.isMobileNumber(value, 'AU') : true;
996
999
  }
997
1000
  }]
998
1001
  },
package/index.js CHANGED
@@ -8,6 +8,7 @@ require('@babel/runtime/helpers/defineProperty');
8
8
  require('yup');
9
9
  require('core-js/es6/promise');
10
10
  require('core-js/es6/set');
11
+ require('google-libphonenumber');
11
12
  var validate = require('./validate.js');
12
13
  require('@babel/runtime/regenerator');
13
14
  require('@babel/runtime/helpers/asyncToGenerator');
@@ -0,0 +1 @@
1
+ export {};
package/lib/abn.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare const normaliseAbn: (abn: string) => string;
2
+ export declare const isValidAbn: (abn: string) => boolean;
3
+ export declare const isValidAcn: (acn: string) => boolean;
@@ -42,7 +42,7 @@ export declare const FIELD_VALIDATORS: {
42
42
  } | {
43
43
  type: string;
44
44
  message: string;
45
- fn: (value: any) => any;
45
+ fn: (value: any) => boolean;
46
46
  })[];
47
47
  };
48
48
  password: {
package/lib/index.d.ts CHANGED
@@ -42,6 +42,7 @@ declare const _default: {
42
42
  isNumber: (number: any) => Promise<boolean>;
43
43
  isStringLength: (length: any, value: any) => Promise<boolean>;
44
44
  isUrl: (value: any) => Promise<boolean>;
45
+ isMobileNumber: (phoneNumber: string, countryCode: string) => boolean;
45
46
  };
46
47
  };
47
48
  export default _default;
@@ -41,5 +41,8 @@ export declare const hasSpaceAfterHyphen: (value: any) => string;
41
41
  export declare const hasSpaceBeforeHyphen: (value: any) => string;
42
42
  export declare const hasSpaceAfterApostrophe: (value: any) => string;
43
43
  export declare const hasSpaceBeforeApostrophe: (value: any) => string;
44
+ export declare const isValidAbn: (value: string) => string;
45
+ export declare const isValidAcn: (value: string) => string;
46
+ export declare const isValidAbnOrAcn: (value: string) => string;
44
47
  declare const combineValidators: (...fns: any[]) => (value: any) => any;
45
48
  export default combineValidators;
package/lib/validate.d.ts CHANGED
@@ -5,11 +5,13 @@ export declare const isEmail: (email: any) => Promise<boolean>;
5
5
  export declare const isNumber: (number: any) => Promise<boolean>;
6
6
  export declare const isStringLength: (length: any, value: any) => Promise<boolean>;
7
7
  export declare const isUrl: (value: any) => Promise<boolean>;
8
- declare const _default: {
8
+ export declare const isMobileNumber: (phoneNumber: string, countryCode: string) => boolean;
9
+ declare const validate: {
9
10
  isEmail: (email: any) => Promise<boolean>;
10
11
  isNotEmpty: (value: any) => Promise<boolean>;
11
12
  isNumber: (number: any) => Promise<boolean>;
12
13
  isStringLength: (length: any, value: any) => Promise<boolean>;
13
14
  isUrl: (value: any) => Promise<boolean>;
15
+ isMobileNumber: (phoneNumber: string, countryCode: string) => boolean;
14
16
  };
15
- export default _default;
17
+ export default validate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medipass/utils",
3
- "version": "11.72.0",
3
+ "version": "11.73.1-chore-remove-is-mobile-number-lib.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -31,8 +31,8 @@
31
31
  "enzyme-adapter-react-16": "1.15.6",
32
32
  "enzyme-to-json": "3.3.4",
33
33
  "escape-html": "1.0.3",
34
+ "google-libphonenumber": "3.2.31",
34
35
  "i18next": "19.6.3",
35
- "is-mobile-number": "1.0.3",
36
36
  "lodash": "4.17.21",
37
37
  "masked": "1.1.0",
38
38
  "moment": "2.22.2",
@@ -51,5 +51,5 @@
51
51
  "rimraf": "^2.6.2",
52
52
  "typescript": "4.8.4"
53
53
  },
54
- "gitHead": "6bd756261aacc641c65a4f7f82033fd02f21e432"
54
+ "gitHead": "159a88b238d9695e6915e18c6f9cf9ec5d19004f"
55
55
  }
package/validate-form.js CHANGED
@@ -7,10 +7,10 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
7
7
  require('yup');
8
8
  require('core-js/es6/promise');
9
9
  require('core-js/es6/set');
10
+ require('google-libphonenumber');
10
11
  var validate = require('./validate.js');
11
12
  var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator'));
12
13
  var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator'));
13
- var isMobileNumber = _interopDefault(require('is-mobile-number'));
14
14
  var _isArray = _interopDefault(require('lodash/isArray'));
15
15
  var _get = _interopDefault(require('lodash/get'));
16
16
  var format = _interopDefault(require('date-fns/format'));
@@ -18,6 +18,7 @@ var isBefore = _interopDefault(require('date-fns/isBefore'));
18
18
  var isFuture = _interopDefault(require('date-fns/isFuture'));
19
19
  var isValid = _interopDefault(require('date-fns/isValid'));
20
20
  var parse = _interopDefault(require('date-fns/parse'));
21
+ var abn = require('./abn.js');
21
22
 
22
23
  var isRequired = function isRequired(value) {
23
24
  return !value || value.trim && !value.trim() || _isArray(value) && value.length === 0 ? 'This field is required' : undefined;
@@ -152,7 +153,7 @@ var isValidEmail = function isValidEmail(value) {
152
153
  return !value || /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+$/i.test(value) ? undefined : 'Please enter a valid email';
153
154
  };
154
155
  var isValidMobile = function isValidMobile(value) {
155
- return !value || isMobileNumber(value, 'AU') ? undefined : 'Please enter a valid mobile number';
156
+ return !value || validate.isMobileNumber(value, 'AU') ? undefined : 'Please enter a valid mobile number';
156
157
  };
157
158
  var isValidDatePatterns = function isValidDatePatterns(_ref2) {
158
159
  var day = _ref2.day,
@@ -331,6 +332,29 @@ var hasSpaceAfterApostrophe = function hasSpaceAfterApostrophe(value) {
331
332
  var hasSpaceBeforeApostrophe = function hasSpaceBeforeApostrophe(value) {
332
333
  return value && /(\s['])/.test(value) ? "Name cannot have a space before an apostrophe (')" : undefined;
333
334
  };
335
+ var isValidAbn = function isValidAbn(value) {
336
+ var isValid = abn.isValidAbn(value);
337
+
338
+ if (isValid) return undefined;
339
+ return 'Invalid ABN';
340
+ };
341
+ var isValidAcn = function isValidAcn(value) {
342
+ var isValid = abn.isValidAcn(value);
343
+
344
+ if (isValid) return undefined;
345
+ return 'Invalid ACN';
346
+ };
347
+ var isValidAbnOrAcn = function isValidAbnOrAcn(value) {
348
+ if (abn.isValidAbn(value)) {
349
+ return undefined;
350
+ }
351
+
352
+ if (abn.isValidAcn(value)) {
353
+ return undefined;
354
+ }
355
+
356
+ return 'Invalid ABN or ACN';
357
+ };
334
358
 
335
359
  var combineValidators = function combineValidators() {
336
360
  for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -376,6 +400,9 @@ exports.isMoreThanThreeYears = isMoreThanThreeYears;
376
400
  exports.isNumber = isNumber;
377
401
  exports.isRequired = isRequired;
378
402
  exports.isSameValueAsField = isSameValueAsField;
403
+ exports.isValidAbn = isValidAbn;
404
+ exports.isValidAbnOrAcn = isValidAbnOrAcn;
405
+ exports.isValidAcn = isValidAcn;
379
406
  exports.isValidBankAccountName = isValidBankAccountName;
380
407
  exports.isValidDOB = isValidDOB;
381
408
  exports.isValidDate = isValidDate;
package/validate.js CHANGED
@@ -2,9 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
5
7
  var yup = require('yup');
6
8
  require('core-js/es6/promise');
7
9
  require('core-js/es6/set');
10
+ var googleLibPhoneNumber = _interopDefault(require('google-libphonenumber'));
8
11
 
9
12
  var isNotEmpty = function isNotEmpty(value) {
10
13
  return yup.mixed().required().isValid(value);
@@ -21,16 +24,36 @@ var isStringLength = function isStringLength(length, value) {
21
24
  var isUrl = function isUrl(value) {
22
25
  return yup.string().url().isValid(value);
23
26
  };
27
+ var phoneUtil = googleLibPhoneNumber.PhoneNumberUtil.getInstance();
28
+ var phoneType = googleLibPhoneNumber.PhoneNumberType;
29
+ var isMobileNumber = function isMobileNumber(phoneNumber, countryCode) {
30
+ if (!countryCode) {
31
+ throw new Error('`countryCode` not given.');
32
+ }
33
+
34
+ if (!phoneNumber) {
35
+ return false;
36
+ }
37
+
38
+ try {
39
+ var parsedPhoneNumber = phoneUtil.parse(phoneNumber, countryCode);
40
+ return phoneUtil.getNumberType(parsedPhoneNumber) === phoneType.MOBILE;
41
+ } catch (err) {
42
+ return false;
43
+ }
44
+ };
24
45
  var validate = {
25
46
  isEmail: isEmail,
26
47
  isNotEmpty: isNotEmpty,
27
48
  isNumber: isNumber,
28
49
  isStringLength: isStringLength,
29
- isUrl: isUrl
50
+ isUrl: isUrl,
51
+ isMobileNumber: isMobileNumber
30
52
  };
31
53
 
32
54
  exports.default = validate;
33
55
  exports.isEmail = isEmail;
56
+ exports.isMobileNumber = isMobileNumber;
34
57
  exports.isNotEmpty = isNotEmpty;
35
58
  exports.isNumber = isNumber;
36
59
  exports.isStringLength = isStringLength;
@@ -1,2 +0,0 @@
1
- declare const _default: (abn: any) => any;
2
- export default _default;
package/normalise-abn.js DELETED
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var ABN_LENGTH = 11;
6
- var ACN_LENGTH = 9;
7
- var normaliseAbn = (function (abn) {
8
- var trimmedABN = abn && abn.replace(/\s/g, ''); // The input is an ABN, in which case the format should be 99 999 999 999
9
-
10
- if (trimmedABN.length === ABN_LENGTH) {
11
- return trimmedABN.substring(0, 2) + ' ' + trimmedABN.substring(2, 5) + ' ' + trimmedABN.substring(5, 8) + ' ' + trimmedABN.substring(8);
12
- } //The input is an ACN, in which case the format should be 999 999 999
13
-
14
-
15
- if (trimmedABN.length === ACN_LENGTH) {
16
- return trimmedABN.substring(0, 3) + ' ' + trimmedABN.substring(3, 6) + ' ' + trimmedABN.substring(6);
17
- }
18
-
19
- return abn;
20
- });
21
-
22
- exports.default = normaliseAbn;