@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,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 {};