@8ms/helpers 1.1.73 → 1.1.75
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/api/response.d.ts +8 -0
- package/api/response.js +12 -1
- package/api/states.d.ts +9 -0
- package/api/states.js +10 -1
- package/api/unexpectedError.d.ts +2 -0
- package/api/unexpectedError.js +4 -1
- package/array/contains.d.ts +8 -0
- package/array/contains.js +6 -2
- package/array/getArray.d.ts +7 -0
- package/array/getArray.js +10 -2
- package/atInternet/request.d.ts +30 -0
- package/atInternet/request.js +2 -1
- package/aws/athenaExpress/initClient.d.ts +12 -0
- package/aws/athenaExpress/initClient.js +27 -3
- package/aws/athenaExpress/query.d.ts +8 -0
- package/aws/athenaExpress/query.js +9 -2
- package/aws/getConfig.d.ts +13 -0
- package/aws/getConfig.js +26 -2
- package/aws/glue/initClient.d.ts +10 -0
- package/aws/glue/initClient.js +17 -2
- package/aws/glue/invoke.d.ts +9 -0
- package/aws/glue/invoke.js +19 -2
- package/aws/isResponse200.d.ts +7 -0
- package/aws/isResponse200.js +21 -2
- package/aws/lambda/getHandlerPath.d.ts +5 -0
- package/aws/lambda/getHandlerPath.js +7 -1
- package/aws/lambda/initClient.d.ts +10 -0
- package/aws/lambda/initClient.js +17 -2
- package/aws/lambda/invoke.d.ts +12 -0
- package/aws/lambda/invoke.js +39 -2
- package/aws/s3/copyFile.d.ts +13 -0
- package/aws/s3/copyFile.js +13 -2
- package/aws/s3/deleteFile.d.ts +9 -0
- package/aws/s3/deleteFile.js +12 -2
- package/aws/s3/deleteFiles.d.ts +9 -0
- package/aws/s3/deleteFiles.js +16 -2
- package/aws/s3/deleteFolder.d.ts +9 -0
- package/aws/s3/deleteFolder.js +35 -2
- package/aws/s3/getGlueJson.d.ts +5 -0
- package/aws/s3/getGlueJson.js +15 -2
- package/aws/s3/getPresignedPost.d.ts +20 -0
- package/aws/s3/getPresignedPost.js +16 -3
- package/aws/s3/getSignedUrl.d.ts +12 -0
- package/aws/s3/getSignedUrl.js +15 -2
- package/aws/s3/initClient.d.ts +10 -0
- package/aws/s3/initClient.js +17 -2
- package/aws/s3/isFileExists.d.ts +9 -0
- package/aws/s3/isFileExists.js +26 -2
- package/aws/s3/listFiles.d.ts +9 -0
- package/aws/s3/listFiles.js +32 -2
- package/aws/s3/listFolders.d.ts +9 -0
- package/aws/s3/listFolders.js +31 -4
- package/aws/s3/moveFile.d.ts +10 -0
- package/aws/s3/moveFile.js +20 -2
- package/aws/s3/readBuffer.d.ts +13 -0
- package/aws/s3/readBuffer.js +51 -2
- package/aws/s3/readFile.d.ts +30 -0
- package/aws/s3/readFile.js +69 -2
- package/aws/s3/writeFile.d.ts +10 -0
- package/aws/s3/writeFile.js +15 -2
- package/aws/s3/writePresignedPost.d.ts +14 -0
- package/aws/s3/writePresignedPost.js +30 -2
- package/aws/s3cache/cache.d.ts +7 -0
- package/aws/s3cache/cache.js +2 -1
- package/aws/s3cache/getCache.d.ts +12 -0
- package/aws/s3cache/getCache.js +35 -2
- package/aws/s3cache/getKey.d.ts +10 -0
- package/aws/s3cache/getKey.js +16 -2
- package/aws/s3cache/saveCache.d.ts +10 -0
- package/aws/s3cache/saveCache.js +12 -2
- package/aws/s3cache/updateCache.d.ts +10 -0
- package/aws/s3cache/updateCache.js +23 -2
- package/aws/ses/SimpleEmail.d.ts +51 -0
- package/aws/ses/SimpleEmail.js +115 -2
- package/aws/ses/initClient.d.ts +10 -0
- package/aws/ses/initClient.js +17 -2
- package/aws/ssm/getParameter.d.ts +10 -0
- package/aws/ssm/getParameter.js +39 -2
- package/aws/ssm/initClient.d.ts +10 -0
- package/aws/ssm/initClient.js +17 -2
- package/axios/get.d.ts +8 -0
- package/axios/get.js +44 -1
- package/axios/post.d.ts +12 -0
- package/axios/post.js +46 -2
- package/boolean/getBoolean.d.ts +7 -0
- package/boolean/getBoolean.js +15 -2
- package/class/BaseClass.d.ts +31 -0
- package/class/BaseClass.js +50 -9
- package/crud/actions.d.ts +8 -0
- package/crud/actions.js +10 -1
- package/crypto/getDecrypt.d.ts +10 -0
- package/crypto/getDecrypt.js +11 -2
- package/crypto/getEncrypt.d.ts +10 -0
- package/crypto/getEncrypt.js +11 -2
- package/crypto/getRandom.d.ts +8 -0
- package/crypto/getRandom.js +10 -2
- package/crypto/getSha256.d.ts +8 -0
- package/crypto/getSha256.js +15 -2
- package/date/date.d.ts +4 -0
- package/date/date.js +2 -1
- package/date/duration.d.ts +5 -0
- package/date/duration.js +2 -1
- package/date/durationComparisons.d.ts +5 -0
- package/date/durationComparisons.js +7 -1
- package/date/durations.d.ts +8 -0
- package/date/durations.js +10 -1
- package/date/financialYear.d.ts +4 -0
- package/date/financialYear.js +2 -1
- package/date/financialYearWeek.d.ts +6 -0
- package/date/financialYearWeek.js +2 -1
- package/date/format.d.ts +13 -0
- package/date/format.js +18 -2
- package/date/getDate.d.ts +12 -0
- package/date/getDate.js +96 -9
- package/date/getDatesBetween.d.ts +10 -0
- package/date/getDatesBetween.js +25 -3
- package/date/getDurationHours.d.ts +8 -0
- package/date/getDurationHours.js +25 -2
- package/date/getDurationMinutes.d.ts +8 -0
- package/date/getDurationMinutes.js +24 -2
- package/date/getFinancialYear.d.ts +9 -0
- package/date/getFinancialYear.js +48 -8
- package/date/getFinancialYearToDate.d.ts +7 -0
- package/date/getFinancialYearToDate.js +18 -2
- package/date/getFinancialYearToYesterday.d.ts +7 -0
- package/date/getFinancialYearToYesterday.js +18 -2
- package/date/getFinancialYearWeeks.d.ts +9 -0
- package/date/getFinancialYearWeeks.js +29 -2
- package/date/getLastWeek.d.ts +10 -0
- package/date/getLastWeek.js +28 -2
- package/date/getMax.d.ts +12 -0
- package/date/getMax.js +15 -2
- package/date/getMidnight.d.ts +10 -0
- package/date/getMidnight.js +12 -2
- package/date/getMin.d.ts +12 -0
- package/date/getMin.js +15 -2
- package/date/getMonday.d.ts +14 -0
- package/date/getMonday.js +32 -5
- package/date/getNumber.d.ts +11 -0
- package/date/getNumber.js +14 -2
- package/date/getPredefinedTimeframe.d.ts +9 -0
- package/date/getPredefinedTimeframe.js +23 -2
- package/date/getSunday.d.ts +14 -0
- package/date/getSunday.js +32 -5
- package/date/getThisWeek.d.ts +10 -0
- package/date/getThisWeek.js +28 -2
- package/date/getTimeZoned.d.ts +13 -0
- package/date/getTimeZoned.js +36 -5
- package/date/getToday.d.ts +9 -0
- package/date/getToday.js +39 -2
- package/date/getTwoWeeksAgo.d.ts +10 -0
- package/date/getTwoWeeksAgo.js +28 -2
- package/date/getWeeksAgo.d.ts +12 -0
- package/date/getWeeksAgo.js +16 -2
- package/date/getYesterday.d.ts +9 -0
- package/date/getYesterday.js +40 -2
- package/date/isDateValid.d.ts +7 -0
- package/date/isDateValid.js +22 -2
- package/date/isLastWeek.d.ts +6 -0
- package/date/isLastWeek.js +13 -2
- package/date/isThisWeek.d.ts +6 -0
- package/date/isThisWeek.js +13 -2
- package/date/parseExcelDate.d.ts +8 -0
- package/date/parseExcelDate.js +17 -2
- package/date/predefinedTimeframes.d.ts +7 -0
- package/date/predefinedTimeframes.js +9 -1
- package/date/timeframe.d.ts +8 -0
- package/date/timeframe.js +2 -1
- package/date/timeframes.d.ts +4 -0
- package/date/timeframes.js +7 -1
- package/deepCrawl/buildRequest.d.ts +15 -0
- package/deepCrawl/buildRequest.js +83 -4
- package/deepCrawl/filter.d.ts +5 -0
- package/deepCrawl/filter.js +2 -1
- package/deepCrawl/getData.d.ts +5 -0
- package/deepCrawl/getData.js +29 -1
- package/deepCrawl/initClient.d.ts +13 -0
- package/deepCrawl/initClient.js +31 -2
- package/deepCrawl/operands.d.ts +11 -0
- package/deepCrawl/operands.js +13 -1
- package/deepCrawl/orders.d.ts +9 -0
- package/deepCrawl/orders.js +7 -1
- package/deepCrawl/reports.d.ts +11 -0
- package/deepCrawl/reports.js +13 -1
- package/environment/environments.d.ts +7 -0
- package/environment/environments.js +8 -1
- package/environment/getEnvironment.d.ts +6 -0
- package/environment/getEnvironment.js +42 -2
- package/environment/isAws.d.ts +5 -0
- package/environment/isAws.js +10 -2
- package/environment/isDevelopment.d.ts +2 -0
- package/environment/isDevelopment.js +9 -1
- package/environment/isLocalhost.d.ts +5 -0
- package/environment/isLocalhost.js +21 -2
- package/environment/isProduction.d.ts +2 -0
- package/environment/isProduction.js +9 -1
- package/environment/isStaging.d.ts +2 -0
- package/environment/isStaging.js +9 -1
- package/environment/isVercel.d.ts +5 -0
- package/environment/isVercel.js +6 -2
- package/environment/platforms.d.ts +6 -0
- package/environment/platforms.js +7 -1
- package/eskimi/ageGroups.d.ts +5 -0
- package/eskimi/ageGroups.js +41 -1
- package/eskimi/campaign.d.ts +19 -0
- package/eskimi/campaign.js +2 -1
- package/eskimi/devices.d.ts +5 -0
- package/eskimi/devices.js +13 -1
- package/eskimi/endpoints.d.ts +16 -0
- package/eskimi/endpoints.js +17 -2
- package/eskimi/genders.d.ts +5 -0
- package/eskimi/genders.js +13 -1
- package/eskimi/getAccessToken.d.ts +9 -0
- package/eskimi/getAccessToken.js +22 -2
- package/eskimi/getAgeGroup.d.ts +7 -0
- package/eskimi/getAgeGroup.js +16 -2
- package/eskimi/getCampaignIds.d.ts +7 -0
- package/eskimi/getCampaignIds.js +11 -2
- package/eskimi/getDevice.d.ts +7 -0
- package/eskimi/getDevice.js +16 -2
- package/eskimi/getGender.d.ts +7 -0
- package/eskimi/getGender.js +16 -2
- package/eskimi/request.d.ts +8 -0
- package/eskimi/request.js +23 -2
- package/google/bigQuery/initClient.d.ts +11 -0
- package/google/bigQuery/initClient.js +20 -2
- package/google/bigQuery/query.d.ts +9 -0
- package/google/bigQuery/query.js +9 -2
- package/google/getConfig.d.ts +20 -0
- package/google/getConfig.js +21 -3
- package/google/sheets/getAssociatedData.d.ts +16 -0
- package/google/sheets/getAssociatedData.js +52 -8
- package/google/sheets/getBatchData.d.ts +18 -0
- package/google/sheets/getBatchData.js +19 -1
- package/google/sheets/initClient.d.ts +11 -0
- package/google/sheets/initClient.js +22 -2
- package/google/sheets/isCellNa.d.ts +7 -0
- package/google/sheets/isCellNa.js +6 -2
- package/google/storage/initClient.d.ts +12 -0
- package/google/storage/initClient.js +20 -2
- package/google/storage/writeFile.d.ts +12 -0
- package/google/storage/writeFile.js +30 -2
- package/googleAds/getCustomer.d.ts +8 -0
- package/googleAds/getCustomer.js +13 -2
- package/googleAds/initClient.d.ts +16 -0
- package/googleAds/initClient.js +23 -2
- package/initClients.d.ts +40 -0
- package/initClients.js +106 -5
- package/json/isJson.d.ts +8 -0
- package/json/isJson.js +18 -2
- package/littleWarden/getUrlStatus.d.ts +9 -0
- package/littleWarden/getUrlStatus.js +20 -2
- package/littleWarden/isAllGood.d.ts +7 -0
- package/littleWarden/isAllGood.js +17 -2
- package/littleWarden/isDanger.d.ts +7 -0
- package/littleWarden/isDanger.js +17 -2
- package/littleWarden/isWarning.d.ts +7 -0
- package/littleWarden/isWarning.js +17 -2
- package/littleWarden/states.d.ts +7 -0
- package/littleWarden/states.js +8 -1
- package/myTarget/getAccessToken.d.ts +9 -0
- package/myTarget/getAccessToken.js +22 -2
- package/myTarget/request.d.ts +8 -0
- package/myTarget/request.js +23 -2
- package/nextAuth/isSessionReady.d.ts +4 -0
- package/nextAuth/isSessionReady.js +12 -1
- package/nextAuth/states.d.ts +7 -0
- package/nextAuth/states.js +8 -2
- package/nextJs/getIp.d.ts +7 -0
- package/nextJs/getIp.js +12 -2
- package/nextJs/getUserAgent.d.ts +7 -0
- package/nextJs/getUserAgent.js +6 -2
- package/number/getDivide.d.ts +9 -0
- package/number/getDivide.js +17 -2
- package/number/getNumber.d.ts +8 -0
- package/number/getNumber.js +50 -7
- package/number/getPercent.d.ts +9 -0
- package/number/getPercent.js +17 -2
- package/number/getPercentIncrease.d.ts +9 -0
- package/number/getPercentIncrease.js +17 -2
- package/number/getRounded.d.ts +9 -0
- package/number/getRounded.js +21 -2
- package/package.json +44 -47
- package/prisma/initClient.d.ts +4 -0
- package/prisma/initClient.js +33 -3
- package/snapchat/getAccessToken.d.ts +9 -0
- package/snapchat/getAccessToken.js +36 -2
- package/sorting/byNumberAscending.d.ts +8 -0
- package/sorting/byNumberAscending.js +16 -2
- package/sorting/byNumberDescending.d.ts +8 -0
- package/sorting/byNumberDescending.js +16 -2
- package/sorting/byStringAscending.d.ts +8 -0
- package/sorting/byStringAscending.js +20 -2
- package/sorting/byStringDescending.d.ts +8 -0
- package/sorting/byStringDescending.js +20 -2
- package/string/formatCapitalise.d.ts +9 -0
- package/string/formatCapitalise.js +14 -2
- package/string/getCleanFolder.d.ts +7 -0
- package/string/getCleanFolder.js +11 -2
- package/string/getString.d.ts +7 -0
- package/string/getString.js +35 -2
- package/string/getStringFromStream.d.ts +8 -0
- package/string/getStringFromStream.js +14 -2
- package/string/toProperCase.d.ts +7 -0
- package/string/toProperCase.js +17 -2
- package/swr/isAllData.d.ts +7 -0
- package/swr/isAllData.js +18 -2
- package/swr/isAnyError.d.ts +7 -0
- package/swr/isAnyError.js +18 -2
- package/swr/isAnyLoading.d.ts +7 -0
- package/swr/isAnyLoading.js +20 -2
- package/swr/isData.d.ts +7 -0
- package/swr/isData.js +6 -2
- package/swr/isError.d.ts +7 -0
- package/swr/isError.js +6 -2
- package/swr/isLoading.d.ts +7 -0
- package/swr/isLoading.js +11 -2
- package/upTimeRobot/getMonitors.d.ts +1 -0
- package/upTimeRobot/getMonitors.js +31 -2
- package/upTimeRobot/logTypes.d.ts +7 -0
- package/upTimeRobot/logTypes.js +9 -1
- package/upTimeRobot/monitorStatuses.d.ts +8 -0
- package/upTimeRobot/monitorStatuses.js +10 -1
- package/upTimeRobot/monitorSubTypes.d.ts +10 -0
- package/upTimeRobot/monitorSubTypes.js +12 -1
- package/upTimeRobot/monitorTypes.d.ts +8 -0
- package/upTimeRobot/monitorTypes.js +10 -1
- package/upTimeRobot/requestStatuses.d.ts +5 -0
- package/upTimeRobot/requestStatuses.js +7 -1
- package/url/buildParameters.d.ts +8 -0
- package/url/buildParameters.js +21 -2
- package/url/buildRelative.d.ts +8 -0
- package/url/buildRelative.js +12 -2
- package/url/buildUrl.d.ts +10 -0
- package/url/buildUrl.js +28 -2
- package/url/isAbsolute.d.ts +7 -0
- package/url/isAbsolute.js +14 -2
- package/url/isRelative.d.ts +7 -0
- package/url/isRelative.js +7 -2
- package/url/url.d.ts +6 -0
- package/url/url.js +2 -1
- package/util/defaultTo.d.ts +10 -0
- package/util/defaultTo.js +34 -2
- package/util/isUndefined.d.ts +9 -0
- package/util/isUndefined.js +18 -2
- package/util/sleep.d.ts +4 -0
- package/util/sleep.js +6 -1
- package/webWorker/states.d.ts +7 -0
- package/webWorker/states.js +8 -1
- package/xml/getXml.d.ts +4 -0
- package/xml/getXml.js +14 -1
- package/globals.d.js +0 -1
package/number/getNumber.js
CHANGED
|
@@ -1,8 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const isJson_1 = __importDefault(require("../json/isJson"));
|
|
7
|
+
/**
|
|
2
8
|
* Take an input and return a number.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
+
*/
|
|
10
|
+
const getNumber = ({ defaultValue = 0, input = '' }) => {
|
|
11
|
+
const actualDefaultValue = defaultValue || 0;
|
|
12
|
+
let response = input;
|
|
13
|
+
// JSON - Decode the value
|
|
14
|
+
if ((0, isJson_1.default)({ input })) {
|
|
15
|
+
// Only parse this if it's a string
|
|
16
|
+
if ('string' === typeof input) {
|
|
17
|
+
response = JSON.parse(input);
|
|
18
|
+
}
|
|
19
|
+
// Already decoded
|
|
20
|
+
else {
|
|
21
|
+
response = input;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Already a number
|
|
25
|
+
if ('number' === typeof response) {
|
|
26
|
+
response = response;
|
|
27
|
+
}
|
|
28
|
+
// String input
|
|
29
|
+
else if ('string' === typeof response) {
|
|
30
|
+
// Attempt to convert to number
|
|
31
|
+
response = Number(response);
|
|
32
|
+
// Not a number, try extracting the number value
|
|
33
|
+
if (isNaN(response)) {
|
|
34
|
+
const match = RegExp(/^\D*([0-9\.]*)\D*$/, 'g')
|
|
35
|
+
.exec(input);
|
|
36
|
+
if (match.length) {
|
|
37
|
+
response = Number(match[1]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Attempt to convert to a number
|
|
42
|
+
else {
|
|
43
|
+
response = Number(response);
|
|
44
|
+
}
|
|
45
|
+
// Trouble converting the number, use default value
|
|
46
|
+
if (isNaN(response)) {
|
|
47
|
+
response = actualDefaultValue;
|
|
48
|
+
}
|
|
49
|
+
return response;
|
|
50
|
+
};
|
|
51
|
+
exports.default = getNumber;
|
package/number/getPercent.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getNumber_1 = __importDefault(require("./getNumber"));
|
|
7
|
+
/**
|
|
2
8
|
* Get the percentage of two numbers.
|
|
3
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const getPercent = ({ defaultValue = 0, divisor, value }) => {
|
|
11
|
+
const cleanValue = (0, getNumber_1.default)({ input: value });
|
|
12
|
+
const cleanDivisor = (0, getNumber_1.default)({ input: divisor });
|
|
13
|
+
if (0 === cleanDivisor) {
|
|
14
|
+
return defaultValue;
|
|
15
|
+
}
|
|
16
|
+
return cleanValue / cleanDivisor;
|
|
17
|
+
};
|
|
18
|
+
exports.default = getPercent;
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getNumber_1 = __importDefault(require("./getNumber"));
|
|
7
|
+
/**
|
|
2
8
|
* Formula to work out the percentage increase/decrease.
|
|
3
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const getPercentageIncrease = ({ comparison, current, defaultValue }) => {
|
|
11
|
+
const currentValue = (0, getNumber_1.default)({ input: current });
|
|
12
|
+
const comparisonValue = (0, getNumber_1.default)({ input: comparison });
|
|
13
|
+
if (0 === currentValue) {
|
|
14
|
+
return defaultValue;
|
|
15
|
+
}
|
|
16
|
+
return (currentValue - comparisonValue) / currentValue * 100;
|
|
17
|
+
};
|
|
18
|
+
exports.default = getPercentageIncrease;
|
package/number/getRounded.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getNumber_1 = __importDefault(require("./getNumber"));
|
|
7
|
+
/**
|
|
2
8
|
* Round a number using the Numbro library.
|
|
3
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const getRounded = ({ decimalPlaces, input }) => {
|
|
11
|
+
const numbro = require('numbro');
|
|
12
|
+
const inputNumber = (0, getNumber_1.default)({ defaultValue: 0, input });
|
|
13
|
+
const stringNumber = numbro(inputNumber)
|
|
14
|
+
.format({
|
|
15
|
+
average: false,
|
|
16
|
+
mantissa: decimalPlaces,
|
|
17
|
+
thousandSeparated: false,
|
|
18
|
+
trimMantissa: true,
|
|
19
|
+
});
|
|
20
|
+
return Number(stringNumber);
|
|
21
|
+
};
|
|
22
|
+
exports.default = getRounded;
|
package/package.json
CHANGED
|
@@ -1,49 +1,46 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"tslib": "2.4.0",
|
|
47
|
-
"typescript": "4.8.2"
|
|
48
|
-
}
|
|
2
|
+
"name": "@8ms/helpers",
|
|
3
|
+
"license": "UNLICENSED",
|
|
4
|
+
"version": "1.1.75",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
|
|
8
|
+
},
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"types": "index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"jest": "jest --watch"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"axios": "0.27.2",
|
|
17
|
+
"crypto-js": "4.1.1",
|
|
18
|
+
"date-fns": "2.29.2",
|
|
19
|
+
"date-fns-tz": "1.3.7",
|
|
20
|
+
"lodash": "4.17.21"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@aws-sdk/client-s3": "3.163.0",
|
|
24
|
+
"@aws-sdk/client-ses": "3.163.0",
|
|
25
|
+
"@aws-sdk/client-ssm": "3.163.0",
|
|
26
|
+
"@aws-sdk/s3-request-presigner": "3.163.0",
|
|
27
|
+
"@babel/preset-env": "7.18.10",
|
|
28
|
+
"@babel/preset-flow": "7.18.6",
|
|
29
|
+
"@babel/preset-typescript": "7.18.6",
|
|
30
|
+
"@google-cloud/bigquery": "6.0.2",
|
|
31
|
+
"@google-cloud/storage": "6.4.2",
|
|
32
|
+
"@prisma/client": "4.3.1",
|
|
33
|
+
"@types/jest": "29.0.0",
|
|
34
|
+
"@types/lodash": "4.14.184",
|
|
35
|
+
"@types/node": "18.7.14",
|
|
36
|
+
"babel-jest": "29.0.2",
|
|
37
|
+
"jest": "29.0.2",
|
|
38
|
+
"node-fetch": "3.2.10",
|
|
39
|
+
"numbro": "2.3.6",
|
|
40
|
+
"prisma-query-log": "3.2.0",
|
|
41
|
+
"timezone-mock": "1.3.4",
|
|
42
|
+
"ts-node": "10.9.1",
|
|
43
|
+
"tslib": "2.4.0",
|
|
44
|
+
"typescript": "4.8.2"
|
|
45
|
+
}
|
|
49
46
|
}
|
package/prisma/initClient.js
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Prevent too many connections
|
|
5
|
+
* https://github.com/prisma/prisma/issues/1983#issuecomment-620621213
|
|
6
|
+
* https://next-auth.js.org/schemas/adapters
|
|
7
|
+
* Library: @prisma/client, prisma-query-log
|
|
8
|
+
*/
|
|
9
|
+
global.prisma = null;
|
|
10
|
+
const initClient = ({ debug } = { debug: false }) => {
|
|
11
|
+
if (!global.prisma) {
|
|
12
|
+
const { PrismaClient } = require('@prisma/client');
|
|
13
|
+
// Show the full query if debugging
|
|
14
|
+
if (debug) {
|
|
15
|
+
global.prisma = new PrismaClient({
|
|
16
|
+
log: [
|
|
17
|
+
{
|
|
18
|
+
emit: "event",
|
|
19
|
+
level: "query",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
const { createPrismaQueryEventHandler } = require('prisma-query-log');
|
|
24
|
+
const log = createPrismaQueryEventHandler();
|
|
25
|
+
global.prisma.$on('query', log);
|
|
26
|
+
}
|
|
27
|
+
// Standard prisma
|
|
28
|
+
else {
|
|
29
|
+
global.prisma = new PrismaClient();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.default = initClient;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare type GetAccessToken = {
|
|
2
|
+
force?: boolean;
|
|
3
|
+
parameterName: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Renew the access token as it expires every 3 hours.
|
|
7
|
+
*/
|
|
8
|
+
declare const getAccessToken: ({ force, parameterName }: GetAccessToken) => Promise<void>;
|
|
9
|
+
export default getAccessToken;
|
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getParameter_1 = __importDefault(require("../aws/ssm/getParameter"));
|
|
7
|
+
const post_1 = __importDefault(require("../axios/post"));
|
|
8
|
+
global.snapchatAccessToken = null;
|
|
9
|
+
/**
|
|
2
10
|
* Renew the access token as it expires every 3 hours.
|
|
3
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
const getAccessToken = async ({ force, parameterName }) => {
|
|
13
|
+
if (!global.snapchatAccessToken || force) {
|
|
14
|
+
// Get the credentials from SSM
|
|
15
|
+
const parameter = await (0, getParameter_1.default)({
|
|
16
|
+
name: parameterName,
|
|
17
|
+
withDecryption: true,
|
|
18
|
+
isJson: true,
|
|
19
|
+
});
|
|
20
|
+
// Build the token request for Snapchat
|
|
21
|
+
let url = `https://accounts.snapchat.com/login/oauth2/access_token`;
|
|
22
|
+
url += `?client_id=${parameter.clientId}`;
|
|
23
|
+
url += `&client_secret=${parameter.clientSecret}`;
|
|
24
|
+
url += `&grant_type=refresh_token`;
|
|
25
|
+
url += `&refresh_token=${parameter.refreshToken}`;
|
|
26
|
+
await (0, post_1.default)({
|
|
27
|
+
onSuccess: apiResponse => {
|
|
28
|
+
if (undefined !== apiResponse['data']['access_token']) {
|
|
29
|
+
global.snapchatAccessToken = apiResponse['data']['access_token'];
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
url: url,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return global.snapchatAccessToken;
|
|
36
|
+
};
|
|
37
|
+
exports.default = getAccessToken;
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
2
4
|
* Take two values, ensure they are numbers and return the sorting value.
|
|
3
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
const byNumberAscending = ({ valueA, valueB }) => {
|
|
7
|
+
let valueAClean = Number(valueA);
|
|
8
|
+
let valueBClean = Number(valueB);
|
|
9
|
+
if (valueAClean > valueBClean) {
|
|
10
|
+
return 1;
|
|
11
|
+
}
|
|
12
|
+
if (valueBClean > valueAClean) {
|
|
13
|
+
return -1;
|
|
14
|
+
}
|
|
15
|
+
return 0;
|
|
16
|
+
};
|
|
17
|
+
exports.default = byNumberAscending;
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
2
4
|
* Take two values, ensure they are numbers and return the sorting value.
|
|
3
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
const byNumberDescending = ({ valueA, valueB }) => {
|
|
7
|
+
let valueAClean = Number(valueA);
|
|
8
|
+
let valueBClean = Number(valueB);
|
|
9
|
+
if (valueAClean > valueBClean) {
|
|
10
|
+
return -1;
|
|
11
|
+
}
|
|
12
|
+
if (valueBClean > valueAClean) {
|
|
13
|
+
return 1;
|
|
14
|
+
}
|
|
15
|
+
return 0;
|
|
16
|
+
};
|
|
17
|
+
exports.default = byNumberDescending;
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
2
4
|
* Take two values, clean the strings and return the sorting value.
|
|
3
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
const byStringAscending = ({ valueA, valueB }) => {
|
|
7
|
+
let valueAClean = valueA
|
|
8
|
+
.trim()
|
|
9
|
+
.toLowerCase();
|
|
10
|
+
let valueBClean = valueB
|
|
11
|
+
.trim()
|
|
12
|
+
.toLowerCase();
|
|
13
|
+
if (valueAClean > valueBClean) {
|
|
14
|
+
return 1;
|
|
15
|
+
}
|
|
16
|
+
if (valueBClean > valueAClean) {
|
|
17
|
+
return -1;
|
|
18
|
+
}
|
|
19
|
+
return 0;
|
|
20
|
+
};
|
|
21
|
+
exports.default = byStringAscending;
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
2
4
|
* Take two values, clean the strings and return the sorting value.
|
|
3
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
const byStringDescending = ({ valueA, valueB }) => {
|
|
7
|
+
let valueAClean = valueA
|
|
8
|
+
.trim()
|
|
9
|
+
.toLowerCase();
|
|
10
|
+
let valueBClean = valueB
|
|
11
|
+
.trim()
|
|
12
|
+
.toLowerCase();
|
|
13
|
+
if (valueAClean > valueBClean) {
|
|
14
|
+
return -1;
|
|
15
|
+
}
|
|
16
|
+
if (valueBClean > valueAClean) {
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
return 0;
|
|
20
|
+
};
|
|
21
|
+
exports.default = byStringDescending;
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
2
4
|
* Convert a string into Capitalised Text.
|
|
3
5
|
* https://stackoverflow.com/a/196991/2664955
|
|
4
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
const formatCapitalise = ({ input, split } = { input: '', split: '_' }) => {
|
|
8
|
+
return input
|
|
9
|
+
.replace(`/${split}/g`, ' ')
|
|
10
|
+
.replace(/\w\S*/g, function (txt) {
|
|
11
|
+
return txt.charAt(0)
|
|
12
|
+
.toUpperCase() + txt.substr(1)
|
|
13
|
+
.toLowerCase();
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
exports.default = formatCapitalise;
|
package/string/getCleanFolder.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const trim_1 = __importDefault(require("lodash/trim"));
|
|
7
|
+
/**
|
|
2
8
|
* Take an input that may have a / before or after the input and return just the folder.
|
|
3
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const getCleanFolder = ({ input }) => (0, trim_1.default)(input, '/')
|
|
11
|
+
.trim();
|
|
12
|
+
exports.default = getCleanFolder;
|
package/string/getString.js
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const isArray_1 = __importDefault(require("lodash/isArray"));
|
|
7
|
+
const isDate_1 = __importDefault(require("lodash/isDate"));
|
|
8
|
+
const isNumber_1 = __importDefault(require("lodash/isNumber"));
|
|
9
|
+
const isObject_1 = __importDefault(require("lodash/isObject"));
|
|
10
|
+
const isString_1 = __importDefault(require("lodash/isString"));
|
|
11
|
+
const getNumber_1 = __importDefault(require("../date/getNumber"));
|
|
12
|
+
/**
|
|
2
13
|
* Convert into string.
|
|
3
|
-
*/
|
|
14
|
+
*/
|
|
15
|
+
const getString = ({ input }) => {
|
|
16
|
+
let string = '';
|
|
17
|
+
// Already a string
|
|
18
|
+
if ((0, isString_1.default)(input)) {
|
|
19
|
+
string = input;
|
|
20
|
+
}
|
|
21
|
+
// Convert a number into a date
|
|
22
|
+
else if ((0, isNumber_1.default)(input)) {
|
|
23
|
+
string = input.toString();
|
|
24
|
+
}
|
|
25
|
+
// Object or array to JSON
|
|
26
|
+
else if ((0, isObject_1.default)(input) || (0, isArray_1.default)(input)) {
|
|
27
|
+
string = JSON.stringify(input);
|
|
28
|
+
}
|
|
29
|
+
// Date
|
|
30
|
+
else if ((0, isDate_1.default)(input)) {
|
|
31
|
+
string = (0, getNumber_1.default)({ input })
|
|
32
|
+
.toString();
|
|
33
|
+
}
|
|
34
|
+
return string;
|
|
35
|
+
};
|
|
36
|
+
exports.default = getString;
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
2
4
|
* Converts a stream into a string.
|
|
3
5
|
* https://stackoverflow.com/a/49428486
|
|
4
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
const getStringFromStream = ({ stream }) => {
|
|
8
|
+
const chunks = [];
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
|
11
|
+
stream.on('error', (err) => reject(err));
|
|
12
|
+
stream.on('end', () => resolve(Buffer.concat(chunks)
|
|
13
|
+
.toString('utf8')));
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
exports.default = getStringFromStream;
|