@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/src/constants.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import allowedHtmlTags from './constants/allowedHtmlTags';
|
|
2
|
+
import avatarColours from './constants/avatarColours';
|
|
3
|
+
import countries from './constants/countries';
|
|
4
|
+
import customFields from './constants/customFields';
|
|
5
|
+
import languages from './constants/languages';
|
|
6
|
+
import currencies from './constants/currencies';
|
|
7
|
+
import distanceUnits from './constants/distancesUnits';
|
|
8
|
+
import groups from './constants/groups';
|
|
9
|
+
import insuranceStatuses from './constants/insuranceStatuses';
|
|
10
|
+
import insuranceTypes from './constants/insuranceTypes';
|
|
11
|
+
import locales from './constants/locales';
|
|
12
|
+
import notifications from './constants/notifications';
|
|
13
|
+
import opportunities from './constants/opportunities';
|
|
14
|
+
import rules from './constants/rules';
|
|
15
|
+
import subscriptions from './constants/subscriptions';
|
|
16
|
+
import surveys from './constants/surveys';
|
|
17
|
+
|
|
18
|
+
import qualificationTypes, { licencesAndCertifications, educationalQualifications } from './constants/qualificationTypes';
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
allowedHtmlTags,
|
|
22
|
+
avatarColours,
|
|
23
|
+
currencies,
|
|
24
|
+
customFields,
|
|
25
|
+
countries,
|
|
26
|
+
languages,
|
|
27
|
+
distanceUnits,
|
|
28
|
+
groups,
|
|
29
|
+
insuranceStatuses,
|
|
30
|
+
insuranceTypes,
|
|
31
|
+
locales,
|
|
32
|
+
notifications,
|
|
33
|
+
opportunities,
|
|
34
|
+
qualificationTypes,
|
|
35
|
+
licencesAndCertifications,
|
|
36
|
+
educationalQualifications,
|
|
37
|
+
surveys,
|
|
38
|
+
subscriptions,
|
|
39
|
+
rules,
|
|
40
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Get current age based on the given birth date
|
|
@@ -9,11 +9,18 @@ const moment = require('moment-timezone');
|
|
|
9
9
|
* @returns {number} age
|
|
10
10
|
*/
|
|
11
11
|
export const getAge = (dateOfBirth, unit = 'years') => {
|
|
12
|
-
|
|
13
|
-
if (isNaN(age)) {
|
|
12
|
+
if (!dateOfBirth) {
|
|
14
13
|
throw new Error('Invalid date');
|
|
15
14
|
}
|
|
16
|
-
|
|
15
|
+
|
|
16
|
+
const dob = DateTime.fromJSDate(new Date(dateOfBirth));
|
|
17
|
+
if (!dob.isValid) {
|
|
18
|
+
throw new Error('Invalid date');
|
|
19
|
+
}
|
|
20
|
+
const age = dob.diffNow(unit);
|
|
21
|
+
const ageUnit = -age.as(unit);
|
|
22
|
+
// Note: luxon returns scientific notation, ie 6.976154236428209e-9
|
|
23
|
+
return Number(ageUnit.toString().split('.').shift());
|
|
17
24
|
};
|
|
18
25
|
/**
|
|
19
26
|
* Check if a user requires parent(guardian) consent
|
|
@@ -31,15 +38,15 @@ export const getAge = (dateOfBirth, unit = 'years') => {
|
|
|
31
38
|
* Then we should throw error if birthdate is not valid
|
|
32
39
|
*/
|
|
33
40
|
export const isUnderSixteen = (dateOfBirth) => {
|
|
34
|
-
if (!dateOfBirth || !
|
|
41
|
+
if (!dateOfBirth || !DateTime.fromJSDate(new Date(dateOfBirth)).isValid) {
|
|
35
42
|
return false;
|
|
36
43
|
}
|
|
37
44
|
const age = getAge(dateOfBirth);
|
|
38
45
|
return isNaN(age) ? false : age < 16;
|
|
39
46
|
};
|
|
40
47
|
|
|
41
|
-
export const isUnderAge = (dateOfBirth, limit, maxAcknowledgedAge) => {
|
|
42
|
-
if ((!dateOfBirth || !
|
|
48
|
+
export const isUnderAge = (dateOfBirth, limit, maxAcknowledgedAge: number | null = null) => {
|
|
49
|
+
if ((!dateOfBirth || !DateTime.fromJSDate(new Date(dateOfBirth)).isValid) && !maxAcknowledgedAge) {
|
|
43
50
|
return false;
|
|
44
51
|
}
|
|
45
52
|
|
|
@@ -52,15 +59,15 @@ export const isUnderAge = (dateOfBirth, limit, maxAcknowledgedAge) => {
|
|
|
52
59
|
|
|
53
60
|
export const datesByThemselves = (a, b) => {
|
|
54
61
|
if (!a.from) return 1;
|
|
55
|
-
return
|
|
62
|
+
return new Date(a.from).getTime() - new Date(b.from).getTime();
|
|
56
63
|
};
|
|
57
64
|
|
|
58
65
|
export const getShiftText = (from, to, timezone) => {
|
|
59
66
|
try {
|
|
60
67
|
if (!from || !to || !timezone) return '';
|
|
61
|
-
const startToTimezone =
|
|
62
|
-
const endToTimezone =
|
|
63
|
-
return `${
|
|
68
|
+
const startToTimezone = DateTime.fromJSDate(from).setZone(timezone);
|
|
69
|
+
const endToTimezone = DateTime.fromJSDate(to).setZone(timezone);
|
|
70
|
+
return `${startToTimezone.toFormat('cccc, DD, h:mma')}-${endToTimezone.toFormat('h:mma')}`;
|
|
64
71
|
}
|
|
65
72
|
catch (e) {
|
|
66
73
|
return '';
|