store-scrapper-js-common 1.0.89 → 1.0.93
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/dto/index.d.ts +2 -1
- package/dist/dto/index.js +3 -1
- package/dist/dto/index.js.map +1 -1
- package/dist/dto/telegram-queue-command.dto.d.ts +14 -0
- package/dist/dto/telegram-queue-command.dto.js +7 -0
- package/dist/dto/telegram-queue-command.dto.js.map +1 -0
- package/dist/enums/index.d.ts +5 -1
- package/dist/enums/index.js +7 -1
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/telegram-client.enum.d.ts +4 -0
- package/dist/enums/telegram-client.enum.js +9 -0
- package/dist/enums/telegram-client.enum.js.map +1 -0
- package/dist/enums/telegram-message-type.d.ts +4 -0
- package/dist/enums/telegram-message-type.js +3 -0
- package/dist/enums/telegram-message-type.js.map +1 -0
- package/dist/enums/telegram-queue-command.enum.d.ts +3 -0
- package/dist/enums/telegram-queue-command.enum.js +8 -0
- package/dist/enums/telegram-queue-command.enum.js.map +1 -0
- package/dist/enums/telegram-queue.enum.d.ts +8 -0
- package/dist/enums/telegram-queue.enum.js +13 -0
- package/dist/enums/telegram-queue.enum.js.map +1 -0
- package/dist/utils/array-utils.d.ts +3 -0
- package/dist/utils/array-utils.js +22 -0
- package/dist/utils/array-utils.js.map +1 -0
- package/dist/utils/number-utils.d.ts +1 -0
- package/dist/utils/number-utils.js +8 -1
- package/dist/utils/number-utils.js.map +1 -1
- package/dist/utils/product.utils.d.ts +3 -0
- package/dist/utils/product.utils.js +16 -0
- package/dist/utils/product.utils.js.map +1 -0
- package/dist/utils/string-formatter.d.ts +4 -0
- package/dist/utils/string-formatter.js +64 -0
- package/dist/utils/string-formatter.js.map +1 -0
- package/package.json +2 -1
- package/src/dto/index.ts +2 -1
- package/src/dto/telegram-queue-command.dto.ts +19 -0
- package/src/enums/index.ts +7 -1
- package/src/enums/telegram-client.enum.ts +4 -0
- package/src/enums/telegram-message-type.ts +4 -0
- package/src/enums/telegram-queue-command.enum.ts +3 -0
- package/src/enums/telegram-queue.enum.ts +8 -0
- package/src/utils/array-utils.ts +23 -0
- package/src/utils/number-utils.ts +10 -0
- package/src/utils/product.utils.ts +18 -0
- package/src/utils/string-formatter.ts +49 -0
- package/tests/utils/array-utils.test.ts +34 -0
- package/tests/utils/product-utils.test.ts +21 -0
- package/tests/utils/string-formatter.test.ts +37 -0
package/dist/dto/index.d.ts
CHANGED
package/dist/dto/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProcessProductCategoryDto = void 0;
|
|
3
|
+
exports.TelegramQueueCommandDto = exports.ProcessProductCategoryDto = void 0;
|
|
4
4
|
const process_product_category_dto_1 = require("./process-product-category.dto");
|
|
5
5
|
Object.defineProperty(exports, "ProcessProductCategoryDto", { enumerable: true, get: function () { return process_product_category_dto_1.ProcessProductCategoryDto; } });
|
|
6
|
+
const telegram_queue_command_dto_1 = require("./telegram-queue-command.dto");
|
|
7
|
+
Object.defineProperty(exports, "TelegramQueueCommandDto", { enumerable: true, get: function () { return telegram_queue_command_dto_1.TelegramQueueCommandDto; } });
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/dist/dto/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["dto/index.ts"],"names":[],"mappings":";;;AAAA,iFAA2E;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["dto/index.ts"],"names":[],"mappings":";;;AAAA,iFAA2E;AAGlE,0GAHA,wDAAyB,OAGA;AAFlC,6EAAuE;AAEnC,wGAF3B,oDAAuB,OAE2B","sourcesContent":["import { ProcessProductCategoryDto } from './process-product-category.dto';\nimport { TelegramQueueCommandDto } from './telegram-queue-command.dto';\n\nexport { ProcessProductCategoryDto, TelegramQueueCommandDto };\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ObjectLiteral } from '../classes';
|
|
2
|
+
import { TelegramQueueCommandEnum } from '../enums/telegram-queue-command.enum';
|
|
3
|
+
import { TelegramMessageType } from '../enums/telegram-message-type';
|
|
4
|
+
export declare class TelegramQueueCommandDto {
|
|
5
|
+
message: string;
|
|
6
|
+
telegramChatId: string | number;
|
|
7
|
+
options?: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
namedJob?: TelegramQueueCommandEnum;
|
|
11
|
+
telegramClientId: string;
|
|
12
|
+
type?: TelegramMessageType;
|
|
13
|
+
imageOpts?: ObjectLiteral;
|
|
14
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelegramQueueCommandDto = void 0;
|
|
4
|
+
class TelegramQueueCommandDto {
|
|
5
|
+
}
|
|
6
|
+
exports.TelegramQueueCommandDto = TelegramQueueCommandDto;
|
|
7
|
+
//# sourceMappingURL=telegram-queue-command.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram-queue-command.dto.js","sourceRoot":"/","sources":["dto/telegram-queue-command.dto.ts"],"names":[],"mappings":";;;AAIA,MAAa,uBAAuB;CAcnC;AAdD,0DAcC","sourcesContent":["import { ObjectLiteral } from '../classes';\nimport { TelegramQueueCommandEnum } from '../enums/telegram-queue-command.enum';\nimport { TelegramMessageType } from '../enums/telegram-message-type';\n\nexport class TelegramQueueCommandDto {\n message: string;\n\n telegramChatId: string | number;\n\n options?: { [key: string]: any };\n\n namedJob?: TelegramQueueCommandEnum;\n\n telegramClientId: string;\n\n type?: TelegramMessageType;\n\n imageOpts?: ObjectLiteral;\n}\n"]}
|
package/dist/enums/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { RequestTypeEnum } from './request-type.enum';
|
|
2
|
-
|
|
2
|
+
import { TelegramClientEnum } from './telegram-client.enum';
|
|
3
|
+
import { TelegramMessageType } from './telegram-message-type';
|
|
4
|
+
import { TelegramQueueCommandEnum } from './telegram-queue-command.enum';
|
|
5
|
+
import { TelegramQueueEnum } from './telegram-queue.enum';
|
|
6
|
+
export { RequestTypeEnum, TelegramClientEnum, TelegramQueueEnum, TelegramQueueCommandEnum, TelegramMessageType, };
|
package/dist/enums/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequestTypeEnum = void 0;
|
|
3
|
+
exports.TelegramQueueCommandEnum = exports.TelegramQueueEnum = exports.TelegramClientEnum = exports.RequestTypeEnum = void 0;
|
|
4
4
|
const request_type_enum_1 = require("./request-type.enum");
|
|
5
5
|
Object.defineProperty(exports, "RequestTypeEnum", { enumerable: true, get: function () { return request_type_enum_1.RequestTypeEnum; } });
|
|
6
|
+
const telegram_client_enum_1 = require("./telegram-client.enum");
|
|
7
|
+
Object.defineProperty(exports, "TelegramClientEnum", { enumerable: true, get: function () { return telegram_client_enum_1.TelegramClientEnum; } });
|
|
8
|
+
const telegram_queue_command_enum_1 = require("./telegram-queue-command.enum");
|
|
9
|
+
Object.defineProperty(exports, "TelegramQueueCommandEnum", { enumerable: true, get: function () { return telegram_queue_command_enum_1.TelegramQueueCommandEnum; } });
|
|
10
|
+
const telegram_queue_enum_1 = require("./telegram-queue.enum");
|
|
11
|
+
Object.defineProperty(exports, "TelegramQueueEnum", { enumerable: true, get: function () { return telegram_queue_enum_1.TelegramQueueEnum; } });
|
|
6
12
|
//# sourceMappingURL=index.js.map
|
package/dist/enums/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["enums/index.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["enums/index.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAOpD,gGAPO,mCAAe,OAOP;AANjB,iEAA4D;AAMzC,mGANV,yCAAkB,OAMU;AAJrC,+EAAyE;AAIf,yGAJjD,sDAAwB,OAIiD;AAHlF,+DAA0D;AAGnB,kGAH9B,uCAAiB,OAG8B","sourcesContent":["import { RequestTypeEnum } from './request-type.enum';\nimport { TelegramClientEnum } from './telegram-client.enum';\nimport { TelegramMessageType } from './telegram-message-type';\nimport { TelegramQueueCommandEnum } from './telegram-queue-command.enum';\nimport { TelegramQueueEnum } from './telegram-queue.enum';\n\nexport {\n RequestTypeEnum, TelegramClientEnum, TelegramQueueEnum, TelegramQueueCommandEnum, TelegramMessageType,\n};\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelegramClientEnum = void 0;
|
|
4
|
+
var TelegramClientEnum;
|
|
5
|
+
(function (TelegramClientEnum) {
|
|
6
|
+
TelegramClientEnum["SEND_ALERT_MESSAGE"] = "send_alert_message";
|
|
7
|
+
TelegramClientEnum["SEND_ALERT_MESSAGE_PUBLIC"] = "send_alert_message_public";
|
|
8
|
+
})(TelegramClientEnum = exports.TelegramClientEnum || (exports.TelegramClientEnum = {}));
|
|
9
|
+
//# sourceMappingURL=telegram-client.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram-client.enum.js","sourceRoot":"/","sources":["enums/telegram-client.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+DAAyC,CAAA;IACzC,6EAAuD,CAAA;AACzD,CAAC,EAHW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAG7B","sourcesContent":["export enum TelegramClientEnum {\n SEND_ALERT_MESSAGE = 'send_alert_message',\n SEND_ALERT_MESSAGE_PUBLIC = 'send_alert_message_public',\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram-message-type.js","sourceRoot":"/","sources":["enums/telegram-message-type.ts"],"names":[],"mappings":"","sourcesContent":["export const enum TelegramMessageType {\n MESSAGE = 'message',\n IMAGE = 'image',\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelegramQueueCommandEnum = void 0;
|
|
4
|
+
var TelegramQueueCommandEnum;
|
|
5
|
+
(function (TelegramQueueCommandEnum) {
|
|
6
|
+
TelegramQueueCommandEnum["SEND_MESSAGE"] = "send_message";
|
|
7
|
+
})(TelegramQueueCommandEnum = exports.TelegramQueueCommandEnum || (exports.TelegramQueueCommandEnum = {}));
|
|
8
|
+
//# sourceMappingURL=telegram-queue-command.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram-queue-command.enum.js","sourceRoot":"/","sources":["enums/telegram-queue-command.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,wBAEX;AAFD,WAAY,wBAAwB;IAClC,yDAA6B,CAAA;AAC/B,CAAC,EAFW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAEnC","sourcesContent":["export enum TelegramQueueCommandEnum {\n SEND_MESSAGE = 'send_message',\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare enum TelegramQueueEnum {
|
|
2
|
+
TELEGRAM_ALERT = "telegram_alert",
|
|
3
|
+
TELEGRAM_ALERT_PUBLIC_1 = "telegram_alert_public",
|
|
4
|
+
TELEGRAM_ALERT_PUBLIC_2 = "telegram_alert_public_non_vip",
|
|
5
|
+
TELEGRAM_ALERT_PUBLIC_3 = "telegram_alert_public_non_vip_60",
|
|
6
|
+
TELEGRAM_ALERT_PUBLIC_4 = "telegram_alert_public_60",
|
|
7
|
+
TELEGRAM_STOCK_ALERT_PUBLIC = "telegram_stock_alert_public"
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelegramQueueEnum = void 0;
|
|
4
|
+
var TelegramQueueEnum;
|
|
5
|
+
(function (TelegramQueueEnum) {
|
|
6
|
+
TelegramQueueEnum["TELEGRAM_ALERT"] = "telegram_alert";
|
|
7
|
+
TelegramQueueEnum["TELEGRAM_ALERT_PUBLIC_1"] = "telegram_alert_public";
|
|
8
|
+
TelegramQueueEnum["TELEGRAM_ALERT_PUBLIC_2"] = "telegram_alert_public_non_vip";
|
|
9
|
+
TelegramQueueEnum["TELEGRAM_ALERT_PUBLIC_3"] = "telegram_alert_public_non_vip_60";
|
|
10
|
+
TelegramQueueEnum["TELEGRAM_ALERT_PUBLIC_4"] = "telegram_alert_public_60";
|
|
11
|
+
TelegramQueueEnum["TELEGRAM_STOCK_ALERT_PUBLIC"] = "telegram_stock_alert_public";
|
|
12
|
+
})(TelegramQueueEnum = exports.TelegramQueueEnum || (exports.TelegramQueueEnum = {}));
|
|
13
|
+
//# sourceMappingURL=telegram-queue.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram-queue.enum.js","sourceRoot":"/","sources":["enums/telegram-queue.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAOX;AAPD,WAAY,iBAAiB;IAC3B,sDAAiC,CAAA;IACjC,sEAAiD,CAAA;IACjD,8EAAyD,CAAA;IACzD,iFAA4D,CAAA;IAC5D,yEAAoD,CAAA;IACpD,gFAA2D,CAAA;AAC7D,CAAC,EAPW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAO5B","sourcesContent":["export enum TelegramQueueEnum {\n TELEGRAM_ALERT = 'telegram_alert',\n TELEGRAM_ALERT_PUBLIC_1 = 'telegram_alert_public',\n TELEGRAM_ALERT_PUBLIC_2 = 'telegram_alert_public_non_vip',\n TELEGRAM_ALERT_PUBLIC_3 = 'telegram_alert_public_non_vip_60',\n TELEGRAM_ALERT_PUBLIC_4 = 'telegram_alert_public_60',\n TELEGRAM_STOCK_ALERT_PUBLIC = 'telegram_stock_alert_public',\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringToArray = exports.hasElementInArray = exports.isArrayEmpty = void 0;
|
|
4
|
+
exports.isArrayEmpty = (arr) => {
|
|
5
|
+
if (arr && !Array.isArray(arr)) {
|
|
6
|
+
throw Error('Element is not an array');
|
|
7
|
+
}
|
|
8
|
+
return !arr || arr.length === 0;
|
|
9
|
+
};
|
|
10
|
+
exports.hasElementInArray = (elements, searchElements) => {
|
|
11
|
+
if (exports.isArrayEmpty(elements) || exports.isArrayEmpty(searchElements)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return elements.some((updateReason) => searchElements.some((searchUpdateReason) => updateReason === searchUpdateReason));
|
|
15
|
+
};
|
|
16
|
+
exports.stringToArray = (str, splitBy = ',') => {
|
|
17
|
+
if (!str) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return str.split(splitBy).filter((e) => e);
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=array-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-utils.js","sourceRoot":"/","sources":["utils/array-utils.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,CAAI,GAAQ,EAAW,EAAE;IACnD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC9B,MAAM,KAAK,CAAC,yBAAyB,CAAC,CAAC;KACxC;IAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC;AAClC,CAAC,CAAC;AAEW,QAAA,iBAAiB,GAAG,CAAI,QAAa,EAAE,cAAmB,EAAW,EAAE;IAClF,IAAI,oBAAY,CAAC,QAAQ,CAAC,IAAI,oBAAY,CAAC,cAAc,CAAC,EAAE;QAC1D,OAAO,KAAK,CAAC;KACd;IAED,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,kBAAkB,EAAE,EAAE,CAAC,YAAY,KAAK,kBAAkB,CAAC,CAAC,CAAC;AAC3H,CAAC,CAAC;AAEW,QAAA,aAAa,GAAG,CAAC,GAAW,EAAE,OAAO,GAAG,GAAG,EAAY,EAAE;IACpE,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,IAAI,CAAC;KACb;IAED,OAAO,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7C,CAAC,CAAC","sourcesContent":["export const isArrayEmpty = <T>(arr: T[]): boolean => {\n if (arr && !Array.isArray(arr)) {\n throw Error('Element is not an array');\n }\n\n return !arr || arr.length === 0;\n};\n\nexport const hasElementInArray = <T>(elements: T[], searchElements: T[]): boolean => {\n if (isArrayEmpty(elements) || isArrayEmpty(searchElements)) {\n return false;\n }\n\n return elements.some((updateReason) => searchElements.some((searchUpdateReason) => updateReason === searchUpdateReason));\n};\n\nexport const stringToArray = (str: string, splitBy = ','): string[] => {\n if (!str) {\n return null;\n }\n\n return str.split(splitBy).filter((e) => e);\n};\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.roundNumber = exports.calculateAverage = void 0;
|
|
3
|
+
exports.getPercentageDiff = exports.roundNumber = exports.calculateAverage = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
4
5
|
exports.calculateAverage = (sum, quantity) => {
|
|
5
6
|
if (!sum || !quantity) {
|
|
6
7
|
return null;
|
|
@@ -22,4 +23,10 @@ exports.roundNumber = (nmb, decimals) => {
|
|
|
22
23
|
}
|
|
23
24
|
return Number(nmb.toFixed(decimals));
|
|
24
25
|
};
|
|
26
|
+
exports.getPercentageDiff = (minPrice, compareToPrice) => {
|
|
27
|
+
if (lodash_1.isNumber(minPrice) && lodash_1.isNumber(compareToPrice)) {
|
|
28
|
+
return exports.roundNumber(100 - (minPrice * 100) / compareToPrice, 2);
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
25
32
|
//# sourceMappingURL=number-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-utils.js","sourceRoot":"/","sources":["utils/number-utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"number-utils.js","sourceRoot":"/","sources":["utils/number-utils.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAErB,QAAA,gBAAgB,GAAG,CAAC,GAAW,EAAE,QAAgB,EAAU,EAAE;IACxE,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE;QACrB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,GAAG,KAAK,CAAC,IAAI,QAAQ,KAAK,CAAC,EAAE;QAC/B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,GAAG,GAAG,QAAQ,CAAC;AACxB,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,CAAC,GAAW,EAAE,QAAiB,EAAU,EAAE;IACpE,IAAI,GAAG,KAAK,CAAC,EAAE;QACb,OAAO,GAAG,CAAC;KACZ;IAED,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,IAAI,CAAC;KACb;IAED,IAAI,CAAC,QAAQ,IAAI,QAAQ,GAAG,CAAC,EAAE;QAC7B,OAAO,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;KAC/B;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AACvC,CAAC,CAAC;AAEW,QAAA,iBAAiB,GAAG,CAAC,QAAgB,EAAE,cAAsB,EAAU,EAAE;IACpF,IAAI,iBAAQ,CAAC,QAAQ,CAAC,IAAI,iBAAQ,CAAC,cAAc,CAAC,EAAE;QAClD,OAAO,mBAAW,CAAC,GAAG,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,GAAG,cAAc,EAAE,CAAC,CAAC,CAAC;KAChE;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["import { isNumber } from 'lodash';\n\nexport const calculateAverage = (sum: number, quantity: number): number => {\n if (!sum || !quantity) {\n return null;\n }\n\n if (sum === 0 || quantity === 0) {\n return null;\n }\n\n return sum / quantity;\n};\n\nexport const roundNumber = (nmb: number, decimals?: number): number => {\n if (nmb === 0) {\n return nmb;\n }\n\n if (!nmb) {\n return null;\n }\n\n if (!decimals || decimals < 0) {\n return Number(nmb.toFixed(0));\n }\n\n return Number(nmb.toFixed(decimals));\n};\n\nexport const getPercentageDiff = (minPrice: number, compareToPrice: number): number => {\n if (isNumber(minPrice) && isNumber(compareToPrice)) {\n return roundNumber(100 - (minPrice * 100) / compareToPrice, 2);\n }\n\n return null;\n};\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasUpdateReason = exports.getStoreName = void 0;
|
|
4
|
+
const array_utils_1 = require("./array-utils");
|
|
5
|
+
exports.getStoreName = (product, stores) => {
|
|
6
|
+
if ((!stores || stores.length === 0) && product) {
|
|
7
|
+
return product.storeName;
|
|
8
|
+
}
|
|
9
|
+
const store = stores.find((storeElement) => storeElement._id.toString() === product.storeRef);
|
|
10
|
+
if (store) {
|
|
11
|
+
return store.displayName || store.name;
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
exports.hasUpdateReason = (enums, search) => array_utils_1.hasElementInArray(enums, search);
|
|
16
|
+
//# sourceMappingURL=product.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.utils.js","sourceRoot":"/","sources":["utils/product.utils.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAGrC,QAAA,YAAY,GAAG,CAAC,OAAgB,EAAE,MAAe,EAAU,EAAE;IACxE,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,IAAI,OAAO,EAAE;QAC/C,OAAO,OAAO,CAAC,SAAS,CAAC;KAC1B;IAGD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9F,IAAI,KAAK,EAAE;QACT,OAAO,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC;KACxC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEW,QAAA,eAAe,GAAG,CAAC,KAAyB,EAAE,MAA0B,EAAW,EAAE,CAAC,+BAAiB,CAAmB,KAAK,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { hasElementInArray } from './array-utils';\nimport { Product, Store, UpdateReasonEnum } from '../entities';\n\nexport const getStoreName = (product: Product, stores: Store[]): string => {\n if ((!stores || stores.length === 0) && product) {\n return product.storeName;\n }\n\n // eslint-disable-next-line no-underscore-dangle\n const store = stores.find((storeElement) => storeElement._id.toString() === product.storeRef);\n if (store) {\n return store.displayName || store.name;\n }\n\n return null;\n};\n\nexport const hasUpdateReason = (enums: UpdateReasonEnum[], search: UpdateReasonEnum[]): boolean => hasElementInArray<UpdateReasonEnum>(enums, search);\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.formatPct = exports.formatDate = exports.formatMoney = void 0;
|
|
23
|
+
const moment = __importStar(require("moment-timezone"));
|
|
24
|
+
const entities_1 = require("../entities");
|
|
25
|
+
const addThousandSeparator = (str) => {
|
|
26
|
+
const nStr = (`${str}`);
|
|
27
|
+
const x = nStr.split('.');
|
|
28
|
+
let x1 = x[0];
|
|
29
|
+
const x2 = x.length > 1 ? `.${x[1]}` : '';
|
|
30
|
+
const rgx = /(\d+)(\d{3})/;
|
|
31
|
+
while (rgx.test(x1)) {
|
|
32
|
+
x1 = x1.replace(rgx, '$1.$2');
|
|
33
|
+
}
|
|
34
|
+
return x1 + x2;
|
|
35
|
+
};
|
|
36
|
+
exports.formatMoney = (money, currency) => {
|
|
37
|
+
if (!money) {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
let prependSign = '';
|
|
41
|
+
if (!currency || !currency.toLowerCase().includes('pts')) {
|
|
42
|
+
if (currency === entities_1.CurrencyEnum.USD) {
|
|
43
|
+
prependSign = 'U$';
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
prependSign = '$';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';
|
|
50
|
+
return prependSign + addThousandSeparator(money.toString()) + appendSign;
|
|
51
|
+
};
|
|
52
|
+
exports.formatDate = (str) => {
|
|
53
|
+
if (!str) {
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
return moment.tz(new Date(str), 'America/Santiago').format('DD-MM-YYYY HH:mm:ss');
|
|
57
|
+
};
|
|
58
|
+
exports.formatPct = (pct) => {
|
|
59
|
+
if (!pct) {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
return `${pct}%`.replace('.', ',');
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=string-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-formatter.js","sourceRoot":"/","sources":["utils/string-formatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,0CAA2C;AAE3C,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAE,EAAE;IAC3C,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACxB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACd,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1C,MAAM,GAAG,GAAG,cAAc,CAAC;IAC3B,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;QACnB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KAC/B;IACD,OAAO,EAAE,GAAG,EAAE,CAAC;AACjB,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,CAAC,KAAsB,EAAE,QAAuB,EAAU,EAAE;IACrF,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,EAAE,CAAC;KACX;IAED,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACxD,IAAI,QAAQ,KAAK,uBAAY,CAAC,GAAG,EAAE;YACjC,WAAW,GAAG,IAAI,CAAC;SACpB;aAAM;YACL,WAAW,GAAG,GAAG,CAAC;SACnB;KACF;IAED,MAAM,UAAU,GAAG,QAAQ,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAEtF,OAAO,WAAW,GAAG,oBAAoB,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,UAAU,CAAC;AAC3E,CAAC,CAAC;AAEW,QAAA,UAAU,GAAG,CAAC,GAAW,EAAU,EAAE;IAChD,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,EAAE,CAAC;KACX;IAED,OAAO,MAAM,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,kBAAkB,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpF,CAAC,CAAC;AAEW,QAAA,SAAS,GAAG,CAAC,GAAoB,EAAU,EAAE;IACxD,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,EAAE,CAAC;KACX;IAED,OAAO,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import * as moment from 'moment-timezone';\nimport { CurrencyEnum } from '../entities';\n\nconst addThousandSeparator = (str: string) => {\n const nStr = (`${str}`);\n const x = nStr.split('.');\n let x1 = x[0];\n const x2 = x.length > 1 ? `.${x[1]}` : '';\n const rgx = /(\\d+)(\\d{3})/;\n while (rgx.test(x1)) {\n x1 = x1.replace(rgx, '$1.$2');\n }\n return x1 + x2;\n};\n\nexport const formatMoney = (money: number | string, currency?: CurrencyEnum): string => {\n if (!money) {\n return '';\n }\n\n let prependSign = '';\n if (!currency || !currency.toLowerCase().includes('pts')) {\n if (currency === CurrencyEnum.USD) {\n prependSign = 'U$';\n } else {\n prependSign = '$';\n }\n }\n\n const appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';\n\n return prependSign + addThousandSeparator(money.toString()) + appendSign;\n};\n\nexport const formatDate = (str: string): string => {\n if (!str) {\n return '';\n }\n\n return moment.tz(new Date(str), 'America/Santiago').format('DD-MM-YYYY HH:mm:ss');\n};\n\nexport const formatPct = (pct: number | string): string => {\n if (!pct) {\n return '';\n }\n\n return `${pct}%`.replace('.', ',');\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "store-scrapper-js-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.93",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"class-validator": "^0.12.2",
|
|
20
20
|
"lodash": "^4.17.20",
|
|
21
|
+
"moment-timezone": "^0.5.34",
|
|
21
22
|
"rimraf": "^3.0.2",
|
|
22
23
|
"typeorm": "^0.2.28"
|
|
23
24
|
},
|
package/src/dto/index.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ObjectLiteral } from '../classes';
|
|
2
|
+
import { TelegramQueueCommandEnum } from '../enums/telegram-queue-command.enum';
|
|
3
|
+
import { TelegramMessageType } from '../enums/telegram-message-type';
|
|
4
|
+
|
|
5
|
+
export class TelegramQueueCommandDto {
|
|
6
|
+
message: string;
|
|
7
|
+
|
|
8
|
+
telegramChatId: string | number;
|
|
9
|
+
|
|
10
|
+
options?: { [key: string]: any };
|
|
11
|
+
|
|
12
|
+
namedJob?: TelegramQueueCommandEnum;
|
|
13
|
+
|
|
14
|
+
telegramClientId: string;
|
|
15
|
+
|
|
16
|
+
type?: TelegramMessageType;
|
|
17
|
+
|
|
18
|
+
imageOpts?: ObjectLiteral;
|
|
19
|
+
}
|
package/src/enums/index.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { RequestTypeEnum } from './request-type.enum';
|
|
2
|
+
import { TelegramClientEnum } from './telegram-client.enum';
|
|
3
|
+
import { TelegramMessageType } from './telegram-message-type';
|
|
4
|
+
import { TelegramQueueCommandEnum } from './telegram-queue-command.enum';
|
|
5
|
+
import { TelegramQueueEnum } from './telegram-queue.enum';
|
|
2
6
|
|
|
3
|
-
export {
|
|
7
|
+
export {
|
|
8
|
+
RequestTypeEnum, TelegramClientEnum, TelegramQueueEnum, TelegramQueueCommandEnum, TelegramMessageType,
|
|
9
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export enum TelegramQueueEnum {
|
|
2
|
+
TELEGRAM_ALERT = 'telegram_alert',
|
|
3
|
+
TELEGRAM_ALERT_PUBLIC_1 = 'telegram_alert_public',
|
|
4
|
+
TELEGRAM_ALERT_PUBLIC_2 = 'telegram_alert_public_non_vip',
|
|
5
|
+
TELEGRAM_ALERT_PUBLIC_3 = 'telegram_alert_public_non_vip_60',
|
|
6
|
+
TELEGRAM_ALERT_PUBLIC_4 = 'telegram_alert_public_60',
|
|
7
|
+
TELEGRAM_STOCK_ALERT_PUBLIC = 'telegram_stock_alert_public',
|
|
8
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const isArrayEmpty = <T>(arr: T[]): boolean => {
|
|
2
|
+
if (arr && !Array.isArray(arr)) {
|
|
3
|
+
throw Error('Element is not an array');
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return !arr || arr.length === 0;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const hasElementInArray = <T>(elements: T[], searchElements: T[]): boolean => {
|
|
10
|
+
if (isArrayEmpty(elements) || isArrayEmpty(searchElements)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return elements.some((updateReason) => searchElements.some((searchUpdateReason) => updateReason === searchUpdateReason));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const stringToArray = (str: string, splitBy = ','): string[] => {
|
|
18
|
+
if (!str) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return str.split(splitBy).filter((e) => e);
|
|
23
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isNumber } from 'lodash';
|
|
2
|
+
|
|
1
3
|
export const calculateAverage = (sum: number, quantity: number): number => {
|
|
2
4
|
if (!sum || !quantity) {
|
|
3
5
|
return null;
|
|
@@ -25,3 +27,11 @@ export const roundNumber = (nmb: number, decimals?: number): number => {
|
|
|
25
27
|
|
|
26
28
|
return Number(nmb.toFixed(decimals));
|
|
27
29
|
};
|
|
30
|
+
|
|
31
|
+
export const getPercentageDiff = (minPrice: number, compareToPrice: number): number => {
|
|
32
|
+
if (isNumber(minPrice) && isNumber(compareToPrice)) {
|
|
33
|
+
return roundNumber(100 - (minPrice * 100) / compareToPrice, 2);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { hasElementInArray } from './array-utils';
|
|
2
|
+
import { Product, Store, UpdateReasonEnum } from '../entities';
|
|
3
|
+
|
|
4
|
+
export const getStoreName = (product: Product, stores: Store[]): string => {
|
|
5
|
+
if ((!stores || stores.length === 0) && product) {
|
|
6
|
+
return product.storeName;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
10
|
+
const store = stores.find((storeElement) => storeElement._id.toString() === product.storeRef);
|
|
11
|
+
if (store) {
|
|
12
|
+
return store.displayName || store.name;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const hasUpdateReason = (enums: UpdateReasonEnum[], search: UpdateReasonEnum[]): boolean => hasElementInArray<UpdateReasonEnum>(enums, search);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as moment from 'moment-timezone';
|
|
2
|
+
import { CurrencyEnum } from '../entities';
|
|
3
|
+
|
|
4
|
+
const addThousandSeparator = (str: string) => {
|
|
5
|
+
const nStr = (`${str}`);
|
|
6
|
+
const x = nStr.split('.');
|
|
7
|
+
let x1 = x[0];
|
|
8
|
+
const x2 = x.length > 1 ? `.${x[1]}` : '';
|
|
9
|
+
const rgx = /(\d+)(\d{3})/;
|
|
10
|
+
while (rgx.test(x1)) {
|
|
11
|
+
x1 = x1.replace(rgx, '$1.$2');
|
|
12
|
+
}
|
|
13
|
+
return x1 + x2;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const formatMoney = (money: number | string, currency?: CurrencyEnum): string => {
|
|
17
|
+
if (!money) {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let prependSign = '';
|
|
22
|
+
if (!currency || !currency.toLowerCase().includes('pts')) {
|
|
23
|
+
if (currency === CurrencyEnum.USD) {
|
|
24
|
+
prependSign = 'U$';
|
|
25
|
+
} else {
|
|
26
|
+
prependSign = '$';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const appendSign = currency && currency.toLowerCase().includes('pts') ? ' (pts)' : '';
|
|
31
|
+
|
|
32
|
+
return prependSign + addThousandSeparator(money.toString()) + appendSign;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const formatDate = (str: string): string => {
|
|
36
|
+
if (!str) {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return moment.tz(new Date(str), 'America/Santiago').format('DD-MM-YYYY HH:mm:ss');
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const formatPct = (pct: number | string): string => {
|
|
44
|
+
if (!pct) {
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return `${pct}%`.replace('.', ',');
|
|
49
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { hasElementInArray, isArrayEmpty, stringToArray } from '../../src/utils/array-utils';
|
|
2
|
+
|
|
3
|
+
describe('array utils test', () => {
|
|
4
|
+
it('should return true if array contains elements', () => {
|
|
5
|
+
expect.hasAssertions();
|
|
6
|
+
|
|
7
|
+
expect(isArrayEmpty(null)).toStrictEqual(true);
|
|
8
|
+
expect(isArrayEmpty([])).toStrictEqual(true);
|
|
9
|
+
|
|
10
|
+
expect(isArrayEmpty([1])).toStrictEqual(false);
|
|
11
|
+
expect(isArrayEmpty(['a', 'b'])).toStrictEqual(false);
|
|
12
|
+
expect(isArrayEmpty([{}])).toStrictEqual(false);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should return true if array contains search elements', () => {
|
|
16
|
+
expect.hasAssertions();
|
|
17
|
+
|
|
18
|
+
expect(hasElementInArray([], [])).toStrictEqual(false);
|
|
19
|
+
expect(hasElementInArray<string>(['a', 'b'], ['c'])).toStrictEqual(false);
|
|
20
|
+
|
|
21
|
+
expect(hasElementInArray<string>(['a', 'b', 'c'], ['c'])).toStrictEqual(true);
|
|
22
|
+
expect(hasElementInArray<number>([1, 2, 3], [2])).toStrictEqual(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should return string split if not empty', () => {
|
|
26
|
+
expect.hasAssertions();
|
|
27
|
+
|
|
28
|
+
expect(stringToArray('', ',')).toBeNull();
|
|
29
|
+
expect(stringToArray(null, ',')).toBeNull();
|
|
30
|
+
|
|
31
|
+
expect(stringToArray('abc', ',')).toStrictEqual(['abc']);
|
|
32
|
+
expect(stringToArray('a,b,c,d,', ',')).toStrictEqual(['a', 'b', 'c', 'd']);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { hasUpdateReason } from '../../src/utils/product.utils';
|
|
2
|
+
import { UpdateReasonEnum } from '../../src';
|
|
3
|
+
|
|
4
|
+
describe('product utils spec', () => {
|
|
5
|
+
it('should return true if product update reason contains search element', () => {
|
|
6
|
+
expect.hasAssertions();
|
|
7
|
+
|
|
8
|
+
expect(hasUpdateReason([UpdateReasonEnum.TIME], [])).toStrictEqual(false);
|
|
9
|
+
expect(hasUpdateReason([], [UpdateReasonEnum.NEW_STOCK])).toStrictEqual(false);
|
|
10
|
+
expect(
|
|
11
|
+
hasUpdateReason([UpdateReasonEnum.TIME, UpdateReasonEnum.MISSING_DATA], [UpdateReasonEnum.NEW_STOCK]),
|
|
12
|
+
).toStrictEqual(false);
|
|
13
|
+
|
|
14
|
+
expect(
|
|
15
|
+
hasUpdateReason(
|
|
16
|
+
[UpdateReasonEnum.TIME, UpdateReasonEnum.NEW_STOCK, UpdateReasonEnum.RE_LISTING],
|
|
17
|
+
[UpdateReasonEnum.NEW_STOCK],
|
|
18
|
+
),
|
|
19
|
+
).toStrictEqual(true);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { formatDate, formatMoney, formatPct } from '../../src/utils/string-formatter';
|
|
2
|
+
import { CurrencyEnum } from '../../src/entities';
|
|
3
|
+
|
|
4
|
+
describe('string formatter', () => {
|
|
5
|
+
it('should return number as a formatted CLP Money Currency', () => {
|
|
6
|
+
expect.hasAssertions();
|
|
7
|
+
|
|
8
|
+
expect(formatMoney(null)).toStrictEqual('');
|
|
9
|
+
expect(formatMoney(100)).toStrictEqual('$100');
|
|
10
|
+
expect(formatMoney(1000)).toStrictEqual('$1.000');
|
|
11
|
+
expect(formatMoney(10000)).toStrictEqual('$10.000');
|
|
12
|
+
expect(formatMoney(100000)).toStrictEqual('$100.000');
|
|
13
|
+
expect(formatMoney(1000000)).toStrictEqual('$1.000.000');
|
|
14
|
+
|
|
15
|
+
expect(formatMoney(1000, CurrencyEnum.CMR_PTS)).toStrictEqual('1.000 (pts)');
|
|
16
|
+
expect(formatMoney(1000000, CurrencyEnum.CMR_PTS)).toStrictEqual('1.000.000 (pts)');
|
|
17
|
+
|
|
18
|
+
expect(formatMoney(1000, CurrencyEnum.USD)).toStrictEqual('U$1.000');
|
|
19
|
+
expect(formatMoney(1000000, CurrencyEnum.USD)).toStrictEqual('U$1.000.000');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should return date as a formatted CLP Date', () => {
|
|
23
|
+
expect.hasAssertions();
|
|
24
|
+
|
|
25
|
+
const date = '2021-01-16T21:35:15.945Z';
|
|
26
|
+
|
|
27
|
+
expect(formatDate(null)).toStrictEqual('');
|
|
28
|
+
expect(formatDate(date)).toStrictEqual('16-01-2021 18:35:15');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should return number as a percentage string', () => {
|
|
32
|
+
expect.hasAssertions();
|
|
33
|
+
|
|
34
|
+
expect(formatPct(10)).toStrictEqual('10%');
|
|
35
|
+
expect(formatPct(10.2)).toStrictEqual('10,2%');
|
|
36
|
+
});
|
|
37
|
+
});
|