@8ms/helpers 1.0.9 → 1.0.13
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/dist/array/tests/getArray.test.d.ts +1 -0
- package/dist/array/tests/getArray.test.js +15 -0
- package/dist/aws/athenaExpress/getClient.js +6 -1
- package/dist/aws/getConfig.d.ts +9 -0
- package/dist/aws/getConfig.js +28 -0
- package/dist/aws/glue/getClient.js +6 -7
- package/dist/aws/lambda/getClient.js +6 -7
- package/dist/aws/s3/getClient.js +6 -7
- package/dist/aws/ses/getClient.js +6 -7
- package/dist/aws/ssm/getClient.js +6 -7
- package/dist/boolean/tests/getBoolean.test.d.ts +1 -0
- package/dist/boolean/tests/getBoolean.test.js +23 -0
- package/dist/date/getMax.d.ts +3 -2
- package/dist/date/getMax.js +5 -7
- package/dist/date/getMin.d.ts +9 -0
- package/dist/date/getMin.js +17 -0
- package/dist/date/index.d.ts +2 -1
- package/dist/date/index.js +3 -1
- package/dist/date/tests/format.test.d.ts +1 -0
- package/dist/date/tests/format.test.js +10 -0
- package/dist/date/tests/getDate.test.d.ts +1 -0
- package/dist/date/tests/getDate.test.js +9 -0
- package/dist/date/tests/getNumber.test.d.ts +1 -0
- package/dist/date/tests/getNumber.test.js +9 -0
- package/dist/nextJs/getIp.d.ts +7 -0
- package/dist/nextJs/getIp.js +14 -0
- package/dist/nextJs/getUserAgent.d.ts +7 -0
- package/dist/nextJs/getUserAgent.js +10 -0
- package/dist/nextJs/index.d.ts +4 -0
- package/dist/nextJs/index.js +10 -0
- package/dist/nextJs/tests/getIp.d.ts +1 -0
- package/dist/nextJs/tests/getIp.js +19 -0
- package/dist/nextJs/tests/getUserAgent.test.d.ts +1 -0
- package/dist/nextJs/tests/getUserAgent.test.js +19 -0
- package/dist/string/tests/getCleanFolder.test.d.ts +1 -0
- package/dist/string/tests/getCleanFolder.test.js +9 -0
- package/dist/url/tests/isAbsolute.test.d.ts +1 -0
- package/dist/url/tests/isAbsolute.test.js +11 -0
- package/dist/url/tests/isRelative.test.d.ts +1 -0
- package/dist/url/tests/isRelative.test.js +11 -0
- package/package.json +27 -19
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('getArray - string', function () {
|
|
5
|
+
var inputString = 'some-input';
|
|
6
|
+
var expected = ['some-input'];
|
|
7
|
+
expect((0, index_1.getArray)({ input: inputString }))
|
|
8
|
+
.toStrictEqual(expected);
|
|
9
|
+
});
|
|
10
|
+
test('getArray - string[]', function () {
|
|
11
|
+
var inputArray = ['some-input'];
|
|
12
|
+
var expected = ['some-input'];
|
|
13
|
+
expect((0, index_1.getArray)({ input: inputArray }))
|
|
14
|
+
.toStrictEqual(expected);
|
|
15
|
+
});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var getConfig_1 = __importDefault(require("../getConfig"));
|
|
3
7
|
var athenaClient = undefined;
|
|
4
8
|
/**
|
|
5
9
|
* Initialise the database using manually provided credentials.
|
|
@@ -7,8 +11,9 @@ var athenaClient = undefined;
|
|
|
7
11
|
var getClient = function (_a) {
|
|
8
12
|
var AthenaExpress = _a.AthenaExpress, AwsSdk = _a.AwsSdk, athenaS3 = _a.athenaS3, config = _a.config, database = _a.database;
|
|
9
13
|
if (!global.awsAthenaClient) {
|
|
14
|
+
var formattedConfig = (0, getConfig_1.default)({ config: config, isAthenaExpress: true });
|
|
10
15
|
// Set the aws authentication
|
|
11
|
-
AwsSdk.config.update(
|
|
16
|
+
AwsSdk.config.update(formattedConfig);
|
|
12
17
|
global.awsAthenaClient = new AthenaExpress.AthenaExpress({
|
|
13
18
|
aws: AwsSdk,
|
|
14
19
|
s3: athenaS3,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AwsConfigType } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* The config must be in a specific structure, if the properties aren't defined don't specify them as they could be inferred (e.g. Lambda).
|
|
4
|
+
*/
|
|
5
|
+
declare const getConfig: ({ config, isAthenaExpress }: {
|
|
6
|
+
config: AwsConfigType;
|
|
7
|
+
isAthenaExpress: boolean;
|
|
8
|
+
}) => object;
|
|
9
|
+
export default getConfig;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* The config must be in a specific structure, if the properties aren't defined don't specify them as they could be inferred (e.g. Lambda).
|
|
5
|
+
*/
|
|
6
|
+
var getConfig = function (_a) {
|
|
7
|
+
var config = _a.config, isAthenaExpress = _a.isAthenaExpress;
|
|
8
|
+
var response = {
|
|
9
|
+
region: config.region,
|
|
10
|
+
};
|
|
11
|
+
// Set the key id and access key if its defined (not required for AWS SAM)
|
|
12
|
+
if ('' !== config.accessKeyId && '' !== config.secretAccessKey) {
|
|
13
|
+
// Athena is a flat structure
|
|
14
|
+
if (isAthenaExpress) {
|
|
15
|
+
response['accessKeyId'] = config.accessKeyId;
|
|
16
|
+
response['secretAccessKey'] = config.secretAccessKey;
|
|
17
|
+
}
|
|
18
|
+
// AWS services are under credentials
|
|
19
|
+
else {
|
|
20
|
+
response['credentials'] = {
|
|
21
|
+
accessKeyId: config.accessKeyId,
|
|
22
|
+
secretAccessKey: config.secretAccessKey,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return response;
|
|
27
|
+
};
|
|
28
|
+
exports.default = getConfig;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var getConfig_1 = __importDefault(require("../getConfig"));
|
|
3
7
|
var glueClient = undefined;
|
|
4
8
|
/**
|
|
5
9
|
* Shorthand function to get the Glue Client.
|
|
@@ -9,13 +13,8 @@ var getClient = function (_a) {
|
|
|
9
13
|
var GlueLib = _a.GlueLib, config = _a.config;
|
|
10
14
|
if (!global.awsGlueClient) {
|
|
11
15
|
var GlueClient = GlueLib.GlueClient;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
accessKeyId: config.accessKeyId,
|
|
15
|
-
secretAccessKey: config.secretAccessKey,
|
|
16
|
-
},
|
|
17
|
-
region: config.region,
|
|
18
|
-
});
|
|
16
|
+
var formattedConfig = (0, getConfig_1.default)({ config: config, isAthenaExpress: false });
|
|
17
|
+
global.awsGlueClient = new GlueClient(formattedConfig);
|
|
19
18
|
}
|
|
20
19
|
glueClient = global.awsGlueClient;
|
|
21
20
|
return glueClient;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var getConfig_1 = __importDefault(require("../getConfig"));
|
|
3
7
|
var lambdaClient = undefined;
|
|
4
8
|
/**
|
|
5
9
|
* Shorthand function to get the Lambda Client.
|
|
@@ -9,13 +13,8 @@ var getClient = function (_a) {
|
|
|
9
13
|
var LambdaLib = _a.LambdaLib, config = _a.config;
|
|
10
14
|
if (!global.awsLambdaClient) {
|
|
11
15
|
var LambdaClient = LambdaLib.LambdaClient;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
accessKeyId: config.accessKeyId,
|
|
15
|
-
secretAccessKey: config.secretAccessKey,
|
|
16
|
-
},
|
|
17
|
-
region: config.region,
|
|
18
|
-
});
|
|
16
|
+
var formattedConfig = (0, getConfig_1.default)({ config: config, isAthenaExpress: false });
|
|
17
|
+
global.awsLambdaClient = new LambdaClient(formattedConfig);
|
|
19
18
|
}
|
|
20
19
|
lambdaClient = global.awsLambdaClient;
|
|
21
20
|
return lambdaClient;
|
package/dist/aws/s3/getClient.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var getConfig_1 = __importDefault(require("../getConfig"));
|
|
3
7
|
var s3Client = undefined;
|
|
4
8
|
/**
|
|
5
9
|
* Shorthand function to get the S3 Client.
|
|
@@ -9,13 +13,8 @@ var getClient = function (_a) {
|
|
|
9
13
|
var S3Lib = _a.S3Lib, config = _a.config;
|
|
10
14
|
if (!global.awsS3Client) {
|
|
11
15
|
var S3Client = S3Lib.S3Client;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
accessKeyId: config.accessKeyId,
|
|
15
|
-
secretAccessKey: config.secretAccessKey,
|
|
16
|
-
},
|
|
17
|
-
region: config.region,
|
|
18
|
-
});
|
|
16
|
+
var formattedConfig = (0, getConfig_1.default)({ config: config, isAthenaExpress: false });
|
|
17
|
+
global.awsS3Client = new S3Client(formattedConfig);
|
|
19
18
|
}
|
|
20
19
|
s3Client = global.awsS3Client;
|
|
21
20
|
return s3Client;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var getConfig_1 = __importDefault(require("../getConfig"));
|
|
3
7
|
var sesClient = undefined;
|
|
4
8
|
/**
|
|
5
9
|
* Shorthand function to get the SES Client.
|
|
@@ -9,13 +13,8 @@ var getClient = function (_a) {
|
|
|
9
13
|
var SesLib = _a.SesLib, config = _a.config;
|
|
10
14
|
if (!global.awsSesClient) {
|
|
11
15
|
var SESClient = SesLib.SESClient;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
accessKeyId: config.accessKeyId,
|
|
15
|
-
secretAccessKey: config.secretAccessKey,
|
|
16
|
-
},
|
|
17
|
-
region: config.region,
|
|
18
|
-
});
|
|
16
|
+
var formattedConfig = (0, getConfig_1.default)({ config: config, isAthenaExpress: false });
|
|
17
|
+
global.sesClient = new SESClient(formattedConfig);
|
|
19
18
|
}
|
|
20
19
|
sesClient = global.awsSesClient;
|
|
21
20
|
return sesClient;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var getConfig_1 = __importDefault(require("../getConfig"));
|
|
3
7
|
var ssmClient = undefined;
|
|
4
8
|
/**
|
|
5
9
|
* Shorthand function to get the Lambda Client.
|
|
@@ -9,13 +13,8 @@ var getClient = function (_a) {
|
|
|
9
13
|
var SsmLib = _a.SsmLib, config = _a.config;
|
|
10
14
|
if (!global.awsSsmClient) {
|
|
11
15
|
var SSMClient = SsmLib.SSMClient;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
accessKeyId: config.accessKeyId,
|
|
15
|
-
secretAccessKey: config.secretAccessKey,
|
|
16
|
-
},
|
|
17
|
-
region: config.region,
|
|
18
|
-
});
|
|
16
|
+
var formattedConfig = (0, getConfig_1.default)({ config: config, isAthenaExpress: false });
|
|
17
|
+
global.awsSsmClient = new SSMClient(formattedConfig);
|
|
19
18
|
}
|
|
20
19
|
ssmClient = global.awsSsmClient;
|
|
21
20
|
return ssmClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('getBoolean - True', function () {
|
|
5
|
+
expect((0, index_1.getBoolean)(true))
|
|
6
|
+
.toBeTruthy();
|
|
7
|
+
expect((0, index_1.getBoolean)(1))
|
|
8
|
+
.toBeTruthy();
|
|
9
|
+
expect((0, index_1.getBoolean)('1'))
|
|
10
|
+
.toBeTruthy();
|
|
11
|
+
});
|
|
12
|
+
test('getBoolean - False', function () {
|
|
13
|
+
expect((0, index_1.getBoolean)(false))
|
|
14
|
+
.toBeFalsy();
|
|
15
|
+
expect((0, index_1.getBoolean)(0))
|
|
16
|
+
.toBeFalsy();
|
|
17
|
+
expect((0, index_1.getBoolean)('0'))
|
|
18
|
+
.toBeFalsy();
|
|
19
|
+
});
|
|
20
|
+
test('getBoolean - Unexpected', function () {
|
|
21
|
+
expect((0, index_1.getBoolean)('test'))
|
|
22
|
+
.toBeFalsy();
|
|
23
|
+
});
|
package/dist/date/getMax.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { DateType } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* If a given date is beyond the maximum, return the maximum.
|
|
4
4
|
*/
|
|
5
|
-
declare const getMax: ({ input }: {
|
|
5
|
+
declare const getMax: ({ input, max }: {
|
|
6
6
|
input: DateType;
|
|
7
|
+
max: DateType;
|
|
7
8
|
}) => Date;
|
|
8
9
|
export default getMax;
|
package/dist/date/getMax.js
CHANGED
|
@@ -5,15 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var isAfter_1 = __importDefault(require("date-fns/isAfter"));
|
|
7
7
|
var getDate_1 = __importDefault(require("./getDate"));
|
|
8
|
-
var getYesterday_1 = __importDefault(require("./getYesterday"));
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
9
|
+
* If a given date is beyond the maximum, return the maximum.
|
|
11
10
|
*/
|
|
12
11
|
var getMax = function (_a) {
|
|
13
|
-
var input = _a.input;
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
return max;
|
|
12
|
+
var input = _a.input, max = _a.max;
|
|
13
|
+
var parsedMax = (0, getDate_1.default)({ input: max });
|
|
14
|
+
var parsedInput = (0, getDate_1.default)({ input: input });
|
|
15
|
+
return (0, isAfter_1.default)(parsedInput, parsedMax) ? parsedMax : parsedInput;
|
|
18
16
|
};
|
|
19
17
|
exports.default = getMax;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
var isBefore_1 = __importDefault(require("date-fns/isBefore"));
|
|
7
|
+
var getDate_1 = __importDefault(require("./getDate"));
|
|
8
|
+
/**
|
|
9
|
+
* If a given date is before the minimum, return the minimum.
|
|
10
|
+
*/
|
|
11
|
+
var getMin = function (_a) {
|
|
12
|
+
var input = _a.input, min = _a.min;
|
|
13
|
+
var parsedMin = (0, getDate_1.default)({ input: min });
|
|
14
|
+
var parsedInput = (0, getDate_1.default)({ input: input });
|
|
15
|
+
return (0, isBefore_1.default)(parsedInput, parsedMin) ? parsedMin : parsedInput;
|
|
16
|
+
};
|
|
17
|
+
exports.default = getMin;
|
package/dist/date/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import getFinancialYear from './getFinancialYear';
|
|
|
7
7
|
import getFinancialYearToDate from './getFinancialYearToDate';
|
|
8
8
|
import getLastWeek from './getLastWeek';
|
|
9
9
|
import getMax from './getMax';
|
|
10
|
+
import getMin from './getMin';
|
|
10
11
|
import getMonday from './getMonday';
|
|
11
12
|
import getNumber from './getNumber';
|
|
12
13
|
import getPredefinedTimeframe from './getPredefinedTimeframe';
|
|
@@ -21,4 +22,4 @@ import isThisWeek from './isThisWeek';
|
|
|
21
22
|
import parseExcelDate from './parseExcelDate';
|
|
22
23
|
import { DateType, FinancialYearType, FinancialYearWeekType, TimeframePredefinedType, TimeframeType } from './types';
|
|
23
24
|
export type { DateType, FinancialYearType, FinancialYearWeekType, TimeframeType, TimeframePredefinedType, };
|
|
24
|
-
export { Duration, DurationComparison, Timeframe, TimeframePredefined, format, getDate, getDurationHours, getDurationMinutes, getFinancialYear, getFinancialYearToDate, getLastWeek, getMax, getMonday, getNumber, getPredefinedTimeframe, getSunday, getThisWeek, getToday, getTwoWeeksAgo, getYesterday, isDateValid, isLastWeek, isThisWeek, parseExcelDate, };
|
|
25
|
+
export { Duration, DurationComparison, Timeframe, TimeframePredefined, format, getDate, getDurationHours, getDurationMinutes, getFinancialYear, getFinancialYearToDate, getLastWeek, getMax, getMin, getMonday, getNumber, getPredefinedTimeframe, getSunday, getThisWeek, getToday, getTwoWeeksAgo, getYesterday, isDateValid, isLastWeek, isThisWeek, parseExcelDate, };
|
package/dist/date/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseExcelDate = exports.isThisWeek = exports.isLastWeek = exports.isDateValid = exports.getYesterday = exports.getTwoWeeksAgo = exports.getToday = exports.getThisWeek = exports.getSunday = exports.getPredefinedTimeframe = exports.getNumber = exports.getMonday = exports.getMax = exports.getLastWeek = exports.getFinancialYearToDate = exports.getFinancialYear = exports.getDurationMinutes = exports.getDurationHours = exports.getDate = exports.format = exports.TimeframePredefined = exports.Timeframe = exports.DurationComparison = exports.Duration = void 0;
|
|
6
|
+
exports.parseExcelDate = exports.isThisWeek = exports.isLastWeek = exports.isDateValid = exports.getYesterday = exports.getTwoWeeksAgo = exports.getToday = exports.getThisWeek = exports.getSunday = exports.getPredefinedTimeframe = exports.getNumber = exports.getMonday = exports.getMin = exports.getMax = exports.getLastWeek = exports.getFinancialYearToDate = exports.getFinancialYear = exports.getDurationMinutes = exports.getDurationHours = exports.getDate = exports.format = exports.TimeframePredefined = exports.Timeframe = exports.DurationComparison = exports.Duration = void 0;
|
|
7
7
|
var constants_1 = require("./constants");
|
|
8
8
|
Object.defineProperty(exports, "Duration", { enumerable: true, get: function () { return constants_1.Duration; } });
|
|
9
9
|
Object.defineProperty(exports, "DurationComparison", { enumerable: true, get: function () { return constants_1.DurationComparison; } });
|
|
@@ -25,6 +25,8 @@ var getLastWeek_1 = __importDefault(require("./getLastWeek"));
|
|
|
25
25
|
exports.getLastWeek = getLastWeek_1.default;
|
|
26
26
|
var getMax_1 = __importDefault(require("./getMax"));
|
|
27
27
|
exports.getMax = getMax_1.default;
|
|
28
|
+
var getMin_1 = __importDefault(require("./getMin"));
|
|
29
|
+
exports.getMin = getMin_1.default;
|
|
28
30
|
var getMonday_1 = __importDefault(require("./getMonday"));
|
|
29
31
|
exports.getMonday = getMonday_1.default;
|
|
30
32
|
var getNumber_1 = __importDefault(require("./getNumber"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('format', function () {
|
|
5
|
+
var expected = '01/02/2021';
|
|
6
|
+
var dateFormat = 'dd/MM/yyyy';
|
|
7
|
+
var dateNumber = 20210201;
|
|
8
|
+
expect((0, index_1.format)({ input: dateNumber, dateFormat: dateFormat }))
|
|
9
|
+
.toBe(expected);
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('getDate', function () {
|
|
5
|
+
var expected = new Date('2021-02-01 00:00:00');
|
|
6
|
+
var parsed = (0, index_1.getDate)({ input: 20210201 });
|
|
7
|
+
expect(parsed)
|
|
8
|
+
.toMatchObject(expected);
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('getNumber', function () {
|
|
5
|
+
var expected = 20210201;
|
|
6
|
+
var parsed = (0, index_1.getNumber)({ input: new Date('2021-02-01 00:00:00') });
|
|
7
|
+
expect(parsed)
|
|
8
|
+
.toBe(expected);
|
|
9
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Get the user's remote IP Address
|
|
5
|
+
*/
|
|
6
|
+
var getIp = function (_a) {
|
|
7
|
+
var req = _a.req;
|
|
8
|
+
var response = 'unset';
|
|
9
|
+
if (undefined !== req.headers['x-real-ip']) {
|
|
10
|
+
response = String(req.headers['x-real-ip']);
|
|
11
|
+
}
|
|
12
|
+
return response;
|
|
13
|
+
};
|
|
14
|
+
exports.default = getIp;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Get the user's User Agent
|
|
5
|
+
*/
|
|
6
|
+
var getUserAgent = function (_a) {
|
|
7
|
+
var req = _a.req;
|
|
8
|
+
return req.headers['user-agent'] || 'unset';
|
|
9
|
+
};
|
|
10
|
+
exports.default = getUserAgent;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
exports.getUserAgent = exports.getIp = void 0;
|
|
7
|
+
var getIp_1 = __importDefault(require("./getIp"));
|
|
8
|
+
exports.getIp = getIp_1.default;
|
|
9
|
+
var getUserAgent_1 = __importDefault(require("./getUserAgent"));
|
|
10
|
+
exports.getUserAgent = getUserAgent_1.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('getIp - Exists', function () {
|
|
5
|
+
var request = {
|
|
6
|
+
headers: {
|
|
7
|
+
'x-real-ip': 'value',
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
expect((0, index_1.getIp)({ req: request }))
|
|
11
|
+
.toBe('value');
|
|
12
|
+
});
|
|
13
|
+
test('getIp - Undefined', function () {
|
|
14
|
+
var request = {
|
|
15
|
+
headers: {}
|
|
16
|
+
};
|
|
17
|
+
expect((0, index_1.getIp)({ req: request }))
|
|
18
|
+
.toBe('unset');
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('getUserAgent - Exists', function () {
|
|
5
|
+
var request = {
|
|
6
|
+
headers: {
|
|
7
|
+
'user-agent': 'value',
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
expect((0, index_1.getUserAgent)({ req: request }))
|
|
11
|
+
.toBe('value');
|
|
12
|
+
});
|
|
13
|
+
test('getUserAgent - Undefined', function () {
|
|
14
|
+
var request = {
|
|
15
|
+
headers: {},
|
|
16
|
+
};
|
|
17
|
+
expect((0, index_1.getUserAgent)({ req: request }))
|
|
18
|
+
.toBe('unset');
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('getCleanFolder', function () {
|
|
5
|
+
var input = ' /some-folder/ ';
|
|
6
|
+
var expected = '/some-folder/';
|
|
7
|
+
expect((0, index_1.getCleanFolder)(input))
|
|
8
|
+
.toBe(expected);
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('isAbsolute', function () {
|
|
5
|
+
var absolute = 'https://www.google.com';
|
|
6
|
+
var relative = '/something';
|
|
7
|
+
expect((0, index_1.isAbsolute)({ input: absolute }))
|
|
8
|
+
.toBeTruthy();
|
|
9
|
+
expect((0, index_1.isAbsolute)({ input: relative }))
|
|
10
|
+
.toBeFalsy();
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('isRelative', function () {
|
|
5
|
+
var absolute = 'https://www.google.com';
|
|
6
|
+
var relative = '/something';
|
|
7
|
+
expect((0, index_1.isRelative)({ input: absolute }))
|
|
8
|
+
.toBeFalsy();
|
|
9
|
+
expect((0, index_1.isRelative)({ input: relative }))
|
|
10
|
+
.toBeTruthy();
|
|
11
|
+
});
|
package/package.json
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name":
|
|
3
|
-
"version":
|
|
4
|
-
"repository":
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@8ms/helpers",
|
|
3
|
+
"version": "1.0.13",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
|
|
7
7
|
},
|
|
8
|
-
"main":
|
|
9
|
-
"types":
|
|
10
|
-
"files":
|
|
11
|
-
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/**/*"
|
|
12
12
|
],
|
|
13
|
-
"scripts":
|
|
14
|
-
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rimraf dist && tsc",
|
|
15
|
+
"jest": "jest --watch"
|
|
15
16
|
},
|
|
16
|
-
"dependencies":
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"axios": "0.25.0",
|
|
19
|
+
"date-fns": "2.28.0",
|
|
20
|
+
"lodash": "4.17.21"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
"@babel/preset-env": "7.16.11",
|
|
24
|
+
"@babel/preset-flow": "7.16.7",
|
|
25
|
+
"@babel/preset-typescript": "7.16.7",
|
|
26
|
+
"@types/jest": "27.4.0",
|
|
27
|
+
"@types/lodash": "4.14.178",
|
|
28
|
+
"@types/node": "17.0.14",
|
|
29
|
+
"babel-jest": "27.4.6",
|
|
30
|
+
"jest": "27.4.7",
|
|
31
|
+
"ts-node": "10.4.0",
|
|
32
|
+
"tslib": "2.3.1",
|
|
33
|
+
"typescript": "4.5.5"
|
|
26
34
|
}
|
|
27
35
|
}
|