@becollective/utils 1.9.0 → 1.9.2
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/bundle.js +8 -4
- package/package.json +2 -2
- package/src/date-time.js +8 -4
- package/tests/date-time.test.js +25 -3
package/bundle.js
CHANGED
|
@@ -105,13 +105,17 @@ var isUnderSixteen = function isUnderSixteen(dateOfBirth) {
|
|
|
105
105
|
var age = getAge(dateOfBirth);
|
|
106
106
|
return isNaN(age) ? false : age < 16;
|
|
107
107
|
};
|
|
108
|
-
var isUnderAge = function isUnderAge(dateOfBirth, limit) {
|
|
109
|
-
if (!dateOfBirth || !moment(dateOfBirth).isValid()) {
|
|
108
|
+
var isUnderAge = function isUnderAge(dateOfBirth, limit, maxAcknowledgedAge) {
|
|
109
|
+
if ((!dateOfBirth || !moment(dateOfBirth).isValid()) && !maxAcknowledgedAge) {
|
|
110
110
|
return false;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
if (dateOfBirth) {
|
|
114
|
+
var age = getAge(dateOfBirth);
|
|
115
|
+
return isNaN(age) ? true : age < limit;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return maxAcknowledgedAge ? maxAcknowledgedAge < limit : true;
|
|
115
119
|
};
|
|
116
120
|
var datesByThemselves = function datesByThemselves(a, b) {
|
|
117
121
|
if (!a.from) return 1;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@becollective/utils",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "Common utilities",
|
|
5
5
|
"main": "bundle.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "NODE_ENV=localtest jest --config jestconfig.json --detectOpenHandles --verbose --forceExit",
|
|
7
|
+
"test": "npm run build && NODE_ENV=localtest jest --config jestconfig.json --detectOpenHandles --verbose --forceExit",
|
|
8
8
|
"build": "rollup -c",
|
|
9
9
|
"prepare": "npm run build"
|
|
10
10
|
},
|
package/src/date-time.js
CHANGED
|
@@ -38,12 +38,16 @@ export const isUnderSixteen = (dateOfBirth) => {
|
|
|
38
38
|
return isNaN(age) ? false : age < 16;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
export const isUnderAge = (dateOfBirth, limit) => {
|
|
42
|
-
if (!dateOfBirth || !moment(dateOfBirth).isValid()) {
|
|
41
|
+
export const isUnderAge = (dateOfBirth, limit, maxAcknowledgedAge) => {
|
|
42
|
+
if ((!dateOfBirth || !moment(dateOfBirth).isValid()) && !maxAcknowledgedAge) {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
|
|
46
|
+
if(dateOfBirth) {
|
|
47
|
+
const age = getAge(dateOfBirth);
|
|
48
|
+
return isNaN(age) ? true : age < limit;
|
|
49
|
+
}
|
|
50
|
+
return maxAcknowledgedAge ? maxAcknowledgedAge < limit : true;
|
|
47
51
|
};
|
|
48
52
|
|
|
49
53
|
export const datesByThemselves = (a, b) => {
|
package/tests/date-time.test.js
CHANGED
|
@@ -56,8 +56,7 @@ describe('isUnderSixteen', () => {
|
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
describe('isUnderAge', () => {
|
|
59
|
+
describe('isUnderAge - dateOfBirth', () => {
|
|
61
60
|
const refPoint = moment().subtract(13, 'years');
|
|
62
61
|
const obj = {};
|
|
63
62
|
test('Is not U13 if dob is 13 years ago', () => {
|
|
@@ -85,6 +84,30 @@ describe('isUnderAge', () => {
|
|
|
85
84
|
});
|
|
86
85
|
});
|
|
87
86
|
|
|
87
|
+
describe('isUnderAge - maxAcknowledgedAge', () => {
|
|
88
|
+
const obj = {};
|
|
89
|
+
test('Is not U13 if maxAcknowledgedAge is 13 years ago', () => {
|
|
90
|
+
expect(isUnderAge(null, 13, 13)).toBe(false);
|
|
91
|
+
expect(isUnderAge(null, 13, 14)).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('Is U13 if maxAcknowledgedAge is less than X years ago', () => {
|
|
95
|
+
expect(isUnderAge(null, 13, 10)).toBe(true);
|
|
96
|
+
expect(isUnderAge(null, 13, 12)).toBe(true);
|
|
97
|
+
expect(isUnderAge(null, 13, 12.5)).toBe(true);
|
|
98
|
+
expect(isUnderAge(null, 13, 13)).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('Undefined maxAcknowledgedAge', () => {
|
|
102
|
+
expect(isUnderAge(null, 13, obj.notDefined)).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
test('Null maxAcknowledgedAge', () => {
|
|
105
|
+
expect(isUnderAge(null, 13, null)).toBe(false);
|
|
106
|
+
});
|
|
107
|
+
test('Invalid value', () => {
|
|
108
|
+
expect(isUnderAge(null, 13, '13x')).toBe(false);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
88
111
|
|
|
89
112
|
describe('isUnderAge - 10', () => {
|
|
90
113
|
const refPoint = moment().subtract(10, 'years');
|
|
@@ -104,7 +127,6 @@ describe('isUnderAge - 10', () => {
|
|
|
104
127
|
});
|
|
105
128
|
});
|
|
106
129
|
|
|
107
|
-
|
|
108
130
|
describe('isUnderAge - over 13', () => {
|
|
109
131
|
const refPoint = moment().subtract(15, 'years');
|
|
110
132
|
const obj = {};
|