@8ms/helpers 2.0.0 → 2.0.1
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/.github/workflows/deploy_npmjs.yml +7 -0
- package/.yarn/install-state.gz +0 -0
- package/_class/BaseClass.d.ts +18 -0
- package/_class/BaseClass.js +53 -0
- package/_class/BaseNamespace.d.ts +9 -0
- package/_class/BaseNamespace.js +27 -0
- package/_class/index.d.ts +2 -0
- package/_class/index.js +7 -0
- package/adverity/getJobs.d.ts +15 -0
- package/adverity/getJobs.js +30 -0
- package/adverity/index.d.ts +112 -0
- package/adverity/index.js +61 -0
- package/api/ApiResponseClass.d.ts +35 -0
- package/api/ApiResponseClass.js +97 -0
- package/api/index.d.ts +22 -0
- package/api/index.js +44 -0
- package/array/index.d.ts +8 -0
- package/array/index.js +17 -0
- package/atInternet/index.d.ts +16 -0
- package/atInternet/index.js +18 -0
- package/aws/athenaExpress/AwsAthenaNamespace.d.ts +8 -0
- package/aws/athenaExpress/AwsAthenaNamespace.js +82 -0
- package/aws/athenaExpress/index.d.ts +10 -0
- package/aws/athenaExpress/index.js +40 -0
- package/aws/ec2/AwsEc2Namespace.d.ts +10 -0
- package/aws/ec2/AwsEc2Namespace.js +78 -0
- package/aws/ec2/index.d.ts +3 -0
- package/aws/ec2/index.js +16 -0
- package/aws/ecs/AwsEcsNamespace.d.ts +53 -0
- package/aws/ecs/AwsEcsNamespace.js +159 -0
- package/aws/ecs/index.d.ts +3 -0
- package/aws/ecs/index.js +16 -0
- package/aws/glue/AwsGlueNamespace.d.ts +12 -0
- package/aws/glue/AwsGlueNamespace.js +70 -0
- package/aws/glue/index.d.ts +3 -0
- package/aws/glue/index.js +16 -0
- package/aws/index.d.ts +9 -0
- package/aws/index.js +34 -0
- package/aws/isResponse200.d.ts +4 -0
- package/aws/isResponse200.js +16 -0
- package/aws/lambda/AwsLambdaNamespace.d.ts +21 -0
- package/aws/lambda/AwsLambdaNamespace.js +110 -0
- package/aws/lambda/index.d.ts +4 -0
- package/aws/lambda/index.js +21 -0
- package/aws/s3/AwsS3Namespace.d.ts +60 -0
- package/aws/s3/AwsS3Namespace.js +401 -0
- package/aws/s3/index.d.ts +25 -0
- package/aws/s3/index.js +36 -0
- package/aws/s3/payload.d.ts +42 -0
- package/aws/s3/payload.js +46 -0
- package/aws/ses/AwsSesNamespace.d.ts +18 -0
- package/aws/ses/AwsSesNamespace.js +69 -0
- package/aws/ses/SimpleEmail.d.ts +56 -0
- package/aws/ses/SimpleEmail.js +106 -0
- package/aws/ses/index.d.ts +4 -0
- package/aws/ses/index.js +18 -0
- package/aws/sqs/AwsSqsNamespace.d.ts +34 -0
- package/aws/sqs/AwsSqsNamespace.js +96 -0
- package/aws/sqs/index.d.ts +3 -0
- package/aws/sqs/index.js +16 -0
- package/aws/ssm/AwsSsmNamespace.d.ts +11 -0
- package/aws/ssm/AwsSsmNamespace.js +89 -0
- package/aws/ssm/index.d.ts +3 -0
- package/aws/ssm/index.js +16 -0
- package/axios/deleteRequest.d.ts +6 -0
- package/axios/deleteRequest.js +33 -0
- package/axios/get.d.ts +5 -0
- package/axios/get.js +31 -0
- package/axios/index.d.ts +3 -0
- package/axios/index.js +9 -0
- package/axios/post.d.ts +5 -0
- package/axios/post.js +32 -0
- package/boolean/getBoolean.d.ts +4 -0
- package/boolean/getBoolean.js +23 -0
- package/boolean/index.d.ts +1 -0
- package/boolean/index.js +5 -0
- package/brightData/index.d.ts +15 -0
- package/brightData/index.js +20 -0
- package/brightData/serpApi/buildGoogleSerpUrl.d.ts +32 -0
- package/brightData/serpApi/buildGoogleSerpUrl.js +116 -0
- package/brightData/serpApi/buildGoogleTrendsUrl.d.ts +22 -0
- package/brightData/serpApi/buildGoogleTrendsUrl.js +61 -0
- package/brightData/serpApi/getAsyncRequestId.d.ts +8 -0
- package/brightData/serpApi/getAsyncRequestId.js +36 -0
- package/brightData/serpApi/getAsyncResults.d.ts +7 -0
- package/brightData/serpApi/getAsyncResults.js +35 -0
- package/brightData/serpApi/getRealtime.d.ts +5 -0
- package/brightData/serpApi/getRealtime.js +30 -0
- package/brightData/serpApi/index.d.ts +14 -0
- package/brightData/serpApi/index.js +23 -0
- package/brightData/webScraperIde/getBatch.d.ts +7 -0
- package/brightData/webScraperIde/getBatch.js +28 -0
- package/brightData/webScraperIde/getRealtime.d.ts +7 -0
- package/brightData/webScraperIde/getRealtime.js +49 -0
- package/brightData/webScraperIde/index.d.ts +2 -0
- package/brightData/webScraperIde/index.js +7 -0
- package/cache/index.d.ts +2 -0
- package/cache/index.js +48 -0
- package/cache/test/cache.test.d.ts +1 -0
- package/cache/test/cache.test.js +10 -0
- package/crud/index.d.ts +6 -0
- package/crud/index.js +10 -0
- package/crypto/getDecrypt.d.ts +5 -0
- package/crypto/getDecrypt.js +47 -0
- package/crypto/getEncrypt.d.ts +5 -0
- package/crypto/getEncrypt.js +47 -0
- package/crypto/getRandom.d.ts +4 -0
- package/crypto/getRandom.js +12 -0
- package/crypto/getSha256.d.ts +5 -0
- package/crypto/getSha256.js +48 -0
- package/crypto/index.d.ts +4 -0
- package/crypto/index.js +11 -0
- package/date/calculation.d.ts +75 -0
- package/date/calculation.js +207 -0
- package/date/financialYear.d.ts +19 -0
- package/date/financialYear.js +85 -0
- package/date/format.d.ts +68 -0
- package/date/format.js +150 -0
- package/date/index.d.ts +35 -0
- package/date/index.js +57 -0
- package/environment/index.d.ts +32 -0
- package/environment/index.js +92 -0
- package/eskimi/getAgeGroup.d.ts +4 -0
- package/eskimi/getAgeGroup.js +15 -0
- package/eskimi/getData.d.ts +4 -0
- package/eskimi/getData.js +17 -0
- package/eskimi/getDevice.d.ts +4 -0
- package/eskimi/getDevice.js +15 -0
- package/eskimi/getGender.d.ts +4 -0
- package/eskimi/getGender.js +15 -0
- package/eskimi/index.d.ts +49 -0
- package/eskimi/index.js +96 -0
- package/file/createDirectory.d.ts +5 -0
- package/file/createDirectory.js +50 -0
- package/file/index.d.ts +1 -0
- package/file/index.js +5 -0
- package/geo/countries.d.ts +12 -0
- package/geo/countries.js +222 -0
- package/geo/index.d.ts +2 -0
- package/geo/index.js +7 -0
- package/geo/languages.d.ts +9 -0
- package/geo/languages.js +58 -0
- package/google/bigQuery/GoogleBigQueryNamespace.d.ts +51 -0
- package/google/bigQuery/GoogleBigQueryNamespace.js +165 -0
- package/google/bigQuery/index.d.ts +5 -0
- package/google/bigQuery/index.js +37 -0
- package/google/bigQuery/loadData.d.ts +19 -0
- package/google/bigQuery/loadData.js +18 -0
- package/google/index.d.ts +27 -0
- package/google/index.js +24 -0
- package/google/sheets/GoogleSheetsNamespace.d.ts +16 -0
- package/google/sheets/GoogleSheetsNamespace.js +81 -0
- package/google/sheets/getAssociatedData.d.ts +10 -0
- package/google/sheets/getAssociatedData.js +43 -0
- package/google/sheets/index.d.ts +8 -0
- package/google/sheets/index.js +37 -0
- package/google/storage/GoogleCloudStorageNamespace.d.ts +20 -0
- package/google/storage/GoogleCloudStorageNamespace.js +108 -0
- package/google/storage/index.d.ts +3 -0
- package/google/storage/index.js +30 -0
- package/googleAds/GoogleAdsNamespace.d.ts +11 -0
- package/googleAds/GoogleAdsNamespace.js +73 -0
- package/googleAds/index.d.ts +11 -0
- package/googleAds/index.js +30 -0
- package/googleAds/keywordPlanner/index.d.ts +40 -0
- package/googleAds/keywordPlanner/index.js +59 -0
- package/googlePageSpeed/GooglePageSpeedNamespace.d.ts +11 -0
- package/googlePageSpeed/GooglePageSpeedNamespace.js +35 -0
- package/googlePageSpeed/index.d.ts +17 -0
- package/googlePageSpeed/index.js +44 -0
- package/googleSearchIncidents/index.d.ts +69 -0
- package/googleSearchIncidents/index.js +46 -0
- package/greenDomain/index.d.ts +21 -0
- package/greenDomain/index.js +41 -0
- package/inngest/index.d.ts +6 -0
- package/inngest/index.js +10 -0
- package/json/getJsonNewline.d.ts +1 -0
- package/json/getJsonNewline.js +13 -0
- package/json/index.d.ts +2 -0
- package/json/index.js +7 -0
- package/json/isJson.d.ts +1 -0
- package/json/isJson.js +26 -0
- package/littleWarden/LittleWardenNamespace.d.ts +11 -0
- package/littleWarden/LittleWardenNamespace.js +38 -0
- package/littleWarden/getUrlStatus.d.ts +4 -0
- package/littleWarden/getUrlStatus.js +16 -0
- package/littleWarden/index.d.ts +29 -0
- package/littleWarden/index.js +74 -0
- package/lumar/api/buildRequest.d.ts +13 -0
- package/lumar/api/buildRequest.js +80 -0
- package/lumar/api/getData.d.ts +5 -0
- package/lumar/api/getData.js +13 -0
- package/lumar/api/index.d.ts +36 -0
- package/lumar/api/index.js +33 -0
- package/lumar/api/initClient.d.ts +6 -0
- package/lumar/api/initClient.js +26 -0
- package/lumar/graphql/columns.d.ts +28 -0
- package/lumar/graphql/columns.js +31 -0
- package/lumar/graphql/getData.d.ts +1 -0
- package/lumar/graphql/getData.js +20 -0
- package/lumar/graphql/index.d.ts +29 -0
- package/lumar/graphql/index.js +39 -0
- package/lumar/graphql/initClient.d.ts +5 -0
- package/lumar/graphql/initClient.js +25 -0
- package/lumar/graphql/queries/crawl.d.ts +5 -0
- package/lumar/graphql/queries/crawl.js +2 -0
- package/lumar/graphql/queries/getCrawls.d.ts +18 -0
- package/lumar/graphql/queries/getCrawls.js +33 -0
- package/lumar/graphql/queries/getReportDifferences.d.ts +24 -0
- package/lumar/graphql/queries/getReportDifferences.js +37 -0
- package/lumar/graphql/queries/getRows.d.ts +38 -0
- package/lumar/graphql/queries/getRows.js +57 -0
- package/lumar/graphql/queries/getTotals.d.ts +25 -0
- package/lumar/graphql/queries/getTotals.js +40 -0
- package/lumar/graphql/queries/row.d.ts +157 -0
- package/lumar/graphql/queries/row.js +2 -0
- package/lumar/graphql/reportTemplates.d.ts +67 -0
- package/lumar/graphql/reportTemplates.js +70 -0
- package/myTarget/request.d.ts +5 -0
- package/myTarget/request.js +17 -0
- package/nextAuth/index.d.ts +6 -0
- package/nextAuth/index.js +11 -0
- package/nextAuth/isSessionReady.d.ts +1 -0
- package/nextAuth/isSessionReady.js +13 -0
- package/nextJs/getIp.d.ts +6 -0
- package/nextJs/getIp.js +14 -0
- package/nextJs/getUserAgent.d.ts +6 -0
- package/nextJs/getUserAgent.js +8 -0
- package/nextJs/index.d.ts +2 -0
- package/nextJs/index.js +7 -0
- package/number/format.d.ts +12 -0
- package/number/format.js +20 -0
- package/number/formatCurrency.d.ts +5 -0
- package/number/formatCurrency.js +21 -0
- package/number/getDecimal.d.ts +4 -0
- package/number/getDecimal.js +12 -0
- package/number/getNumber.d.ts +4 -0
- package/number/getNumber.js +48 -0
- package/number/getPercentIncrease.d.ts +4 -0
- package/number/getPercentIncrease.js +16 -0
- package/number/getSafeDivide.d.ts +11 -0
- package/number/getSafeDivide.js +20 -0
- package/number/index.d.ts +6 -0
- package/number/index.js +15 -0
- package/object/index.d.ts +1 -0
- package/object/index.js +5 -0
- package/object/replaceKeys.d.ts +5 -0
- package/object/replaceKeys.js +25 -0
- package/onePassword/OnePasswordNamespace.d.ts +13 -0
- package/onePassword/OnePasswordNamespace.js +81 -0
- package/onePassword/index.d.ts +7 -0
- package/onePassword/index.js +25 -0
- package/openAi/OpenAiNamespace.d.ts +11 -0
- package/openAi/OpenAiNamespace.js +44 -0
- package/openAi/index.d.ts +5 -0
- package/openAi/index.js +30 -0
- package/package.json +2 -2
- package/prisma/PrismaNamespace.d.ts +8 -0
- package/prisma/PrismaNamespace.js +79 -0
- package/prisma/getDecimal.d.ts +4 -0
- package/prisma/getDecimal.js +23 -0
- package/prisma/index.d.ts +8 -0
- package/prisma/index.js +29 -0
- package/snapchat/SnapchatNamespace.d.ts +15 -0
- package/snapchat/SnapchatNamespace.js +30 -0
- package/snapchat/index.d.ts +7 -0
- package/snapchat/index.js +30 -0
- package/sorting/byNumberAscending.d.ts +4 -0
- package/sorting/byNumberAscending.js +19 -0
- package/sorting/byNumberDescending.d.ts +4 -0
- package/sorting/byNumberDescending.js +22 -0
- package/sorting/byStringAscending.d.ts +4 -0
- package/sorting/byStringAscending.js +16 -0
- package/sorting/byStringDescending.d.ts +4 -0
- package/sorting/byStringDescending.js +16 -0
- package/sorting/index.d.ts +4 -0
- package/sorting/index.js +11 -0
- package/stream/index.d.ts +1 -0
- package/stream/index.js +5 -0
- package/stream/sort.d.ts +13 -0
- package/stream/sort.js +51 -0
- package/string/getCapitalised.d.ts +5 -0
- package/string/getCapitalised.js +18 -0
- package/string/getClean.d.ts +18 -0
- package/string/getClean.js +51 -0
- package/string/getFolder.d.ts +4 -0
- package/string/getFolder.js +15 -0
- package/string/getProperCase.d.ts +11 -0
- package/string/getProperCase.js +25 -0
- package/string/getString.d.ts +4 -0
- package/string/getString.js +34 -0
- package/string/getStringFromStream.d.ts +5 -0
- package/string/getStringFromStream.js +17 -0
- package/string/getUnescaped.d.ts +6 -0
- package/string/getUnescaped.js +26 -0
- package/string/getWithoutAccents.d.ts +5 -0
- package/string/getWithoutAccents.js +13 -0
- package/string/getWithoutHtmlTags.d.ts +5 -0
- package/string/getWithoutHtmlTags.js +12 -0
- package/string/getWithoutPunctuation.d.ts +5 -0
- package/string/getWithoutPunctuation.js +13 -0
- package/string/getWithoutUnderscores.d.ts +4 -0
- package/string/getWithoutUnderscores.js +11 -0
- package/string/getWithoutWhitespaces.d.ts +5 -0
- package/string/getWithoutWhitespaces.js +13 -0
- package/string/index.d.ts +12 -0
- package/string/index.js +27 -0
- package/swr/index.d.ts +42 -0
- package/swr/index.js +59 -0
- package/upTimeRobot/UpTimeRobotNamespace.d.ts +31 -0
- package/upTimeRobot/UpTimeRobotNamespace.js +52 -0
- package/upTimeRobot/index.d.ts +38 -0
- package/upTimeRobot/index.js +63 -0
- package/url/index.d.ts +19 -0
- package/url/index.js +70 -0
- package/url/writeUrlContents.d.ts +6 -0
- package/url/writeUrlContents.js +75 -0
- package/util/defaultTo.d.ts +4 -0
- package/util/defaultTo.js +44 -0
- package/util/getBrotliCompressed.d.ts +5 -0
- package/util/getBrotliCompressed.js +23 -0
- package/util/getBrotliDecompressed.d.ts +5 -0
- package/util/getBrotliDecompressed.js +24 -0
- package/util/getClean.d.ts +11 -0
- package/util/getClean.js +23 -0
- package/util/getGzipCompressed.d.ts +5 -0
- package/util/getGzipCompressed.js +23 -0
- package/util/getGzipDecompressed.d.ts +5 -0
- package/util/getGzipDecompressed.js +24 -0
- package/util/getWithoutHash.d.ts +4 -0
- package/util/getWithoutHash.js +18 -0
- package/util/getWithoutParameter.d.ts +4 -0
- package/util/getWithoutParameter.js +18 -0
- package/util/index.d.ts +11 -0
- package/util/index.js +25 -0
- package/util/isUndefined.d.ts +4 -0
- package/util/isUndefined.js +13 -0
- package/util/promiseChunks.d.ts +5 -0
- package/util/promiseChunks.js +19 -0
- package/util/sleep.d.ts +1 -0
- package/util/sleep.js +7 -0
- package/webWorker/index.d.ts +5 -0
- package/webWorker/index.js +9 -0
- package/xml/getXml.d.ts +1 -0
- package/xml/getXml.js +18 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRealtime = void 0;
|
|
4
|
+
const axios_1 = require("../../axios");
|
|
5
|
+
const api_1 = require("../../api");
|
|
6
|
+
const util_1 = require("../../util");
|
|
7
|
+
/**
|
|
8
|
+
* Depends on the Scraper setup!
|
|
9
|
+
*
|
|
10
|
+
* Make the request and pool the response until the data is available.
|
|
11
|
+
*/
|
|
12
|
+
const getRealtime = async (auth, scraperId, data = {}) => {
|
|
13
|
+
let response = {};
|
|
14
|
+
const requestUrl = `https://api.brightdata.com/dca/trigger_immediate?collector=${scraperId}`;
|
|
15
|
+
const requestResponse = await (0, axios_1.post)(requestUrl, data, {
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${auth.apiKey}`
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
if (requestResponse.isSuccess()) {
|
|
21
|
+
const responseId = requestResponse.getBodyDefaultTo(["response_id"], "");
|
|
22
|
+
if ("" !== responseId) {
|
|
23
|
+
let state = api_1.ApiState.PENDING;
|
|
24
|
+
while (api_1.ApiState.PENDING === state) {
|
|
25
|
+
const resultUrl = `https://api.brightdata.com/dca/get_result?response_id=${responseId}`;
|
|
26
|
+
// Use fetch with the agent option to make an HTTP request through the proxy
|
|
27
|
+
// Replace <target_url> with the URL you want to request
|
|
28
|
+
const resultResponse = await (0, axios_1.get)(resultUrl, {
|
|
29
|
+
headers: {
|
|
30
|
+
Authorization: `Bearer ${auth.apiKey}`
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (resultResponse.isSuccess()) {
|
|
34
|
+
if (undefined !== resultResponse.body.pending &&
|
|
35
|
+
true === resultResponse.body.pending) {
|
|
36
|
+
state = api_1.ApiState.PENDING;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
state = api_1.ApiState.SUCCESS;
|
|
40
|
+
response = resultResponse.getBody();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
await (0, util_1.sleep)(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return response;
|
|
48
|
+
};
|
|
49
|
+
exports.getRealtime = getRealtime;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRealtime = exports.getBatch = void 0;
|
|
4
|
+
var getBatch_1 = require("./getBatch");
|
|
5
|
+
Object.defineProperty(exports, "getBatch", { enumerable: true, get: function () { return getBatch_1.getBatch; } });
|
|
6
|
+
var getRealtime_1 = require("./getRealtime");
|
|
7
|
+
Object.defineProperty(exports, "getRealtime", { enumerable: true, get: function () { return getRealtime_1.getRealtime; } });
|
package/cache/index.d.ts
ADDED
package/cache/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setCache = exports.getCache = void 0;
|
|
4
|
+
const cache = new Map();
|
|
5
|
+
const getCache = (key) => {
|
|
6
|
+
let response = null;
|
|
7
|
+
if (cache.has(key)) {
|
|
8
|
+
const cacheItem = cache.get(key);
|
|
9
|
+
// Timed expiry
|
|
10
|
+
if (cacheItem.expires > 0) {
|
|
11
|
+
// https://ui.dev/get-current-timestamp-javascript
|
|
12
|
+
const expiresAt = Math.floor(cacheItem.insertedAt / 1000) + cacheItem.expires;
|
|
13
|
+
const now = Math.floor(Date.now() / 1000);
|
|
14
|
+
// If we are now beyond the expiry date, update the data
|
|
15
|
+
if (now < expiresAt) {
|
|
16
|
+
response = cacheItem;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// 0 - Never expires
|
|
20
|
+
else {
|
|
21
|
+
response = cacheItem;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return response;
|
|
25
|
+
};
|
|
26
|
+
exports.getCache = getCache;
|
|
27
|
+
const setCache = (key, data, expires = 0, force = false) => {
|
|
28
|
+
const now = Math.floor(Date.now() / 1000);
|
|
29
|
+
if (cache.has(key) && !force) {
|
|
30
|
+
const cacheItem = cache.get(key);
|
|
31
|
+
// 0 - Never expires
|
|
32
|
+
if (cacheItem.expires > 0) {
|
|
33
|
+
// https://ui.dev/get-current-timestamp-javascript
|
|
34
|
+
const expiresAt = Math.floor(cacheItem.insertedAt / 1000) + cacheItem.expires;
|
|
35
|
+
// If we are now beyond the expiry date, update the data
|
|
36
|
+
if (now < expiresAt) {
|
|
37
|
+
return cacheItem;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
cache.set(key, {
|
|
42
|
+
data,
|
|
43
|
+
expires,
|
|
44
|
+
insertedAt: now,
|
|
45
|
+
});
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
exports.setCache = setCache;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const __1 = require("../");
|
|
4
|
+
test('cache', () => {
|
|
5
|
+
const item1 = (0, __1.getCache)('test');
|
|
6
|
+
// console.log('item1', item1);
|
|
7
|
+
(0, __1.setCache)('test', { 'this is something': 'item' });
|
|
8
|
+
const item2 = (0, __1.getCache)('test');
|
|
9
|
+
// console.log('item2', item2);
|
|
10
|
+
});
|
package/crud/index.d.ts
ADDED
package/crud/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CrudState = void 0;
|
|
4
|
+
var CrudState;
|
|
5
|
+
(function (CrudState) {
|
|
6
|
+
CrudState["CREATE"] = "CREATE";
|
|
7
|
+
CrudState["READ"] = "READ";
|
|
8
|
+
CrudState["UPDATE"] = "UPDATE";
|
|
9
|
+
CrudState["DELETE"] = "DELETE";
|
|
10
|
+
})(CrudState || (exports.CrudState = CrudState = {}));
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getDecrypt = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* Decrypt an encoding string using a salt
|
|
39
|
+
* Library: crypto-js
|
|
40
|
+
*/
|
|
41
|
+
const getDecrypt = async (appSalt, input, salt) => {
|
|
42
|
+
const { AES, enc } = await Promise.resolve().then(() => __importStar(require("crypto-js")));
|
|
43
|
+
const customSalt = `${appSalt}-${salt}`;
|
|
44
|
+
return AES.decrypt(input, customSalt)
|
|
45
|
+
.toString(enc.Utf8);
|
|
46
|
+
};
|
|
47
|
+
exports.getDecrypt = getDecrypt;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getEncrypt = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* Encrypt an encoding string using a salt
|
|
39
|
+
* Library: crypto-js
|
|
40
|
+
*/
|
|
41
|
+
const getEncrypt = async (appSalt, input, salt) => {
|
|
42
|
+
const { AES } = await Promise.resolve().then(() => __importStar(require("crypto-js")));
|
|
43
|
+
const customSalt = `${appSalt}-${salt}`;
|
|
44
|
+
return AES.encrypt(input, customSalt)
|
|
45
|
+
.toString();
|
|
46
|
+
};
|
|
47
|
+
exports.getEncrypt = getEncrypt;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRandom = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Create a random string and return a number of characters from it.
|
|
6
|
+
*/
|
|
7
|
+
const getRandom = (length) => {
|
|
8
|
+
return Math.random()
|
|
9
|
+
.toString(36)
|
|
10
|
+
.substr(0, length);
|
|
11
|
+
};
|
|
12
|
+
exports.getRandom = getRandom;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getSha256 = void 0;
|
|
37
|
+
const string_1 = require("../string");
|
|
38
|
+
/**
|
|
39
|
+
* Encrypt a string using sha256
|
|
40
|
+
* Library: crypto-js
|
|
41
|
+
*/
|
|
42
|
+
const getSha256 = async (input) => {
|
|
43
|
+
const { SHA256 } = await Promise.resolve().then(() => __importStar(require("crypto-js")));
|
|
44
|
+
const inputString = (0, string_1.getString)(input);
|
|
45
|
+
return SHA256(inputString)
|
|
46
|
+
.toString();
|
|
47
|
+
};
|
|
48
|
+
exports.getSha256 = getSha256;
|
package/crypto/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSha256 = exports.getRandom = exports.getEncrypt = exports.getDecrypt = void 0;
|
|
4
|
+
var getDecrypt_1 = require("./getDecrypt");
|
|
5
|
+
Object.defineProperty(exports, "getDecrypt", { enumerable: true, get: function () { return getDecrypt_1.getDecrypt; } });
|
|
6
|
+
var getEncrypt_1 = require("./getEncrypt");
|
|
7
|
+
Object.defineProperty(exports, "getEncrypt", { enumerable: true, get: function () { return getEncrypt_1.getEncrypt; } });
|
|
8
|
+
var getRandom_1 = require("./getRandom");
|
|
9
|
+
Object.defineProperty(exports, "getRandom", { enumerable: true, get: function () { return getRandom_1.getRandom; } });
|
|
10
|
+
var getSha256_1 = require("./getSha256");
|
|
11
|
+
Object.defineProperty(exports, "getSha256", { enumerable: true, get: function () { return getSha256_1.getSha256; } });
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { DateTime, Zone } from "luxon";
|
|
2
|
+
import { InputDate, Timeframe } from "./";
|
|
3
|
+
/**
|
|
4
|
+
* Convert an client's input (any time-zone) ready to be used by the server (UTC).
|
|
5
|
+
*/
|
|
6
|
+
export declare const getUtcDate: (input: InputDate, inputZone?: Zone) => DateTime<boolean>;
|
|
7
|
+
/**
|
|
8
|
+
* Assume the input is always UTC.
|
|
9
|
+
*
|
|
10
|
+
* If it's not UTC, it needs to be converted to UTC before being used.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getDate: (input?: InputDate, setMidnight?: boolean) => DateTime<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Similar to date-fns' eachDayOfInterval, however the timezone messes this function up.
|
|
15
|
+
* https://date-fns.org/v2.28.0/docs/eachDayOfInterval
|
|
16
|
+
* https://www.gov.uk/when-do-the-clocks-change
|
|
17
|
+
*/
|
|
18
|
+
export declare const getDatesBetween: (start: InputDate, end: InputDate) => DateTime<true>[];
|
|
19
|
+
/**
|
|
20
|
+
* If a given date is beyond the maximum, return the maximum.
|
|
21
|
+
*/
|
|
22
|
+
export declare const getMax: (input: DateTime, max: DateTime) => DateTime<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* If a given date is before the minimum, return the minimum.
|
|
25
|
+
*/
|
|
26
|
+
export declare const getMin: (input: DateTime, min: DateTime) => DateTime<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieve the closest last Monday relative to the input or today.
|
|
29
|
+
* 0 weeksAgo - Tuesday (10th), return Monday (8th)
|
|
30
|
+
* 1 weeksAgo - Tuesday (10th), return Monday (1st)
|
|
31
|
+
*/
|
|
32
|
+
export declare const getMonday: (input?: InputDate, weeksAgo?: number) => DateTime<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieve the closest last Sunday relative to the input or today.
|
|
35
|
+
* 0 weeksAgo - Tuesday (17th), return Sunday (14th)
|
|
36
|
+
* 1 weeksAgo - Tuesday (17th), return Monday (7th)
|
|
37
|
+
*/
|
|
38
|
+
export declare const getSunday: (input?: InputDate, weeksAgo?: number) => DateTime<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Return an object of start/end predefined date of Last Week.
|
|
41
|
+
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
42
|
+
*/
|
|
43
|
+
export declare const getLastWeek: () => Timeframe;
|
|
44
|
+
/**
|
|
45
|
+
* Return an object of start/end predefined date of This Week.
|
|
46
|
+
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
47
|
+
*/
|
|
48
|
+
export declare const getThisWeek: () => Timeframe;
|
|
49
|
+
/**
|
|
50
|
+
* Return an object of start/end predefined date of Two Weeks Ago.
|
|
51
|
+
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
52
|
+
*/
|
|
53
|
+
export declare const getTwoWeeksAgo: () => Timeframe;
|
|
54
|
+
/**
|
|
55
|
+
* Shortcut to get today's date.
|
|
56
|
+
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
57
|
+
*/
|
|
58
|
+
export declare const getToday: (setMidnight?: boolean) => DateTime<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* From a given input, move the date back X weeksAgo
|
|
61
|
+
*/
|
|
62
|
+
export declare const getWeeksAgo: (input?: InputDate, weeksAgo?: number) => DateTime<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Shortcut to get yesterday's date.
|
|
65
|
+
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
66
|
+
*/
|
|
67
|
+
export declare const getYesterday: (input?: InputDate) => DateTime<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* Check to see if a given timeframe is This Week.
|
|
70
|
+
*/
|
|
71
|
+
export declare const isThisWeek: (start: InputDate, end: InputDate) => boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Check to see if a given timeframe is Last Week.
|
|
74
|
+
*/
|
|
75
|
+
export declare const isLastWeek: (start: InputDate, end: InputDate) => boolean;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLastWeek = exports.isThisWeek = exports.getYesterday = exports.getWeeksAgo = exports.getToday = exports.getTwoWeeksAgo = exports.getThisWeek = exports.getLastWeek = exports.getSunday = exports.getMonday = exports.getMin = exports.getMax = exports.getDatesBetween = exports.getDate = exports.getUtcDate = void 0;
|
|
4
|
+
const luxon_1 = require("luxon");
|
|
5
|
+
/**
|
|
6
|
+
* Convert an client's input (any time-zone) ready to be used by the server (UTC).
|
|
7
|
+
*/
|
|
8
|
+
const getUtcDate = (input, inputZone) => {
|
|
9
|
+
let instance = luxon_1.DateTime.now();
|
|
10
|
+
if (input) {
|
|
11
|
+
if (input instanceof Date) {
|
|
12
|
+
instance = luxon_1.DateTime.fromJSDate(input);
|
|
13
|
+
}
|
|
14
|
+
else if (input instanceof luxon_1.DateTime) {
|
|
15
|
+
instance = input;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
instance = luxon_1.DateTime.fromISO(input.toString(), { zone: inputZone });
|
|
19
|
+
if (!instance.isValid) {
|
|
20
|
+
instance = luxon_1.DateTime.fromFormat(input.toString(), "yyyy-MM-dd HH:mm:ss", { zone: inputZone });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return instance.toUTC();
|
|
25
|
+
};
|
|
26
|
+
exports.getUtcDate = getUtcDate;
|
|
27
|
+
/**
|
|
28
|
+
* Assume the input is always UTC.
|
|
29
|
+
*
|
|
30
|
+
* If it's not UTC, it needs to be converted to UTC before being used.
|
|
31
|
+
*/
|
|
32
|
+
const getDate = (input, setMidnight) => {
|
|
33
|
+
let instance = luxon_1.DateTime.now();
|
|
34
|
+
if (input) {
|
|
35
|
+
if (input instanceof Date) {
|
|
36
|
+
instance = luxon_1.DateTime.fromJSDate(input).toUTC();
|
|
37
|
+
}
|
|
38
|
+
else if (input instanceof luxon_1.DateTime) {
|
|
39
|
+
instance = input.toUTC();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
instance = luxon_1.DateTime.fromISO(input.toString(), { zone: "utc" });
|
|
43
|
+
if (!instance.isValid) {
|
|
44
|
+
instance = luxon_1.DateTime.fromFormat(input.toString(), "yyyy-MM-dd HH:mm:ss", { zone: "utc" });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// instance = instance.setZone("utc");
|
|
49
|
+
if (setMidnight) {
|
|
50
|
+
instance = instance.set({
|
|
51
|
+
hour: 0,
|
|
52
|
+
minute: 0,
|
|
53
|
+
second: 0,
|
|
54
|
+
millisecond: 0,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return instance;
|
|
58
|
+
};
|
|
59
|
+
exports.getDate = getDate;
|
|
60
|
+
/**
|
|
61
|
+
* Similar to date-fns' eachDayOfInterval, however the timezone messes this function up.
|
|
62
|
+
* https://date-fns.org/v2.28.0/docs/eachDayOfInterval
|
|
63
|
+
* https://www.gov.uk/when-do-the-clocks-change
|
|
64
|
+
*/
|
|
65
|
+
const getDatesBetween = (start, end) => {
|
|
66
|
+
const startInstance = (0, exports.getDate)(start);
|
|
67
|
+
const endInstance = (0, exports.getDate)(end);
|
|
68
|
+
const response = luxon_1.Interval.fromDateTimes(startInstance.startOf("day"), endInstance.endOf("day"))
|
|
69
|
+
.splitBy({ day: 1 })
|
|
70
|
+
.map(d => d.start);
|
|
71
|
+
return response;
|
|
72
|
+
};
|
|
73
|
+
exports.getDatesBetween = getDatesBetween;
|
|
74
|
+
/**
|
|
75
|
+
* If a given date is beyond the maximum, return the maximum.
|
|
76
|
+
*/
|
|
77
|
+
const getMax = (input, max) => {
|
|
78
|
+
return input > max ? max : input;
|
|
79
|
+
};
|
|
80
|
+
exports.getMax = getMax;
|
|
81
|
+
/**
|
|
82
|
+
* If a given date is before the minimum, return the minimum.
|
|
83
|
+
*/
|
|
84
|
+
const getMin = (input, min) => {
|
|
85
|
+
return input < min ? min : input;
|
|
86
|
+
};
|
|
87
|
+
exports.getMin = getMin;
|
|
88
|
+
/**
|
|
89
|
+
* Retrieve the closest last Monday relative to the input or today.
|
|
90
|
+
* 0 weeksAgo - Tuesday (10th), return Monday (8th)
|
|
91
|
+
* 1 weeksAgo - Tuesday (10th), return Monday (1st)
|
|
92
|
+
*/
|
|
93
|
+
const getMonday = (input, weeksAgo) => {
|
|
94
|
+
let instance = (0, exports.getDate)(input);
|
|
95
|
+
if ("Mon" !== instance.toFormat("EEE")) {
|
|
96
|
+
// Get the ISO Day of week (Monday - 1 to Sunday - 7)
|
|
97
|
+
const isoDay = Number(instance.toFormat("E")) - 1;
|
|
98
|
+
instance = instance.minus({ days: isoDay });
|
|
99
|
+
}
|
|
100
|
+
// Move it back weeks
|
|
101
|
+
instance = instance.minus({ weeks: weeksAgo ?? 0 });
|
|
102
|
+
return instance;
|
|
103
|
+
};
|
|
104
|
+
exports.getMonday = getMonday;
|
|
105
|
+
/**
|
|
106
|
+
* Retrieve the closest last Sunday relative to the input or today.
|
|
107
|
+
* 0 weeksAgo - Tuesday (17th), return Sunday (14th)
|
|
108
|
+
* 1 weeksAgo - Tuesday (17th), return Monday (7th)
|
|
109
|
+
*/
|
|
110
|
+
const getSunday = (input, weeksAgo) => {
|
|
111
|
+
let instance = (0, exports.getDate)(input);
|
|
112
|
+
if ("Sun" !== instance.toFormat("EEE")) {
|
|
113
|
+
// Get the ISO Day of week (Monday - 1 to Sunday - 7)
|
|
114
|
+
const isoDay = Number(instance.toFormat("E"));
|
|
115
|
+
instance = instance.minus({ days: isoDay });
|
|
116
|
+
}
|
|
117
|
+
// Move it back weeks
|
|
118
|
+
instance = instance.minus({ weeks: weeksAgo ?? 0 });
|
|
119
|
+
return instance;
|
|
120
|
+
};
|
|
121
|
+
exports.getSunday = getSunday;
|
|
122
|
+
/**
|
|
123
|
+
* Return an object of start/end predefined date of Last Week.
|
|
124
|
+
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
125
|
+
*/
|
|
126
|
+
const getLastWeek = () => {
|
|
127
|
+
return {
|
|
128
|
+
end: (0, exports.getMonday)(undefined, 0),
|
|
129
|
+
start: (0, exports.getSunday)(undefined, 1),
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
exports.getLastWeek = getLastWeek;
|
|
133
|
+
/**
|
|
134
|
+
* Return an object of start/end predefined date of This Week.
|
|
135
|
+
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
136
|
+
*/
|
|
137
|
+
const getThisWeek = () => {
|
|
138
|
+
return {
|
|
139
|
+
end: (0, exports.getMonday)(undefined, 0),
|
|
140
|
+
start: (0, exports.getSunday)(undefined, -1),
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
exports.getThisWeek = getThisWeek;
|
|
144
|
+
/**
|
|
145
|
+
* Return an object of start/end predefined date of Two Weeks Ago.
|
|
146
|
+
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
147
|
+
*/
|
|
148
|
+
const getTwoWeeksAgo = () => {
|
|
149
|
+
return {
|
|
150
|
+
end: (0, exports.getMonday)(undefined, 1),
|
|
151
|
+
start: (0, exports.getSunday)(undefined, 2),
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
exports.getTwoWeeksAgo = getTwoWeeksAgo;
|
|
155
|
+
/**
|
|
156
|
+
* Shortcut to get today's date.
|
|
157
|
+
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
158
|
+
*/
|
|
159
|
+
const getToday = (setMidnight) => {
|
|
160
|
+
return (0, exports.getDate)(undefined, setMidnight);
|
|
161
|
+
};
|
|
162
|
+
exports.getToday = getToday;
|
|
163
|
+
/**
|
|
164
|
+
* From a given input, move the date back X weeksAgo
|
|
165
|
+
*/
|
|
166
|
+
const getWeeksAgo = (input, weeksAgo) => {
|
|
167
|
+
let instance = (0, exports.getDate)(input);
|
|
168
|
+
instance = instance.plus({ weeks: weeksAgo });
|
|
169
|
+
return instance;
|
|
170
|
+
};
|
|
171
|
+
exports.getWeeksAgo = getWeeksAgo;
|
|
172
|
+
/**
|
|
173
|
+
* Shortcut to get yesterday's date.
|
|
174
|
+
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
175
|
+
*/
|
|
176
|
+
const getYesterday = (input) => {
|
|
177
|
+
let instance = (0, exports.getDate)(input);
|
|
178
|
+
instance = instance.minus({ days: 1 });
|
|
179
|
+
return instance;
|
|
180
|
+
};
|
|
181
|
+
exports.getYesterday = getYesterday;
|
|
182
|
+
/**
|
|
183
|
+
* Check to see if a given timeframe is This Week.
|
|
184
|
+
*/
|
|
185
|
+
const isThisWeek = (start, end) => {
|
|
186
|
+
const inputWeek = {
|
|
187
|
+
start: (0, exports.getDate)(start),
|
|
188
|
+
end: (0, exports.getDate)(end),
|
|
189
|
+
};
|
|
190
|
+
const thisWeek = (0, exports.getThisWeek)();
|
|
191
|
+
// Day confirms same year and month and day
|
|
192
|
+
return inputWeek.start.hasSame(thisWeek.start, "day") && inputWeek.end.hasSame(thisWeek.end, "day");
|
|
193
|
+
};
|
|
194
|
+
exports.isThisWeek = isThisWeek;
|
|
195
|
+
/**
|
|
196
|
+
* Check to see if a given timeframe is Last Week.
|
|
197
|
+
*/
|
|
198
|
+
const isLastWeek = (start, end) => {
|
|
199
|
+
const inputWeek = {
|
|
200
|
+
start: (0, exports.getDate)(start),
|
|
201
|
+
end: (0, exports.getDate)(end),
|
|
202
|
+
};
|
|
203
|
+
const lastWeek = (0, exports.getLastWeek)();
|
|
204
|
+
// Day confirms same year and month and day
|
|
205
|
+
return inputWeek.start.hasSame(lastWeek.start, "day") && inputWeek.end.hasSame(lastWeek.end, "day");
|
|
206
|
+
};
|
|
207
|
+
exports.isLastWeek = isLastWeek;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Timeframe } from "./";
|
|
2
|
+
import { Interval } from "luxon";
|
|
3
|
+
/**
|
|
4
|
+
* Get the current financial year.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getFinancialYear: (year?: number) => Timeframe;
|
|
7
|
+
/**
|
|
8
|
+
* Return the current financial year up to today.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getFinancialYearToDate: () => Timeframe;
|
|
11
|
+
/**
|
|
12
|
+
* Return the current financial year up to yesterday.
|
|
13
|
+
* Timezone should always be London based
|
|
14
|
+
*/
|
|
15
|
+
export declare const getFinancialYearToYesterday: () => Timeframe;
|
|
16
|
+
/**
|
|
17
|
+
* Get the current financial year.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getFinancialYearWeeks: (year?: number) => Interval<boolean>[];
|