@zeesoft/i18n-verify 1.0.0
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/driver/adapters/cypress.js +160 -0
- package/dist/driver/adapters/nightwatch.js +95 -0
- package/dist/driver/adapters/selenium.js +94 -0
- package/dist/driver/adapters/webdriver.io.js +81 -0
- package/dist/driver/baseDriver.js +69 -0
- package/dist/driver/factory.js +27 -0
- package/dist/index.js +47 -0
- package/dist/lib/config.js +99 -0
- package/dist/lib/i18n.js +177 -0
- package/dist/lib/validator/base.js +125 -0
- package/dist/lib/validator/currency.js +94 -0
- package/dist/lib/validator/date.js +72 -0
- package/dist/lib/validator/datetime.js +72 -0
- package/dist/lib/validator/index.js +156 -0
- package/dist/lib/validator/number.js +58 -0
- package/dist/lib/validator/percentage.js +78 -0
- package/dist/lib/validator/string.js +172 -0
- package/dist/lib/validator/time.js +72 -0
- package/dist/utils/2Dgraphic.js +57 -0
- package/dist/utils/cache.js +47 -0
- package/dist/utils/common.js +18 -0
- package/dist/utils/configFile.js +64 -0
- package/dist/utils/constants.js +145 -0
- package/dist/utils/cypress.js +120 -0
- package/dist/utils/dateUtils/chronoNode.js +52 -0
- package/dist/utils/file.js +57 -0
- package/dist/utils/logs.js +61 -0
- package/dist/utils/objects/cacheData.js +91 -0
- package/dist/utils/objects/metaData.js +48 -0
- package/dist/utils/objects/reportData.js +48 -0
- package/dist/utils/objects/statData.js +365 -0
- package/dist/utils/objects/stringData.js +67 -0
- package/dist/utils/objects/stringInfo.js +51 -0
- package/dist/utils/regex.js +8 -0
- package/dist/utils/reportFactory/base.js +51 -0
- package/dist/utils/reportFactory/html/index.js +36 -0
- package/dist/utils/reportFactory/html/template/css.js +133 -0
- package/dist/utils/reportFactory/html/template/html.js +79 -0
- package/dist/utils/reportFactory/html/template/javascript.js +106 -0
- package/dist/utils/reportFactory/index.js +38 -0
- package/dist/utils/reports.js +120 -0
- package/dist/utils/reportsTable.js +71 -0
- package/dist/utils/resource.js +54 -0
- package/dist/utils/runtime.js +16 -0
- package/dist/utils/scripts/genreport.js +1 -0
- package/dist/utils/scripts/postinstall.js +21 -0
- package/package.json +59 -0
- package/readme.md +15 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.USER_INPUT_PRE_FIX = exports.SYSTEM_TYPES = exports.STATUS_INFO = exports.STATUS_COLOR = exports.RES_FILE_EXTENSIONS = exports.REPORT_COUNTS = exports.PATTERNS = exports.LOG_FILE_PATH = exports.I18N_STATUS = exports.GARBLED_CHARACTERS = exports.DEBUG_MODE = exports.CONFIG_FILE_NAME = exports.COMMON_XPATH = exports.COLOR = void 0;
|
|
7
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const SYSTEM_TYPES = exports.SYSTEM_TYPES = {
|
|
10
|
+
NIGHT_WATCH: 'nightwatch',
|
|
11
|
+
WEB_DRIVER_IO: 'webio',
|
|
12
|
+
CYPRESS: 'cypress',
|
|
13
|
+
SELENIUMJS: 'seleniumJS'
|
|
14
|
+
};
|
|
15
|
+
const COLOR = exports.COLOR = {
|
|
16
|
+
GRB_GREEN: 'rgb(0, 154, 61)',
|
|
17
|
+
GRB_RED: 'rgb(255, 0, 0)',
|
|
18
|
+
GRB_YELLOW: 'rgb(255, 255, 0)',
|
|
19
|
+
GRB_BLUE: 'rgb(0, 0, 255)',
|
|
20
|
+
GRB_ORANGE: 'rgb(255, 165, 0)',
|
|
21
|
+
HEX_GREEN: '#007C00',
|
|
22
|
+
HEX_RED: '#F70000',
|
|
23
|
+
HEX_YELLOW: '#F7F700',
|
|
24
|
+
HEX_ORANGE: '#F76300',
|
|
25
|
+
ANSI_GREEN: '\x1b[32m',
|
|
26
|
+
ANSI_RED: '\x1b[31m',
|
|
27
|
+
ANSI_YELLOW: '\x1b[33m',
|
|
28
|
+
ANSI_BLUE: '\x1b[34m',
|
|
29
|
+
ANSI_ORANGE: '\x1b[91m'
|
|
30
|
+
};
|
|
31
|
+
const I18N_STATUS = exports.I18N_STATUS = {
|
|
32
|
+
STRING_LOCALIZED: 'STRING_LOCALIZED',
|
|
33
|
+
STRING_PARTIALLY_LOCALIZED: 'STRING_PARTIALLY_LOCALIZED',
|
|
34
|
+
NUMBER_LOCALIZED: 'NUMBER_LOCALIZED',
|
|
35
|
+
CURRENCY_LOCALIZED: 'CURRENCY_LOCALIZED',
|
|
36
|
+
PERCENTAGE_LOCALIZED: 'PERCENTAGE_LOCALIZED',
|
|
37
|
+
DATE_LOCALIZED: 'DATE_LOCALIZED',
|
|
38
|
+
TIME_LOCALIZED: 'TIME_LOCALIZED',
|
|
39
|
+
DATE_TIME_LOCALIZED: 'DATE_TIME_LOCALIZED',
|
|
40
|
+
STRING_NOT_LOCALIZED: 'STRING_NOT_LOCALIZED',
|
|
41
|
+
NUMBER_NOT_LOCALIZED: 'NUMBER_NOT_LOCALIZED',
|
|
42
|
+
CURRENCY_NOT_LOCALIZED: 'CURRENCY_NOT_LOCALIZED',
|
|
43
|
+
PERCENTAGE_NOT_LOCALIZED: 'PERCENTAGE_NOT_LOCALIZED',
|
|
44
|
+
DATE_NOT_LOCALIZED: 'DATE_NOT_LOCALIZED',
|
|
45
|
+
TIME_NOT_LOCALIZED: 'TIME_NOT_LOCALIZED',
|
|
46
|
+
DATE_TIME_NOT_LOCALIZED: 'DATE_TIME_NOT_LOCALIZED',
|
|
47
|
+
TRUNCATION_ISSUE: 'TRUNCATION_ISSUE',
|
|
48
|
+
OVERLAPPING_ISSUE: 'OVERLAPPING_ISSUE',
|
|
49
|
+
ENCODING_ISSUE: 'ENCODING_ISSUE',
|
|
50
|
+
DNT: 'DNT',
|
|
51
|
+
IGNORE: 'IGNORE',
|
|
52
|
+
UNTRANSLATED: 'UNTRANSLATED',
|
|
53
|
+
AUTO_IGNORE: 'AUTO_IGNORE',
|
|
54
|
+
USER_INPUT: 'USER_INPUT',
|
|
55
|
+
REVIEWED: 'REVIEWED'
|
|
56
|
+
};
|
|
57
|
+
const REPORT_COUNTS = exports.REPORT_COUNTS = {
|
|
58
|
+
[I18N_STATUS.STRING_LOCALIZED]: 0,
|
|
59
|
+
[I18N_STATUS.STRING_NOT_LOCALIZED]: 0,
|
|
60
|
+
[I18N_STATUS.STRING_PARTIALLY_LOCALIZED]: 0,
|
|
61
|
+
[I18N_STATUS.NUMBER_LOCALIZED]: 0,
|
|
62
|
+
[I18N_STATUS.NUMBER_NOT_LOCALIZED]: 0,
|
|
63
|
+
[I18N_STATUS.DATE_LOCALIZED]: 0,
|
|
64
|
+
[I18N_STATUS.DATE_NOT_LOCALIZED]: 0,
|
|
65
|
+
[I18N_STATUS.DATE_TIME_LOCALIZED]: 0,
|
|
66
|
+
[I18N_STATUS.DATE_TIME_NOT_LOCALIZED]: 0,
|
|
67
|
+
[I18N_STATUS.TIME_LOCALIZED]: 0,
|
|
68
|
+
[I18N_STATUS.TIME_NOT_LOCALIZED]: 0,
|
|
69
|
+
[I18N_STATUS.CURRENCY_LOCALIZED]: 0,
|
|
70
|
+
[I18N_STATUS.CURRENCY_NOT_LOCALIZED]: 0,
|
|
71
|
+
[I18N_STATUS.PERCENTAGE_LOCALIZED]: 0,
|
|
72
|
+
[I18N_STATUS.PERCENTAGE_NOT_LOCALIZED]: 0,
|
|
73
|
+
[I18N_STATUS.TRUNCATION_ISSUE]: 0,
|
|
74
|
+
[I18N_STATUS.OVERLAPPING_ISSUE]: 0,
|
|
75
|
+
[I18N_STATUS.ENCODING_ISSUE]: 0,
|
|
76
|
+
[I18N_STATUS.DNT]: 0,
|
|
77
|
+
[I18N_STATUS.IGNORE]: 0,
|
|
78
|
+
[I18N_STATUS.UNTRANSLATED]: 0,
|
|
79
|
+
[I18N_STATUS.AUTO_IGNORE]: 0,
|
|
80
|
+
[I18N_STATUS.USER_INPUT]: 0,
|
|
81
|
+
[I18N_STATUS.REVIEWED]: 0
|
|
82
|
+
};
|
|
83
|
+
const STATUS_COLOR = exports.STATUS_COLOR = {
|
|
84
|
+
[I18N_STATUS.STRING_LOCALIZED]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
85
|
+
[I18N_STATUS.STRING_PARTIALLY_LOCALIZED]: [COLOR.GRB_YELLOW, COLOR.ANSI_YELLOW],
|
|
86
|
+
[I18N_STATUS.NUMBER_LOCALIZED]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
87
|
+
[I18N_STATUS.DATE_LOCALIZED]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
88
|
+
[I18N_STATUS.TIME_LOCALIZED]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
89
|
+
[I18N_STATUS.DATE_TIME_LOCALIZED]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
90
|
+
[I18N_STATUS.CURRENCY_LOCALIZED]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
91
|
+
[I18N_STATUS.PERCENTAGE_LOCALIZED]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
92
|
+
[I18N_STATUS.STRING_NOT_LOCALIZED]: [COLOR.GRB_RED, COLOR.ANSI_RED],
|
|
93
|
+
[I18N_STATUS.DATE_NOT_LOCALIZED]: [COLOR.GRB_RED, COLOR.ANSI_RED],
|
|
94
|
+
[I18N_STATUS.DATE_TIME_NOT_LOCALIZED]: [COLOR.GRB_RED, COLOR.ANSI_RED],
|
|
95
|
+
[I18N_STATUS.TIME_NOT_LOCALIZED]: [COLOR.GRB_RED, COLOR.ANSI_RED],
|
|
96
|
+
[I18N_STATUS.NUMBER_NOT_LOCALIZED]: [COLOR.GRB_RED, COLOR.ANSI_RED],
|
|
97
|
+
[I18N_STATUS.CURRENCY_NOT_LOCALIZED]: [COLOR.GRB_RED, COLOR.ANSI_RED],
|
|
98
|
+
[I18N_STATUS.PERCENTAGE_NOT_LOCALIZED]: [COLOR.GRB_RED, COLOR.ANSI_RED],
|
|
99
|
+
[I18N_STATUS.TRUNCATION_ISSUE]: [COLOR.GRB_RED, COLOR.ANSI_RED],
|
|
100
|
+
[I18N_STATUS.OVERLAPPING_ISSUE]: [COLOR.GRB_RED, COLOR.ANSI_RED],
|
|
101
|
+
[I18N_STATUS.ENCODING_ISSUE]: [COLOR.GRB_RED, COLOR.ANSI_RED],
|
|
102
|
+
[I18N_STATUS.DNT]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
103
|
+
[I18N_STATUS.IGNORE]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
104
|
+
[I18N_STATUS.UNTRANSLATED]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
105
|
+
[I18N_STATUS.AUTO_IGNORE]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
106
|
+
[I18N_STATUS.USER_INPUT]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN],
|
|
107
|
+
[I18N_STATUS.REVIEWED]: [COLOR.GRB_GREEN, COLOR.ANSI_GREEN]
|
|
108
|
+
};
|
|
109
|
+
const STATUS_INFO = exports.STATUS_INFO = {
|
|
110
|
+
[I18N_STATUS.STRING_LOCALIZED]: 'String is localized',
|
|
111
|
+
[I18N_STATUS.STRING_PARTIALLY_LOCALIZED]: 'String is partially localized',
|
|
112
|
+
[I18N_STATUS.NUMBER_LOCALIZED]: 'Number is localized',
|
|
113
|
+
[I18N_STATUS.DATE_LOCALIZED]: 'Date is localized',
|
|
114
|
+
[I18N_STATUS.DATE_TIME_LOCALIZED]: 'DateTime is localized',
|
|
115
|
+
[I18N_STATUS.TIME_LOCALIZED]: 'Time is localized',
|
|
116
|
+
[I18N_STATUS.CURRENCY_LOCALIZED]: 'Currency is localized',
|
|
117
|
+
[I18N_STATUS.PERCENTAGE_LOCALIZED]: 'Percentage is localized',
|
|
118
|
+
[I18N_STATUS.STRING_NOT_LOCALIZED]: 'String is not localized',
|
|
119
|
+
[I18N_STATUS.DATE_NOT_LOCALIZED]: 'Date is not localized',
|
|
120
|
+
[I18N_STATUS.DATE_TIME_NOT_LOCALIZED]: 'DateTime is not localized',
|
|
121
|
+
[I18N_STATUS.TIME_NOT_LOCALIZED]: 'Time is not localized',
|
|
122
|
+
[I18N_STATUS.NUMBER_NOT_LOCALIZED]: 'Number is not localized',
|
|
123
|
+
[I18N_STATUS.CURRENCY_NOT_LOCALIZED]: 'Currency is not localized',
|
|
124
|
+
[I18N_STATUS.PERCENTAGE_NOT_LOCALIZED]: 'Percentage is not localized',
|
|
125
|
+
[I18N_STATUS.TRUNCATION_ISSUE]: 'Truncation issue detected',
|
|
126
|
+
[I18N_STATUS.OVERLAPPING_ISSUE]: 'Overlapping issue detected',
|
|
127
|
+
[I18N_STATUS.ENCODING_ISSUE]: 'Encoding issue detected',
|
|
128
|
+
[I18N_STATUS.DNT]: 'Do not translate',
|
|
129
|
+
[I18N_STATUS.IGNORE]: 'Ignored this issue',
|
|
130
|
+
[I18N_STATUS.UNTRANSLATED]: 'String is untranslated',
|
|
131
|
+
[I18N_STATUS.AUTO_IGNORE]: 'Automatically ignored issue',
|
|
132
|
+
[I18N_STATUS.USER_INPUT]: 'User input field',
|
|
133
|
+
[I18N_STATUS.REVIEWED]: 'Issue has been reviewed'
|
|
134
|
+
};
|
|
135
|
+
const PATTERNS = exports.PATTERNS = {
|
|
136
|
+
EMAIL: /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}\b/gi,
|
|
137
|
+
URL: /^(https?:\/\/)?(www\.)?[a-zA-Z0-9-]+\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?$/
|
|
138
|
+
};
|
|
139
|
+
const USER_INPUT_PRE_FIX = exports.USER_INPUT_PRE_FIX = 'zqa_';
|
|
140
|
+
const RES_FILE_EXTENSIONS = exports.RES_FILE_EXTENSIONS = ['.txt', '.json'];
|
|
141
|
+
const COMMON_XPATH = exports.COMMON_XPATH = `//*[string-length(normalize-space(text())) > 0 and not(ancestor-or-self::*/@style[contains(.,'display:none')]) or @placeholder] | //input[@type='checkbox']/parent::*[text() and not(ancestor-or-self::*/@style[contains(.,'display:none')])]`;
|
|
142
|
+
const DEBUG_MODE = exports.DEBUG_MODE = true;
|
|
143
|
+
const LOG_FILE_PATH = exports.LOG_FILE_PATH = _path.default.resolve(__dirname, '../logs');
|
|
144
|
+
const GARBLED_CHARACTERS = exports.GARBLED_CHARACTERS = ['☐', '�', '', 'â€', 'î', 'ÃÂ', 'ÃÂ', 'ü', 'é', 'é', 'æ•°', 'æ®', 'ラã'];
|
|
145
|
+
const CONFIG_FILE_NAME = exports.CONFIG_FILE_NAME = '.i18n-verify.rc';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.xpath = void 0;
|
|
7
|
+
const xpath = ({
|
|
8
|
+
subject,
|
|
9
|
+
selector,
|
|
10
|
+
options = {},
|
|
11
|
+
driver
|
|
12
|
+
}) => {
|
|
13
|
+
if (!Cypress) {
|
|
14
|
+
driver.printOnConsole('Cypress object is inaccessible');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* global XPathResult */
|
|
19
|
+
const isNumber = xpathResult => xpathResult.resultType === XPathResult.NUMBER_TYPE;
|
|
20
|
+
const numberResult = xpathResult => xpathResult.numberValue;
|
|
21
|
+
const isString = xpathResult => xpathResult.resultType === XPathResult.STRING_TYPE;
|
|
22
|
+
const stringResult = xpathResult => xpathResult.stringValue;
|
|
23
|
+
const isBoolean = xpathResult => xpathResult.resultType === XPathResult.BOOLEAN_TYPE;
|
|
24
|
+
const booleanResult = xpathResult => xpathResult.booleanValue;
|
|
25
|
+
const isPrimitive = x => Cypress._.isNumber(x) || Cypress._.isString(x) || Cypress._.isBoolean(x);
|
|
26
|
+
|
|
27
|
+
// options to log later
|
|
28
|
+
const log = {
|
|
29
|
+
name: 'xpath',
|
|
30
|
+
message: selector
|
|
31
|
+
};
|
|
32
|
+
if (Cypress.dom.isElement(subject) && subject.length > 1) {
|
|
33
|
+
throw new Error('xpath() can only be called on a single element. Your subject contained ' + subject.length + ' elements.');
|
|
34
|
+
}
|
|
35
|
+
const getValue = () => {
|
|
36
|
+
let nodes = [];
|
|
37
|
+
let contextNode;
|
|
38
|
+
let withinSubject = cy.state('withinSubject');
|
|
39
|
+
if (Cypress.dom.isElement(subject)) {
|
|
40
|
+
contextNode = subject[0];
|
|
41
|
+
} else if (Cypress.dom.isDocument(subject)) {
|
|
42
|
+
contextNode = subject;
|
|
43
|
+
} else if (withinSubject) {
|
|
44
|
+
contextNode = withinSubject[0];
|
|
45
|
+
} else {
|
|
46
|
+
contextNode = cy.state('window').document;
|
|
47
|
+
}
|
|
48
|
+
let iterator = (contextNode.ownerDocument || contextNode).evaluate(selector, contextNode);
|
|
49
|
+
if (isNumber(iterator)) {
|
|
50
|
+
const result = numberResult(iterator);
|
|
51
|
+
log.consoleProps = () => {
|
|
52
|
+
return {
|
|
53
|
+
XPath: selector,
|
|
54
|
+
type: 'number',
|
|
55
|
+
result
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
if (isString(iterator)) {
|
|
61
|
+
const result = stringResult(iterator);
|
|
62
|
+
log.consoleProps = () => {
|
|
63
|
+
return {
|
|
64
|
+
XPath: selector,
|
|
65
|
+
type: 'string',
|
|
66
|
+
result
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
if (isBoolean(iterator)) {
|
|
72
|
+
const result = booleanResult(iterator);
|
|
73
|
+
log.consoleProps = () => {
|
|
74
|
+
return {
|
|
75
|
+
XPath: selector,
|
|
76
|
+
type: 'boolean',
|
|
77
|
+
result
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
let node = iterator.iterateNext();
|
|
84
|
+
while (node) {
|
|
85
|
+
nodes.push(node);
|
|
86
|
+
node = iterator.iterateNext();
|
|
87
|
+
}
|
|
88
|
+
log.consoleProps = () => {
|
|
89
|
+
return {
|
|
90
|
+
XPath: selector,
|
|
91
|
+
result: nodes.length === 1 ? nodes[0] : nodes
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
return nodes;
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.error('Document tree modified during iteration', e);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const resolveValue = () => {
|
|
101
|
+
return Cypress.Promise.try(getValue).then(value => {
|
|
102
|
+
if (!isPrimitive(value)) {
|
|
103
|
+
value = Cypress.$(value);
|
|
104
|
+
// Add the ".selector" property because Cypress uses it for error messages
|
|
105
|
+
value.selector = selector;
|
|
106
|
+
}
|
|
107
|
+
return cy.verifyUpcomingAssertions(value, options, {
|
|
108
|
+
onRetry: resolveValue
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
return resolveValue().then(value => {
|
|
113
|
+
if (options.log !== false) {
|
|
114
|
+
// TODO set found elements on the command log?
|
|
115
|
+
Cypress.log(log);
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
}).catch(ex => console.log(ex));
|
|
119
|
+
};
|
|
120
|
+
exports.xpath = xpath;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isValid = exports.getParser = void 0;
|
|
7
|
+
var _chronoNode = require("chrono-node");
|
|
8
|
+
const getParser = locale => {
|
|
9
|
+
let [lang = 'en', country = 'us'] = locale.split(/[-_ ]/g);
|
|
10
|
+
country = String(country).toLowerCase();
|
|
11
|
+
switch (lang) {
|
|
12
|
+
case 'en':
|
|
13
|
+
return country === 'gb' ? _chronoNode.en.GB : _chronoNode.en;
|
|
14
|
+
case 'de':
|
|
15
|
+
return _chronoNode.de;
|
|
16
|
+
case 'es':
|
|
17
|
+
return _chronoNode.es;
|
|
18
|
+
case 'fr':
|
|
19
|
+
return _chronoNode.fr;
|
|
20
|
+
case 'pt':
|
|
21
|
+
return _chronoNode.pt;
|
|
22
|
+
case 'ja':
|
|
23
|
+
return _chronoNode.ja;
|
|
24
|
+
case 'zh':
|
|
25
|
+
if (['hans', 'cn', 'sg', 'hans-cn'].includes(country)) {
|
|
26
|
+
return _chronoNode.zh.hans;
|
|
27
|
+
} else if (['hant', 'tw', 'hk', 'mo', 'hant-tw'].includes(country)) {
|
|
28
|
+
return _chronoNode.zh.hant;
|
|
29
|
+
}
|
|
30
|
+
return _chronoNode.zh;
|
|
31
|
+
case 'ru':
|
|
32
|
+
return _chronoNode.ru;
|
|
33
|
+
case 'nl':
|
|
34
|
+
return _chronoNode.nl;
|
|
35
|
+
case 'uk':
|
|
36
|
+
return _chronoNode.uk;
|
|
37
|
+
default:
|
|
38
|
+
return _chronoNode.en;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// performs strict validation rather than loose parsing
|
|
43
|
+
exports.getParser = getParser;
|
|
44
|
+
const isValid = (locale, string) => {
|
|
45
|
+
string = String(string);
|
|
46
|
+
const parsedResults = getParser(locale).parse(String(string).trim());
|
|
47
|
+
parsedResults.forEach(r => {
|
|
48
|
+
string = string.replace(r.text, '');
|
|
49
|
+
});
|
|
50
|
+
return string.replace(/[^\p{L}\p{N}]+/gu, '').trim().length === 0;
|
|
51
|
+
};
|
|
52
|
+
exports.isValid = isValid;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.saveToFile = exports.pathExists = exports.joinPaths = exports.getFileName = exports.getFileExtenstion = exports.getFileContent = exports.getDirContents = exports.fileExists = exports.ensureDirectoryExists = exports.dirExists = exports.deleteFile = exports.createFolder = exports.addContentToFile = void 0;
|
|
7
|
+
var _fs = require("fs");
|
|
8
|
+
var _path = require("path");
|
|
9
|
+
const getFileName = path => (0, _path.basename)(path);
|
|
10
|
+
exports.getFileName = getFileName;
|
|
11
|
+
const dirExists = path => pathExists(path) && (0, _fs.statSync)(path).isDirectory();
|
|
12
|
+
exports.dirExists = dirExists;
|
|
13
|
+
const fileExists = path => pathExists(path) && (0, _fs.statSync)(path).isFile();
|
|
14
|
+
exports.fileExists = fileExists;
|
|
15
|
+
const pathExists = path => (0, _fs.existsSync)(path);
|
|
16
|
+
exports.pathExists = pathExists;
|
|
17
|
+
const createFolder = path => !pathExists(path) && (0, _fs.mkdirSync)(path, {
|
|
18
|
+
recursive: true
|
|
19
|
+
});
|
|
20
|
+
exports.createFolder = createFolder;
|
|
21
|
+
const ensureDirectoryExists = (path, log = true) => {
|
|
22
|
+
if (!pathExists(path) || !dirExists(path)) {
|
|
23
|
+
log && console.log(`Folder doesn't exists, creating ${path}`);
|
|
24
|
+
createFolder(path);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.ensureDirectoryExists = ensureDirectoryExists;
|
|
28
|
+
const getFileContent = path => fileExists(path) ? (0, _fs.readFileSync)(path, {
|
|
29
|
+
encoding: 'utf-8'
|
|
30
|
+
}) : '';
|
|
31
|
+
exports.getFileContent = getFileContent;
|
|
32
|
+
const getDirContents = path => dirExists(path) ? (0, _fs.readdirSync)(path) : [];
|
|
33
|
+
exports.getDirContents = getDirContents;
|
|
34
|
+
const getFileExtenstion = path => fileExists(path) ? (0, _path.extname)(path) : '';
|
|
35
|
+
exports.getFileExtenstion = getFileExtenstion;
|
|
36
|
+
const joinPaths = (...paths) => (0, _path.join)(...paths);
|
|
37
|
+
exports.joinPaths = joinPaths;
|
|
38
|
+
const saveToFile = (path, content, encoding = 'utf-8') => (0, _fs.writeFileSync)(path, content, {
|
|
39
|
+
encoding
|
|
40
|
+
});
|
|
41
|
+
exports.saveToFile = saveToFile;
|
|
42
|
+
const addContentToFile = (path, content, encoding = 'utf-8') => {
|
|
43
|
+
if (!path || !content) return;
|
|
44
|
+
try {
|
|
45
|
+
(0, _fs.appendFileSync)(path, content + '\n', {
|
|
46
|
+
encoding,
|
|
47
|
+
flag: 'a'
|
|
48
|
+
});
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.error(err);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.addContentToFile = addContentToFile;
|
|
54
|
+
const deleteFile = (path, recursive = false) => pathExists(path) && (0, _fs.rmSync)(path, {
|
|
55
|
+
recursive
|
|
56
|
+
});
|
|
57
|
+
exports.deleteFile = deleteFile;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
var _constants = require("../utils/constants.js");
|
|
9
|
+
var _file = require("./file.js");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
class Logger {
|
|
13
|
+
static info(message) {
|
|
14
|
+
Logger.#print('info', message);
|
|
15
|
+
}
|
|
16
|
+
static warn(message) {
|
|
17
|
+
Logger.#print('warn', message);
|
|
18
|
+
}
|
|
19
|
+
static error(message) {
|
|
20
|
+
Logger.#print('error', message);
|
|
21
|
+
}
|
|
22
|
+
static debug(message) {
|
|
23
|
+
Logger.#print('debug', message);
|
|
24
|
+
}
|
|
25
|
+
static #print(type, message) {
|
|
26
|
+
type = type.toUpperCase();
|
|
27
|
+
let logMessage = `${new Date().toISOString()} - ${type} - ${message}`;
|
|
28
|
+
switch (type) {
|
|
29
|
+
case 'INFO':
|
|
30
|
+
_constants.DEBUG_MODE && console.info(logMessage);
|
|
31
|
+
break;
|
|
32
|
+
case 'WARN':
|
|
33
|
+
_constants.DEBUG_MODE && console.warn(logMessage);
|
|
34
|
+
break;
|
|
35
|
+
case 'ERROR':
|
|
36
|
+
console.error(logMessage);
|
|
37
|
+
break;
|
|
38
|
+
case 'DEBUG':
|
|
39
|
+
_constants.DEBUG_MODE && console.debug(logMessage);
|
|
40
|
+
break;
|
|
41
|
+
default:
|
|
42
|
+
_constants.DEBUG_MODE && console.log(logMessage);
|
|
43
|
+
}
|
|
44
|
+
logMessage = logMessage.replace(/\x1b\[\d+m/g, '');
|
|
45
|
+
Logger.#customLog(`${logMessage}\n`);
|
|
46
|
+
}
|
|
47
|
+
static #customLog = message => {
|
|
48
|
+
const LOGS_DIR = _path.default.resolve(_constants.LOG_FILE_PATH);
|
|
49
|
+
const logFilePath = (0, _file.joinPaths)(LOGS_DIR, 'log.log');
|
|
50
|
+
(0, _file.ensureDirectoryExists)(LOGS_DIR, _constants.DEBUG_MODE);
|
|
51
|
+
if (!(0, _file.fileExists)(logFilePath)) {
|
|
52
|
+
fs.writeFileSync(logFilePath, '');
|
|
53
|
+
}
|
|
54
|
+
fs.appendFile(logFilePath, message, err => {
|
|
55
|
+
if (err) {
|
|
56
|
+
Logger.error('Error writing to log file:', err);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.default = Logger;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _cache = _interopRequireDefault(require("../cache.js"));
|
|
8
|
+
var _metaData = _interopRequireDefault(require("./metaData.js"));
|
|
9
|
+
var _statData = _interopRequireDefault(require("./statData.js"));
|
|
10
|
+
var _stringData = _interopRequireDefault(require("./stringData.js"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
class CacheData {
|
|
13
|
+
/**
|
|
14
|
+
* @type {MetaData}
|
|
15
|
+
*/
|
|
16
|
+
#metaData;
|
|
17
|
+
/**
|
|
18
|
+
* @type {{[key: string] : StringData}}
|
|
19
|
+
*/
|
|
20
|
+
#localeData = {};
|
|
21
|
+
constructor(data = {}) {
|
|
22
|
+
this.#metaData = new _metaData.default(data.metaData);
|
|
23
|
+
if (data.localeData) {
|
|
24
|
+
for (const locale in data.localeData) {
|
|
25
|
+
this.#localeData[locale] = new _stringData.default(data.localeData[locale]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
getMetaData() {
|
|
30
|
+
return this.#metaData;
|
|
31
|
+
}
|
|
32
|
+
setMetaData(metaData) {
|
|
33
|
+
this.#metaData = metaData;
|
|
34
|
+
}
|
|
35
|
+
getLocales() {
|
|
36
|
+
return Object.keys(this.#localeData);
|
|
37
|
+
}
|
|
38
|
+
getLocaleStringData(locale) {
|
|
39
|
+
return locale ? this.#localeData[locale] : this.#localeData;
|
|
40
|
+
}
|
|
41
|
+
setLocaleStringData(locale, stringData) {
|
|
42
|
+
this.#localeData[locale] = stringData;
|
|
43
|
+
}
|
|
44
|
+
getStringEntry(locale, string) {
|
|
45
|
+
return this.#localeData[locale].getStringData(string);
|
|
46
|
+
}
|
|
47
|
+
static addString(locale, string, type, description, imagePath) {
|
|
48
|
+
const cache = CacheData.getInstance();
|
|
49
|
+
const added = cache.#addStringEntry(locale, string, type, description, imagePath);
|
|
50
|
+
cache.save();
|
|
51
|
+
return added;
|
|
52
|
+
}
|
|
53
|
+
#addStringEntry(locale, string, type, description, imagePath) {
|
|
54
|
+
let dataAdded = false;
|
|
55
|
+
const info = {
|
|
56
|
+
type,
|
|
57
|
+
description,
|
|
58
|
+
imagePath
|
|
59
|
+
};
|
|
60
|
+
if (!this.#localeData[locale]) {
|
|
61
|
+
this.#localeData[locale] = _stringData.default.createNew(string, info);
|
|
62
|
+
this.#metaData.setStatByLocale(locale, new _statData.default());
|
|
63
|
+
dataAdded = true;
|
|
64
|
+
} else if (!this.#localeData[locale].hasStringData(string)) {
|
|
65
|
+
dataAdded = this.#localeData[locale].setStringData(string, info);
|
|
66
|
+
} else {
|
|
67
|
+
dataAdded = this.#localeData[locale].checkAndAdd(string, info);
|
|
68
|
+
}
|
|
69
|
+
if (dataAdded) {
|
|
70
|
+
this.#metaData.getStat().incrementByType(type);
|
|
71
|
+
this.#metaData.getStatByLocale(locale).incrementByType(type);
|
|
72
|
+
}
|
|
73
|
+
return dataAdded;
|
|
74
|
+
}
|
|
75
|
+
toJSON() {
|
|
76
|
+
return {
|
|
77
|
+
metaData: this.#metaData,
|
|
78
|
+
localeData: this.#localeData
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
save() {
|
|
82
|
+
_cache.default.save(this);
|
|
83
|
+
}
|
|
84
|
+
remove() {
|
|
85
|
+
_cache.default.delete();
|
|
86
|
+
}
|
|
87
|
+
static getInstance() {
|
|
88
|
+
return new CacheData(_cache.default.getData());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.default = CacheData;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _statData = _interopRequireDefault(require("./statData.js"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
class MetaData {
|
|
10
|
+
/**
|
|
11
|
+
* @type {StatData}
|
|
12
|
+
*/
|
|
13
|
+
#stat;
|
|
14
|
+
/**
|
|
15
|
+
* @type {{[key: string]: StatData}}
|
|
16
|
+
*/
|
|
17
|
+
#statByLocale = {};
|
|
18
|
+
constructor(data = {}) {
|
|
19
|
+
this.#stat = new _statData.default(data.stat);
|
|
20
|
+
if (data?.statByLocale) {
|
|
21
|
+
for (const locale in data.statByLocale) {
|
|
22
|
+
this.#statByLocale[locale] = new _statData.default(data.statByLocale[locale]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
getStat() {
|
|
27
|
+
return this.#stat;
|
|
28
|
+
}
|
|
29
|
+
setStat(stat) {
|
|
30
|
+
this.#stat = stat;
|
|
31
|
+
}
|
|
32
|
+
getStatByLocale(locale) {
|
|
33
|
+
return locale ? this.#statByLocale[locale] : this.#statByLocale;
|
|
34
|
+
}
|
|
35
|
+
setStatByLocale(locale, data) {
|
|
36
|
+
this.#statByLocale[locale] = data;
|
|
37
|
+
}
|
|
38
|
+
getLocales() {
|
|
39
|
+
return Object.keys(this.#statByLocale);
|
|
40
|
+
}
|
|
41
|
+
toJSON() {
|
|
42
|
+
return {
|
|
43
|
+
stat: this.#stat,
|
|
44
|
+
statByLocale: this.#statByLocale
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.default = MetaData;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _cacheData = _interopRequireDefault(require("./cacheData.js"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
class ReportData {
|
|
10
|
+
/**
|
|
11
|
+
* @type {CacheData}
|
|
12
|
+
*/
|
|
13
|
+
#data;
|
|
14
|
+
/**
|
|
15
|
+
* @type {String}
|
|
16
|
+
*/
|
|
17
|
+
#appName;
|
|
18
|
+
/**
|
|
19
|
+
* @type {String}
|
|
20
|
+
*/
|
|
21
|
+
#reportTime;
|
|
22
|
+
constructor({
|
|
23
|
+
data,
|
|
24
|
+
appName,
|
|
25
|
+
reportTime
|
|
26
|
+
}) {
|
|
27
|
+
this.#data = data;
|
|
28
|
+
this.#appName = appName;
|
|
29
|
+
this.#reportTime = reportTime;
|
|
30
|
+
}
|
|
31
|
+
getData() {
|
|
32
|
+
return this.#data;
|
|
33
|
+
}
|
|
34
|
+
getAppName() {
|
|
35
|
+
return this.#appName;
|
|
36
|
+
}
|
|
37
|
+
getReportTime() {
|
|
38
|
+
return this.#reportTime;
|
|
39
|
+
}
|
|
40
|
+
toJSON() {
|
|
41
|
+
return {
|
|
42
|
+
data: this.#data,
|
|
43
|
+
appName: this.#appName,
|
|
44
|
+
reportTime: this.#reportTime
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.default = ReportData;
|