@becollective/utils 1.10.2 → 2.0.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/.semaphore/utils.yml +1 -1
- package/index.ts +7 -0
- package/lib/FeatureFlag.d.ts +12 -0
- package/lib/FeatureFlag.js +51 -0
- package/lib/constants/allowedHtmlTags.d.ts +7 -0
- package/lib/constants/allowedHtmlTags.js +8 -0
- package/lib/constants/avatarColours.d.ts +35 -0
- package/lib/constants/avatarColours.js +36 -0
- package/lib/constants/countries.d.ts +253 -0
- package/lib/constants/countries.js +254 -0
- package/lib/constants/currencies.d.ts +29 -0
- package/lib/constants/currencies.js +36 -0
- package/lib/constants/customFields.d.ts +11 -0
- package/lib/constants/customFields.js +12 -0
- package/lib/constants/distancesUnits.d.ts +11 -0
- package/lib/constants/distancesUnits.js +13 -0
- package/lib/constants/groups.d.ts +13 -0
- package/lib/constants/groups.js +85 -0
- package/lib/constants/insuranceStatuses.d.ts +15 -0
- package/lib/constants/insuranceStatuses.js +7 -0
- package/lib/constants/insuranceTypes.d.ts +35 -0
- package/lib/constants/insuranceTypes.js +36 -0
- package/lib/constants/languages.d.ts +2 -0
- package/lib/constants/languages.js +194 -0
- package/lib/constants/locales.d.ts +119 -0
- package/lib/constants/locales.js +191 -0
- package/lib/constants/notifications.d.ts +47 -0
- package/lib/constants/notifications.js +31 -0
- package/lib/constants/opportunities.d.ts +72 -0
- package/lib/constants/opportunities.js +82 -0
- package/lib/constants/qualificationTypes.d.ts +4 -0
- package/lib/constants/qualificationTypes.js +18 -0
- package/lib/constants/rules.d.ts +13 -0
- package/lib/constants/rules.js +21 -0
- package/lib/constants/subscriptions.d.ts +9 -0
- package/lib/constants/subscriptions.js +10 -0
- package/lib/constants/surveys.d.ts +16 -0
- package/lib/constants/surveys.js +17 -0
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +76 -0
- package/lib/date-time.d.ts +28 -0
- package/lib/date-time.js +79 -0
- package/lib/forms.d.ts +1 -0
- package/lib/forms.js +728 -0
- package/lib/locality.d.ts +5 -0
- package/lib/locality.js +15 -0
- package/lib/money.d.ts +7 -0
- package/lib/money.js +32 -0
- package/lib/opportunity.d.ts +1 -0
- package/lib/opportunity.js +11 -0
- package/lib/opportunityUser.d.ts +8 -0
- package/lib/opportunityUser.js +29 -0
- package/lib/password.d.ts +8 -0
- package/lib/password.js +43 -0
- package/lib/rrule/date.d.ts +4 -0
- package/lib/rrule/date.js +30 -0
- package/lib/rrule/index.d.ts +2 -0
- package/lib/rrule/index.js +18 -0
- package/lib/rrule/parsing.d.ts +6 -0
- package/lib/rrule/parsing.js +130 -0
- package/lib/rrule/parsing.test.d.ts +1 -0
- package/lib/rrule/parsing.test.js +11 -0
- package/lib/rrule.d.ts +49 -0
- package/lib/rrule.js +303 -0
- package/lib/src/FeatureFlag.d.ts +12 -0
- package/lib/src/FeatureFlag.js +51 -0
- package/lib/src/date-time.d.ts +28 -0
- package/lib/src/date-time.js +79 -0
- package/lib/src/forms.d.ts +1 -0
- package/lib/src/forms.js +728 -0
- package/lib/src/locality.d.ts +5 -0
- package/lib/src/locality.js +15 -0
- package/lib/src/money.d.ts +7 -0
- package/lib/src/money.js +32 -0
- package/lib/src/opportunity.d.ts +1 -0
- package/lib/src/opportunity.js +11 -0
- package/lib/src/opportunityUser.d.ts +8 -0
- package/lib/src/opportunityUser.js +29 -0
- package/lib/src/password.d.ts +8 -0
- package/lib/src/password.js +43 -0
- package/package.json +15 -29
- package/src/FeatureFlag.ts +26 -10
- package/src/constants/allowedHtmlTags.ts +6 -0
- package/src/constants/avatarColours.ts +34 -0
- package/src/constants/countries.ts +252 -0
- package/src/constants/currencies.ts +33 -0
- package/src/constants/customFields.ts +10 -0
- package/src/constants/distancesUnits.ts +11 -0
- package/src/constants/groups.ts +83 -0
- package/src/constants/insuranceStatuses.ts +5 -0
- package/src/constants/insuranceTypes.ts +34 -0
- package/src/constants/languages.ts +192 -0
- package/src/constants/locales.ts +189 -0
- package/src/constants/notifications.ts +30 -0
- package/src/constants/opportunities.ts +84 -0
- package/src/constants/qualificationTypes.ts +17 -0
- package/src/constants/rules.ts +22 -0
- package/src/constants/subscriptions.ts +8 -0
- package/src/constants/surveys.ts +15 -0
- package/src/constants.ts +40 -0
- package/src/{date-time.js → date-time.ts} +18 -11
- package/src/forms.ts +807 -0
- package/src/{opportunityUser.js → opportunityUser.ts} +5 -1
- package/src/{password.js → password.ts} +2 -0
- package/src/rrule/date.ts +25 -0
- package/src/rrule/index.ts +2 -0
- package/src/rrule/parsing.ts +136 -0
- package/src/rrule.ts +367 -0
- package/tests/{date-time.test.js → date-time.test.ts} +48 -46
- package/tests/featureFlag.test.ts +36 -39
- package/tests/forms.test-data.json +43 -0
- package/tests/forms.test-schema.json +144 -0
- package/tests/forms.test-uischema.json +117 -0
- package/tests/forms.test.ts +674 -0
- package/tests/{money.test.js → money.test.ts} +2 -3
- package/tests/{password.test.js → password.test.ts} +7 -6
- package/tests/rrule/parsing.test.ts +12 -0
- package/tests/rrule.test.ts +625 -0
- package/tsconfig.json +15 -12
- package/bundle.js +0 -270
- package/index.js +0 -25
- package/rollup.config.js +0 -25
- /package/src/{locality.js → locality.ts} +0 -0
- /package/src/{money.js → money.ts} +0 -0
- /package/src/{opportunity.js → opportunity.ts} +0 -0
package/lib/date-time.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getShiftText = exports.datesByThemselves = exports.isUnderAge = exports.isUnderSixteen = exports.getAge = void 0;
|
|
4
|
+
const luxon_1 = require("luxon");
|
|
5
|
+
/**
|
|
6
|
+
* Get current age based on the given birth date
|
|
7
|
+
* @param {string} dateOfBirth
|
|
8
|
+
* @param {string} unit the measurement of the the difference
|
|
9
|
+
* The supported measurements are:
|
|
10
|
+
* years, months, weeks, days, hours, minutes, and seconds.
|
|
11
|
+
* @returns {number} age
|
|
12
|
+
*/
|
|
13
|
+
const getAge = (dateOfBirth, unit = 'years') => {
|
|
14
|
+
if (!dateOfBirth) {
|
|
15
|
+
throw new Error('Invalid date');
|
|
16
|
+
}
|
|
17
|
+
const dob = luxon_1.DateTime.fromJSDate(new Date(dateOfBirth));
|
|
18
|
+
if (!dob.isValid) {
|
|
19
|
+
throw new Error('Invalid date');
|
|
20
|
+
}
|
|
21
|
+
const age = dob.diffNow(unit);
|
|
22
|
+
const ageUnit = -age.as(unit);
|
|
23
|
+
// Note: luxon returns scientific notation, ie 6.976154236428209e-9
|
|
24
|
+
return Number(ageUnit.toString().split('.').shift());
|
|
25
|
+
};
|
|
26
|
+
exports.getAge = getAge;
|
|
27
|
+
/**
|
|
28
|
+
* Check if a user requires parent(guardian) consent
|
|
29
|
+
* i.e. Is under the age of 16 years, based on GDPR
|
|
30
|
+
* https://gdpr-info.eu/art-8-gdpr/
|
|
31
|
+
* @param {string} dateOfBirth moment.js compatible date time
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
* NOTE:
|
|
34
|
+
* We used to not allow child (under 16) to register,
|
|
35
|
+
* and birthdate is not a required field for ghost user
|
|
36
|
+
* So an existing user could have no birthdate, we assume these users are adults
|
|
37
|
+
* TODO:
|
|
38
|
+
* Remove above logic after we migrated all legacy
|
|
39
|
+
* data to have a consistent birthdate property.
|
|
40
|
+
* Then we should throw error if birthdate is not valid
|
|
41
|
+
*/
|
|
42
|
+
const isUnderSixteen = (dateOfBirth) => {
|
|
43
|
+
if (!dateOfBirth || !luxon_1.DateTime.fromJSDate(new Date(dateOfBirth)).isValid) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const age = (0, exports.getAge)(dateOfBirth);
|
|
47
|
+
return isNaN(age) ? false : age < 16;
|
|
48
|
+
};
|
|
49
|
+
exports.isUnderSixteen = isUnderSixteen;
|
|
50
|
+
const isUnderAge = (dateOfBirth, limit, maxAcknowledgedAge = null) => {
|
|
51
|
+
if ((!dateOfBirth || !luxon_1.DateTime.fromJSDate(new Date(dateOfBirth)).isValid) && !maxAcknowledgedAge) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (dateOfBirth) {
|
|
55
|
+
const age = (0, exports.getAge)(dateOfBirth);
|
|
56
|
+
return isNaN(age) ? true : age < limit;
|
|
57
|
+
}
|
|
58
|
+
return maxAcknowledgedAge ? maxAcknowledgedAge < limit : true;
|
|
59
|
+
};
|
|
60
|
+
exports.isUnderAge = isUnderAge;
|
|
61
|
+
const datesByThemselves = (a, b) => {
|
|
62
|
+
if (!a.from)
|
|
63
|
+
return 1;
|
|
64
|
+
return new Date(a.from).getTime() - new Date(b.from).getTime();
|
|
65
|
+
};
|
|
66
|
+
exports.datesByThemselves = datesByThemselves;
|
|
67
|
+
const getShiftText = (from, to, timezone) => {
|
|
68
|
+
try {
|
|
69
|
+
if (!from || !to || !timezone)
|
|
70
|
+
return '';
|
|
71
|
+
const startToTimezone = luxon_1.DateTime.fromJSDate(from).setZone(timezone);
|
|
72
|
+
const endToTimezone = luxon_1.DateTime.fromJSDate(to).setZone(timezone);
|
|
73
|
+
return `${startToTimezone.toFormat('cccc, DD, h:mma')}-${endToTimezone.toFormat('h:mma')}`;
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
return '';
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.getShiftText = getShiftText;
|
package/lib/forms.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|