@stbmoz-onboarding/core 1.1.4 → 1.1.6

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/Dates/dates.js CHANGED
@@ -20,9 +20,24 @@ module.exports.DateFormater = (date, format) => {
20
20
  }
21
21
  }
22
22
 
23
+ const dateGenerator = (date) => {
24
+ date = date.slice(0, 10)
25
+ const _date = date.split('-')
26
+ const newDate = new Date()
27
+ const month = parseInt(_date[1]) -1;
28
+
29
+ newDate.setFullYear(_date[0])
30
+ newDate.setMonth(month)
31
+ newDate.setDate(_date[2])
32
+
33
+ return newDate
34
+
35
+ }
36
+
23
37
  module.exports.ValidateDate = (values, key, errors, invalidDateMsg) => {
24
38
  try {
25
- const date = new Date(values[key])
39
+ const date = dateGenerator(values[key])
40
+
26
41
  if (date == "Invalid Date") {
27
42
  errors[key] = invalidDateMsg
28
43
  } else {
@@ -31,4 +46,47 @@ module.exports.ValidateDate = (values, key, errors, invalidDateMsg) => {
31
46
  } catch (error) {
32
47
  errors[key] = invalidDateMsg
33
48
  }
34
- }
49
+ }
50
+
51
+
52
+ module.exports.isValidRange = (date, rangeLimit) => {
53
+ let today = new Date()
54
+ let dateObj = new Date(date)
55
+ let range = today.getFullYear() - dateObj.getFullYear()
56
+ let m = today.getMonth() - dateObj.getMonth()
57
+ if (m < 0 || (m === 0 && today.getDate() < dateObj.getDate())) {
58
+ range--
59
+ }
60
+ if (range <= rangeLimit) return true
61
+ }
62
+
63
+
64
+ module.exports.isValidRangeFuture = (date, rangeLimit) => {
65
+ let today = new Date()
66
+ let dateObj = new Date(date)
67
+ let range = dateObj.getFullYear() - today.getFullYear()
68
+ let m = dateObj.getMonth() - today.getMonth()
69
+ if (m < 0 || (m === 0 && today.getDate() < dateObj.getDate())) {
70
+ range--
71
+ }
72
+
73
+ if (range <= rangeLimit) return true
74
+ }
75
+
76
+ module.exports.isInFuture = (date) => {
77
+
78
+ let today = new Date()
79
+ let dateObj = new Date(date)
80
+ if (dateObj <= today) {
81
+ return true
82
+ }
83
+ }
84
+ module.exports.isInPast = (date) => {
85
+
86
+ let today = new Date()
87
+ let dateObj = new Date(date)
88
+ if (dateObj >= today) {
89
+ return true
90
+ }
91
+ }
92
+
package/Dates/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const { DateFormater, ValidateDate } = require("./dates")
1
+ const { DateFormater, ValidateDate, isValidRange, isInFuture, isInPast, isValidRangeFuture } = require("./dates")
2
2
 
3
3
 
4
- module.exports = { DateFormater, ValidateDate }
4
+ module.exports = { DateFormater, ValidateDate, isValidRange, isInFuture, isInPast, isValidRangeFuture }
@@ -44,7 +44,7 @@ module.exports.provinces = [
44
44
  {
45
45
  value: "08",
46
46
  default:"40000",
47
- pt: "Zambézia",
47
+ pt: "Zambezia",
48
48
  en: "Zambezia"
49
49
  },
50
50
  {
@@ -1,12 +1,13 @@
1
- const {
2
- isBIValid, isMinor, isPDF, isValidCertificateNumber, isValidNuit,
3
- WordsCount, allowedCharsOnly, containesWhiteSpace, isAboveMaxLength,
4
- isContactValid, isEmailValid, isIn, isInteger, isLength, isMinLength,
5
- isMinValue, isPasswordStrong, isSameAs, startsWith
6
- } = require("./rules")
1
+ const {
2
+ isBIValid, isMinor, isOlder, isPDF, isValidCertificateNumber, isValidNuit,
3
+ WordsCount, allowedCharsOnly, containesWhiteSpace, isAboveMaxLength,
4
+ isContactValid, isEmailValid, isIn, isInteger, isLength, isMinLength,
5
+ isMinValue, isPasswordStrong, isSameAs, startsWith
6
+ } = require("./rules")
7
7
 
8
- module.exports = {
9
- isBIValid, isMinor, isPDF, isValidCertificateNumber, isValidNuit,
10
- WordsCount, allowedCharsOnly, containesWhiteSpace, isAboveMaxLength,
11
- isContactValid, isEmailValid, isIn, isInteger, isLength, isMinLength,
12
- isMinValue, isPasswordStrong, isSameAs, startsWith }
8
+ module.exports = {
9
+ isBIValid, isMinor, isOlder, isPDF, isValidCertificateNumber, isValidNuit,
10
+ WordsCount, allowedCharsOnly, containesWhiteSpace, isAboveMaxLength,
11
+ isContactValid, isEmailValid, isIn, isInteger, isLength, isMinLength,
12
+ isMinValue, isPasswordStrong, isSameAs, startsWith
13
+ }
@@ -142,6 +142,17 @@ module.exports.isMinor = (dateOfBirth, ageLimit) => {
142
142
  if (age >= ageLimit) return true
143
143
  }
144
144
 
145
+ module.exports.isOlder = (dateOfBirth, ageLimit) =>{
146
+ let today = new Date()
147
+ let birthDate = new Date(dateOfBirth)
148
+ let age = today.getFullYear() - birthDate.getFullYear()
149
+ let m = today.getMonth() - birthDate.getMonth()
150
+ if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
151
+ age--
152
+ }
153
+ if (age <= ageLimit) return true
154
+ }
155
+
145
156
  module.exports.isBIValid = (BINumber) => {
146
157
  if (/^([0-9]{12})+([A-Z]\b)$/.test(BINumber)) {
147
158
  return true
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const { DateFormater, ValidateDate } = require("./Dates/dates")
1
+ const { DateFormater, ValidateDate, isValidRange, isInFuture, isInPast, isValidRangeFuture} = require("./Dates/dates")
2
2
  const {
3
3
  AllowedPrefixes, GenerateNumericPin, ReferenceGenerator, Sanitize, Serializer,
4
4
  removeFile, SubArrayGenerator
@@ -20,18 +20,18 @@ const { districts } = require("./Utilities/districts")
20
20
  const { segment, segments } = require("./Utilities/segments")
21
21
  const { AllowedChars } = require("./Utilities/allowedChars")
22
22
  const {
23
- isBIValid, isMinor, isPDF, isValidCertificateNumber, isValidNuit,
23
+ isBIValid, isMinor, isOlder, isPDF, isValidCertificateNumber, isValidNuit,
24
24
  WordsCount, allowedCharsOnly, containesWhiteSpace, isAboveMaxLength,
25
25
  isContactValid, isEmailValid, isIn, isInteger, isLength, isMinLength,
26
26
  isMinValue, isPasswordStrong, isSameAs, startsWith
27
27
  } = require("./Validations/rules")
28
28
 
29
29
  const { branch } = require("./Utilities/branch")
30
- const { incomeFrequecies} = require("./Utilities/incomeFrequencies")
30
+ const { incomeFrequecies } = require("./Utilities/incomeFrequencies")
31
31
  const { neighborhood } = require("./Utilities/neighborhood")
32
32
 
33
33
 
34
- module.exports.Dates = { DateFormater, ValidateDate }
34
+ module.exports.Dates = { DateFormater, ValidateDate, isValidRange, isInFuture, isInPast,isValidRangeFuture }
35
35
 
36
36
  module.exports.Functions = {
37
37
  AllowedPrefixes, GenerateNumericPin, ReferenceGenerator, Sanitize, Serializer, removeFile,
@@ -46,7 +46,7 @@ module.exports.Utilities = {
46
46
  }
47
47
 
48
48
  module.exports.Validations = {
49
- isBIValid, isMinor, isPDF, isValidCertificateNumber, isValidNuit,
49
+ isBIValid, isMinor, isOlder, isPDF, isValidCertificateNumber, isValidNuit,
50
50
  WordsCount, allowedCharsOnly, containesWhiteSpace, isAboveMaxLength,
51
51
  isContactValid, isEmailValid, isIn, isInteger, isLength, isMinLength,
52
52
  isMinValue, isPasswordStrong, isSameAs, startsWith
package/package.json CHANGED
@@ -1,34 +1,34 @@
1
1
  {
2
2
  "_args": [
3
3
  [
4
- "@stbmoz-onboarding/core@1.1.44",
4
+ "@stbmoz-onboarding/core@1.1.6",
5
5
  "/Users/pedrodava/Desktop/Bank/RAO/frontend"
6
6
  ]
7
7
  ],
8
- "_from": "@stbmoz-onboarding/core@^1.1.4",
9
- "_id": "@stbmoz-onboarding/core@1.1.4",
8
+ "_from": "@stbmoz-onboarding/core@^1.1.6",
9
+ "_id": "@stbmoz-onboarding/core@1.1.6",
10
10
  "_inBundle": false,
11
- "_integrity": "sha512-49Uu6x1QbTWFMWRZQz1A28IjRmo8hA22izluXc5Y2yiDii51nvRvLj/Hu3AjGOYvHlWa+j8J1nVh0fmt93WCnA==",
11
+ "_integrity": "sha512-jzmeLgErpseqkKJsWBERFiB/wMS6BeSgH9OK1r2uzOWWgKO3iOCUCywu06I5dGSy5xZfRKejG+MNV3KqW4fwQw==",
12
12
  "_location": "/@stbmoz-onboarding/core",
13
13
  "_phantomChildren": {},
14
14
  "_requested": {
15
15
  "type": "range",
16
16
  "registry": true,
17
- "raw": "@stbmoz-onboarding/core@^1.1.4",
17
+ "raw": "@stbmoz-onboarding/core@^1.1.6",
18
18
  "name": "@stbmoz-onboarding/core",
19
19
  "escapedName": "@stbmoz-onboarding%2fcore",
20
20
  "scope": "@stbmoz-onboarding",
21
- "rawSpec": "^1.1.4",
21
+ "rawSpec": "^1.1.6",
22
22
  "saveSpec": null,
23
- "fetchSpec": "^1.1.4"
23
+ "fetchSpec": "^1.1.6"
24
24
  },
25
25
  "_requiredBy": [
26
26
  "#USER",
27
27
  "/"
28
28
  ],
29
- "_resolved": "https://registry.npmjs.org/@stbmoz-onboarding/core/-/core-1.1.4.tgz",
30
- "_shasum": "87974a4970b4ae2a12a290bb2ab0d415aab344d1",
31
- "_spec": "@stbmoz-onboarding/core@^1.1.4",
29
+ "_resolved": "https://registry.npmjs.org/@stbmoz-onboarding/core/-/core-1.1.6.tgz",
30
+ "_shasum": "0222e0ea09cafcfddf3bfa6886d142f1e54256c1",
31
+ "_spec": "@stbmoz-onboarding/core@^1.1.6",
32
32
  "_where": "/Users/pedrodava/Desktop/Bank/RAO/frontend",
33
33
  "author": "",
34
34
  "bundleDependencies": false,
@@ -42,5 +42,5 @@
42
42
  "test": "echo \"Error: no test specified\" && exit 1"
43
43
  },
44
44
  "type": "commonjs",
45
- "version": "1.1.4"
45
+ "version": "1.1.6"
46
46
  }