@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.
Files changed (125) hide show
  1. package/.semaphore/utils.yml +1 -1
  2. package/index.ts +7 -0
  3. package/lib/FeatureFlag.d.ts +12 -0
  4. package/lib/FeatureFlag.js +51 -0
  5. package/lib/constants/allowedHtmlTags.d.ts +7 -0
  6. package/lib/constants/allowedHtmlTags.js +8 -0
  7. package/lib/constants/avatarColours.d.ts +35 -0
  8. package/lib/constants/avatarColours.js +36 -0
  9. package/lib/constants/countries.d.ts +253 -0
  10. package/lib/constants/countries.js +254 -0
  11. package/lib/constants/currencies.d.ts +29 -0
  12. package/lib/constants/currencies.js +36 -0
  13. package/lib/constants/customFields.d.ts +11 -0
  14. package/lib/constants/customFields.js +12 -0
  15. package/lib/constants/distancesUnits.d.ts +11 -0
  16. package/lib/constants/distancesUnits.js +13 -0
  17. package/lib/constants/groups.d.ts +13 -0
  18. package/lib/constants/groups.js +85 -0
  19. package/lib/constants/insuranceStatuses.d.ts +15 -0
  20. package/lib/constants/insuranceStatuses.js +7 -0
  21. package/lib/constants/insuranceTypes.d.ts +35 -0
  22. package/lib/constants/insuranceTypes.js +36 -0
  23. package/lib/constants/languages.d.ts +2 -0
  24. package/lib/constants/languages.js +194 -0
  25. package/lib/constants/locales.d.ts +119 -0
  26. package/lib/constants/locales.js +191 -0
  27. package/lib/constants/notifications.d.ts +47 -0
  28. package/lib/constants/notifications.js +31 -0
  29. package/lib/constants/opportunities.d.ts +72 -0
  30. package/lib/constants/opportunities.js +82 -0
  31. package/lib/constants/qualificationTypes.d.ts +4 -0
  32. package/lib/constants/qualificationTypes.js +18 -0
  33. package/lib/constants/rules.d.ts +13 -0
  34. package/lib/constants/rules.js +21 -0
  35. package/lib/constants/subscriptions.d.ts +9 -0
  36. package/lib/constants/subscriptions.js +10 -0
  37. package/lib/constants/surveys.d.ts +16 -0
  38. package/lib/constants/surveys.js +17 -0
  39. package/lib/constants.d.ts +1 -0
  40. package/lib/constants.js +76 -0
  41. package/lib/date-time.d.ts +28 -0
  42. package/lib/date-time.js +79 -0
  43. package/lib/forms.d.ts +1 -0
  44. package/lib/forms.js +728 -0
  45. package/lib/locality.d.ts +5 -0
  46. package/lib/locality.js +15 -0
  47. package/lib/money.d.ts +7 -0
  48. package/lib/money.js +32 -0
  49. package/lib/opportunity.d.ts +1 -0
  50. package/lib/opportunity.js +11 -0
  51. package/lib/opportunityUser.d.ts +8 -0
  52. package/lib/opportunityUser.js +29 -0
  53. package/lib/password.d.ts +8 -0
  54. package/lib/password.js +43 -0
  55. package/lib/rrule/date.d.ts +4 -0
  56. package/lib/rrule/date.js +30 -0
  57. package/lib/rrule/index.d.ts +2 -0
  58. package/lib/rrule/index.js +18 -0
  59. package/lib/rrule/parsing.d.ts +6 -0
  60. package/lib/rrule/parsing.js +130 -0
  61. package/lib/rrule/parsing.test.d.ts +1 -0
  62. package/lib/rrule/parsing.test.js +11 -0
  63. package/lib/rrule.d.ts +49 -0
  64. package/lib/rrule.js +303 -0
  65. package/lib/src/FeatureFlag.d.ts +12 -0
  66. package/lib/src/FeatureFlag.js +51 -0
  67. package/lib/src/date-time.d.ts +28 -0
  68. package/lib/src/date-time.js +79 -0
  69. package/lib/src/forms.d.ts +1 -0
  70. package/lib/src/forms.js +728 -0
  71. package/lib/src/locality.d.ts +5 -0
  72. package/lib/src/locality.js +15 -0
  73. package/lib/src/money.d.ts +7 -0
  74. package/lib/src/money.js +32 -0
  75. package/lib/src/opportunity.d.ts +1 -0
  76. package/lib/src/opportunity.js +11 -0
  77. package/lib/src/opportunityUser.d.ts +8 -0
  78. package/lib/src/opportunityUser.js +29 -0
  79. package/lib/src/password.d.ts +8 -0
  80. package/lib/src/password.js +43 -0
  81. package/package.json +15 -29
  82. package/src/FeatureFlag.ts +26 -10
  83. package/src/constants/allowedHtmlTags.ts +6 -0
  84. package/src/constants/avatarColours.ts +34 -0
  85. package/src/constants/countries.ts +252 -0
  86. package/src/constants/currencies.ts +33 -0
  87. package/src/constants/customFields.ts +10 -0
  88. package/src/constants/distancesUnits.ts +11 -0
  89. package/src/constants/groups.ts +83 -0
  90. package/src/constants/insuranceStatuses.ts +5 -0
  91. package/src/constants/insuranceTypes.ts +34 -0
  92. package/src/constants/languages.ts +192 -0
  93. package/src/constants/locales.ts +189 -0
  94. package/src/constants/notifications.ts +30 -0
  95. package/src/constants/opportunities.ts +84 -0
  96. package/src/constants/qualificationTypes.ts +17 -0
  97. package/src/constants/rules.ts +22 -0
  98. package/src/constants/subscriptions.ts +8 -0
  99. package/src/constants/surveys.ts +15 -0
  100. package/src/constants.ts +40 -0
  101. package/src/{date-time.js → date-time.ts} +18 -11
  102. package/src/forms.ts +807 -0
  103. package/src/{opportunityUser.js → opportunityUser.ts} +5 -1
  104. package/src/{password.js → password.ts} +2 -0
  105. package/src/rrule/date.ts +25 -0
  106. package/src/rrule/index.ts +2 -0
  107. package/src/rrule/parsing.ts +136 -0
  108. package/src/rrule.ts +367 -0
  109. package/tests/{date-time.test.js → date-time.test.ts} +48 -46
  110. package/tests/featureFlag.test.ts +36 -39
  111. package/tests/forms.test-data.json +43 -0
  112. package/tests/forms.test-schema.json +144 -0
  113. package/tests/forms.test-uischema.json +117 -0
  114. package/tests/forms.test.ts +674 -0
  115. package/tests/{money.test.js → money.test.ts} +2 -3
  116. package/tests/{password.test.js → password.test.ts} +7 -6
  117. package/tests/rrule/parsing.test.ts +12 -0
  118. package/tests/rrule.test.ts +625 -0
  119. package/tsconfig.json +15 -12
  120. package/bundle.js +0 -270
  121. package/index.js +0 -25
  122. package/rollup.config.js +0 -25
  123. /package/src/{locality.js → locality.ts} +0 -0
  124. /package/src/{money.js → money.ts} +0 -0
  125. /package/src/{opportunity.js → opportunity.ts} +0 -0
@@ -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
- const moment = require('moment-timezone');
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
- const age = moment().diff(dateOfBirth, unit);
13
- if (isNaN(age)) {
12
+ if (!dateOfBirth) {
14
13
  throw new Error('Invalid date');
15
14
  }
16
- return age;
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 || !moment(dateOfBirth).isValid()) {
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 || !moment(dateOfBirth).isValid()) && !maxAcknowledgedAge) {
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 moment(a.from) - moment(b.from);
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 = moment(from).tz(timezone);
62
- const endToTimezone = moment(to).tz(timezone);
63
- return `${moment(startToTimezone).format('dddd, DD MMMM YYYY, h:mma')}-${moment(endToTimezone).format('h:mma')}`;
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 '';