@becollective/utils 2.0.13 → 2.0.14

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.
@@ -1,5 +0,0 @@
1
- /**
2
- *
3
- * @param {Array} locationList
4
- */
5
- export declare const getHomeLocalityFromLocationList: (locationList: any) => any;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHomeLocalityFromLocationList = void 0;
4
- /**
5
- *
6
- * @param {Array} locationList
7
- */
8
- const getHomeLocalityFromLocationList = (locationList) => {
9
- const homeLocation = Array.isArray(locationList) && locationList.find((location) => location.name === 'Home');
10
- if (homeLocation && homeLocation.locality && homeLocation.locality.long) {
11
- return homeLocation.locality.long;
12
- }
13
- return null;
14
- };
15
- exports.getHomeLocalityFromLocationList = getHomeLocalityFromLocationList;
@@ -1,7 +0,0 @@
1
- export declare const getCurrencyFromCurrencyCode: (currencyCode: any) => any;
2
- export declare const makeMoneyString: ({ amount: inputAmount, currencyCode, rounded, showCurrencyCode }: {
3
- amount: any;
4
- currencyCode: any;
5
- rounded?: boolean | undefined;
6
- showCurrencyCode?: boolean | undefined;
7
- }) => string;
package/lib/src/money.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeMoneyString = exports.getCurrencyFromCurrencyCode = void 0;
4
- const { currencies } = require('@becollective/constants');
5
- // We should probably throw and error on bad input instead of falling back to a default.
6
- // We're making an assumption that whoever is calling this function can safely work
7
- // with AUD. But this assumption removes a lot of error handling elsewhere.
8
- const getCurrencyFromCurrencyCode = (currencyCode) => {
9
- if (typeof currencyCode !== 'string' || !currencies[currencyCode]) {
10
- console.error(new Error(`Invalid currencyCode: ${currencyCode}. Falling back to 'AUD'.`));
11
- return currencies.AUD;
12
- }
13
- return currencies[currencyCode];
14
- };
15
- exports.getCurrencyFromCurrencyCode = getCurrencyFromCurrencyCode;
16
- const makeMoneyString = ({ amount: inputAmount, currencyCode, rounded = false, showCurrencyCode = false }) => {
17
- let amount = Number(inputAmount);
18
- if (isNaN(amount)) {
19
- console.error(new Error(`Invalid amount: ${inputAmount}. Falling back to 0.`));
20
- amount = 0;
21
- }
22
- const currency = (0, exports.getCurrencyFromCurrencyCode)(currencyCode);
23
- const { minorUnit, symbol } = currency;
24
- const decimalPlaces = rounded ? 0 : minorUnit;
25
- const localeAmount = amount.toLocaleString(undefined, {
26
- minimumFractionDigits: decimalPlaces,
27
- maximumFractionDigits: decimalPlaces,
28
- });
29
- const currencyCodeString = showCurrencyCode ? ` ${currency.code}` : '';
30
- return `${symbol}${localeAmount}${currencyCodeString}`;
31
- };
32
- exports.makeMoneyString = makeMoneyString;
@@ -1 +0,0 @@
1
- export declare const readableOpportunityType: (type: any) => string | null;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readableOpportunityType = void 0;
4
- const { opportunities } = require('@becollective/constants');
5
- const { typesMapV2: opportunityTypes } = opportunities;
6
- const TYPE_MAP = {
7
- [opportunityTypes.shift]: 'Shifts',
8
- [opportunityTypes.flexible]: 'Flexible',
9
- };
10
- const readableOpportunityType = (type) => TYPE_MAP[type] || null;
11
- exports.readableOpportunityType = readableOpportunityType;
@@ -1,8 +0,0 @@
1
- /**
2
- *
3
- * @param {*} opportunityUser
4
- * @param {*} opportunity
5
- */
6
- export declare const getTimeInfo: (opportunityUser: any, opportunity?: null) => {
7
- [k: string]: unknown;
8
- };
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTimeInfo = void 0;
4
- const pick = (obj, keysToPick = []) => {
5
- return Object.fromEntries(Object.entries(obj).filter(([key]) => keysToPick.includes(key)));
6
- };
7
- /**
8
- *
9
- * @param {*} opportunityUser
10
- * @param {*} opportunity
11
- */
12
- const getTimeInfo = (opportunityUser, opportunity = null) => {
13
- const opp = opportunity || opportunityUser.opportunity;
14
- const isEoi = (opportunityUser && opportunityUser.eoi) || (opp && opp.eoi);
15
- const record = isEoi ? opportunityUser : opp;
16
- const fields = pick(record, [
17
- 'startDate',
18
- 'endDate',
19
- 'type',
20
- 'dates',
21
- 'recurrenceRule',
22
- 'timezone',
23
- 'location',
24
- 'locationOther',
25
- 'locationVirtual',
26
- ]);
27
- return fields;
28
- };
29
- exports.getTimeInfo = getTimeInfo;
@@ -1,8 +0,0 @@
1
- export declare const password: {
2
- hasUppercase: (input: any) => boolean;
3
- hasLowerCase: (input: any) => boolean;
4
- hasNumeral: (input: any) => boolean;
5
- validate: (input: any) => boolean;
6
- isValid: (input: any) => boolean;
7
- };
8
- export default password;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.password = void 0;
4
- exports.password = {
5
- hasUppercase: (input) => {
6
- return !!input.match(/[A-Z]/);
7
- },
8
- hasLowerCase: (input) => {
9
- return !!input.match(/[a-z]/);
10
- },
11
- hasNumeral: (input) => {
12
- return !!input.match(/[0-9]/);
13
- },
14
- validate: (input) => {
15
- if (typeof input !== 'string') {
16
- throw new Error('not-string');
17
- }
18
- else if (input.length < 12) {
19
- throw new Error('invalid-length');
20
- }
21
- let rules = 0;
22
- if (exports.password.hasUppercase(input))
23
- rules++;
24
- if (exports.password.hasLowerCase(input))
25
- rules++;
26
- if (exports.password.hasNumeral(input))
27
- rules++;
28
- if (rules < 3) {
29
- throw new Error('invalid-minimum-rules');
30
- }
31
- return true;
32
- },
33
- isValid: (input) => {
34
- try {
35
- exports.password.validate(input);
36
- return true;
37
- }
38
- catch (e) {
39
- return false;
40
- }
41
- },
42
- };
43
- exports.default = exports.password;