@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
package/dist/lib/i18n.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _baseDriver = _interopRequireDefault(require("../driver/baseDriver.js"));
|
|
8
|
+
var _constants = require("../utils/constants.js");
|
|
9
|
+
var _config = _interopRequireDefault(require("./config.js"));
|
|
10
|
+
var _reports = _interopRequireDefault(require("../utils/reports.js"));
|
|
11
|
+
var _dGraphic = _interopRequireDefault(require("../utils/2dGraphic.js"));
|
|
12
|
+
var _logs = _interopRequireDefault(require("../utils/logs.js"));
|
|
13
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
14
|
+
var _file = require("../utils/file.js");
|
|
15
|
+
var _index = _interopRequireDefault(require("./validator/index.js"));
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
class I18nVerify {
|
|
18
|
+
#driver;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {BaseDriver} driver
|
|
22
|
+
*/
|
|
23
|
+
constructor(driver) {
|
|
24
|
+
this.#driver = driver;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} verificationArea - xpath selector of verification area
|
|
29
|
+
* @param {string} staticLocators - user parsed xpath selectors to find text of elements under verification area
|
|
30
|
+
* @param {string} description - identity of verification area ex: page, popup, form etc name
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
async verify({
|
|
34
|
+
verificationArea,
|
|
35
|
+
staticLocators,
|
|
36
|
+
description
|
|
37
|
+
}) {
|
|
38
|
+
let locArray = [];
|
|
39
|
+
let xPath;
|
|
40
|
+
const options = _config.default.getOptions();
|
|
41
|
+
if (Array.isArray(staticLocators) && staticLocators.length > 0) {
|
|
42
|
+
for (const locator of staticLocators) {
|
|
43
|
+
let updatedLocator = verificationArea + locator;
|
|
44
|
+
locArray.push(updatedLocator);
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
xPath = verificationArea !== '' ? verificationArea + _constants.COMMON_XPATH : _constants.COMMON_XPATH;
|
|
48
|
+
}
|
|
49
|
+
_config.default.incrementCounter();
|
|
50
|
+
const img_name = `${_config.default.getSSCount().toString().padStart(3, '0')}_${description.replace(/[^\w\s]/gi, '').replace(/\s+/g, '')}.png`;
|
|
51
|
+
const reviewed_image = (0, _file.joinPaths)(_reports.default.reviewedReports(), img_name);
|
|
52
|
+
await this.#captureCurrentScreen(reviewed_image);
|
|
53
|
+
if (options?.i18nVerify) {
|
|
54
|
+
try {
|
|
55
|
+
if (locArray.length > 0) {
|
|
56
|
+
for (const locator of locArray) {
|
|
57
|
+
await this.#getElement(verificationArea, locator, img_name, description);
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
await this.#getElements(verificationArea, xPath, img_name, description);
|
|
61
|
+
}
|
|
62
|
+
} catch (elementsError) {
|
|
63
|
+
_logs.default.error('Elements not found under specified locator on page: ', description);
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
_logs.default.info('Skipped i18n verification as per user configuration...');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async #getElement(verificationArea, locator, img_name, desc) {
|
|
70
|
+
const ele = await this.#driver.getElement(locator);
|
|
71
|
+
if (ele && (await this.#driver.isElementDisplayed(ele))) {
|
|
72
|
+
let str;
|
|
73
|
+
try {
|
|
74
|
+
str = await this.#driver.getElementString(ele);
|
|
75
|
+
try {
|
|
76
|
+
await this.#generateReports(verificationArea, ele, img_name, str, desc);
|
|
77
|
+
} catch (reportError) {
|
|
78
|
+
console.error('Error generating report of element:', reportError);
|
|
79
|
+
}
|
|
80
|
+
} catch (textError) {
|
|
81
|
+
console.error('Error getting text of element:', textError);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
console.error('No element found:', locator);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async #getElements(verificationArea, xpaths, img_name, desc) {
|
|
88
|
+
const eles = await this.#driver.getElements(xpaths);
|
|
89
|
+
if (eles.length > 0) {
|
|
90
|
+
for (const el of eles) {
|
|
91
|
+
if (await this.#driver.isElementDisplayed(el)) {
|
|
92
|
+
let uiStrings;
|
|
93
|
+
try {
|
|
94
|
+
uiStrings = await this.#driver.getElementStrings(el);
|
|
95
|
+
try {
|
|
96
|
+
for (const str of uiStrings) {
|
|
97
|
+
await this.#generateReports(verificationArea, el, img_name, str, desc);
|
|
98
|
+
}
|
|
99
|
+
} catch (reportError) {
|
|
100
|
+
console.error('Error generating report of element:', reportError);
|
|
101
|
+
}
|
|
102
|
+
} catch (textError) {
|
|
103
|
+
console.error('Error getting text of elements:', textError);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
console.error('No elements found:', xpaths);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async #generateReports(verificationArea, el, image_name, str, desc) {
|
|
112
|
+
//TODO: in some cases, the str is having 0
|
|
113
|
+
//needs more inspection
|
|
114
|
+
if (typeof str !== 'string' || !str || Number(str) === 0) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
_reports.default.incrementCount(_constants.I18N_STATUS.REVIEWED);
|
|
118
|
+
const i18nStatus = _index.default.getIssueType(str),
|
|
119
|
+
src_img = (0, _file.joinPaths)(_reports.default.reviewedReports(str, image_name), image_name);
|
|
120
|
+
if (i18nStatus && src_img && typeof _reports.default[i18nStatus] === 'function') {
|
|
121
|
+
const color = this.#defineColor(i18nStatus, str),
|
|
122
|
+
dest_img = (0, _file.joinPaths)(_reports.default[i18nStatus](str, image_name), image_name);
|
|
123
|
+
const eles = [];
|
|
124
|
+
eles.push(el);
|
|
125
|
+
browser.perform(async function () {
|
|
126
|
+
for (const el of eles) {
|
|
127
|
+
if (true) {
|
|
128
|
+
// Highlight the element using custom JavaScript
|
|
129
|
+
browser.execute(function (el, color) {
|
|
130
|
+
el.style.border = `3px solid ${color}`;
|
|
131
|
+
setTimeout(function () {
|
|
132
|
+
el.style.border = 'none'; // Remove border
|
|
133
|
+
}, 50);
|
|
134
|
+
}, [el, color]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
await this.#highlightReports(verificationArea, el, color, src_img, dest_img, str);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async #highlightReports(verificationArea, el, color, src_img, rep_img, str) {
|
|
142
|
+
try {
|
|
143
|
+
if (_fs.default.existsSync(src_img) && !_fs.default.existsSync(rep_img)) {
|
|
144
|
+
_fs.default.copyFileSync(src_img, rep_img);
|
|
145
|
+
} else if (!_fs.default.existsSync(rep_img) && !_fs.default.existsSync(src_img)) {
|
|
146
|
+
await this.#captureCurrentScreen(src_img);
|
|
147
|
+
_fs.default.copyFileSync(src_img, rep_img);
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {
|
|
150
|
+
_logs.default.error(`zee-error#2 - ${src_img} is not exists and unable to capture screenshot`);
|
|
151
|
+
}
|
|
152
|
+
const area = await this.#driver.getElement(verificationArea);
|
|
153
|
+
const areaColor = _constants.COLOR.GRB_BLUE;
|
|
154
|
+
const areaRec = await this.#getRect(area);
|
|
155
|
+
const eleRec = await this.#getRect(el);
|
|
156
|
+
await _dGraphic.default.drawRectangle(areaRec, areaColor, rep_img);
|
|
157
|
+
await _dGraphic.default.drawRectangle(eleRec, color, rep_img);
|
|
158
|
+
}
|
|
159
|
+
async #captureCurrentScreen(imagePath) {
|
|
160
|
+
await this.#driver.captureScreenshot(imagePath);
|
|
161
|
+
}
|
|
162
|
+
async #getRect(el) {
|
|
163
|
+
const elObj = await this.#driver.getElementDimension(el);
|
|
164
|
+
return {
|
|
165
|
+
x: elObj[0],
|
|
166
|
+
y: elObj[1],
|
|
167
|
+
height: elObj[2],
|
|
168
|
+
width: elObj[3]
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
#defineColor(i18nStatus, str) {
|
|
172
|
+
_reports.default.incrementCount(i18nStatus);
|
|
173
|
+
_logs.default.debug(`[${str}] ${_constants.STATUS_COLOR[i18nStatus][1]} ${_constants.STATUS_INFO[i18nStatus]}${'\x1b[0m'}`);
|
|
174
|
+
return _constants.STATUS_COLOR[i18nStatus][0];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.default = I18nVerify;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _config = _interopRequireDefault(require("../config.js"));
|
|
8
|
+
var _globalize = _interopRequireDefault(require("globalize"));
|
|
9
|
+
var _cldrData = _interopRequireDefault(require("cldr-data"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const parserType = {
|
|
12
|
+
dateParser:
|
|
13
|
+
/**
|
|
14
|
+
* @type {Globalize.dateParser}
|
|
15
|
+
*/
|
|
16
|
+
() => {},
|
|
17
|
+
numberParser:
|
|
18
|
+
/**
|
|
19
|
+
* @type {Globalize.numberParser}
|
|
20
|
+
*/
|
|
21
|
+
() => {}
|
|
22
|
+
};
|
|
23
|
+
class BaseValidator {
|
|
24
|
+
#config = {};
|
|
25
|
+
#type;
|
|
26
|
+
constructor(type) {
|
|
27
|
+
this.#type = type;
|
|
28
|
+
this.#addBaseConfig();
|
|
29
|
+
this.buildConfig();
|
|
30
|
+
this.#buildParser();
|
|
31
|
+
}
|
|
32
|
+
#addBaseConfig() {
|
|
33
|
+
this.addToConfig('supportedLocales', _config.default.getOptions()?.supportedLocales, []);
|
|
34
|
+
this.addToConfig('defaultLocale', _config.default.getDefaultLocale());
|
|
35
|
+
this.addToConfig('defaultLanguage', _config.default.getDefaultLocale()?.split(/[-_ ]/g)[0]);
|
|
36
|
+
this.addToConfig('language', _config.default.getLocale()?.split(/[-_ ]/g)[0]);
|
|
37
|
+
this.addToConfig('locale', _config.default.getLocale());
|
|
38
|
+
this.addToConfig('qaLocale', _config.default.getQALocale());
|
|
39
|
+
}
|
|
40
|
+
buildConfig() {
|
|
41
|
+
throw new Error(`{{${this.#type}}} buildConfig should be implemented by child class`);
|
|
42
|
+
}
|
|
43
|
+
#buildParser() {
|
|
44
|
+
_globalize.default.load(_cldrData.default.entireSupplemental());
|
|
45
|
+
_globalize.default.load(_cldrData.default.entireMainFor(this.#getCompatibleLocale(this.#config.defaultLocale), this.#getCompatibleLocale(this.#config.locale)));
|
|
46
|
+
}
|
|
47
|
+
#getCompatibleLocale(locale) {
|
|
48
|
+
if (this.isQaLocale()) {
|
|
49
|
+
return 'en';
|
|
50
|
+
}
|
|
51
|
+
locale = locale.replace(/[-_ ]/g, '-');
|
|
52
|
+
const locales = _cldrData.default.availableLocales;
|
|
53
|
+
let suitableLocale;
|
|
54
|
+
if (locales.find(l => l === locale)) {
|
|
55
|
+
suitableLocale = locale;
|
|
56
|
+
} else {
|
|
57
|
+
const temp = locale.split('-')[0];
|
|
58
|
+
if (locales.find(l => l === temp)) {
|
|
59
|
+
suitableLocale = temp;
|
|
60
|
+
} else {
|
|
61
|
+
suitableLocale = locale;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return suitableLocale;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* to check if the given text is a valid issue type
|
|
69
|
+
* @param {String} string
|
|
70
|
+
* @returns {Boolean}
|
|
71
|
+
*/
|
|
72
|
+
validate(string) {
|
|
73
|
+
throw new Error(`{{${this.#type}}} validate should be implemented by child class`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* check whether the given value is a valid type of the supplied locale
|
|
78
|
+
*
|
|
79
|
+
* @param {String} string
|
|
80
|
+
* @returns {Boolean}
|
|
81
|
+
*/
|
|
82
|
+
isInternationalized(string) {
|
|
83
|
+
throw new Error(`{{${this.#type}}} isInternationalized should be implemented by child class`);
|
|
84
|
+
}
|
|
85
|
+
setConfig(data) {
|
|
86
|
+
this.#config = data;
|
|
87
|
+
}
|
|
88
|
+
addToConfig(prop, value, defaultValue) {
|
|
89
|
+
this.#config[prop] = value ?? defaultValue;
|
|
90
|
+
}
|
|
91
|
+
getConfig() {
|
|
92
|
+
return this.#config;
|
|
93
|
+
}
|
|
94
|
+
isSupportedLocale() {
|
|
95
|
+
return this.#config.supportedLocales.includes(this.currentLocale());
|
|
96
|
+
}
|
|
97
|
+
isQaLocale() {
|
|
98
|
+
return this.currentLocale() === this.#config?.qaLocale;
|
|
99
|
+
}
|
|
100
|
+
isDefaultLocale() {
|
|
101
|
+
return this.currentLocale() === this.defaultLocale();
|
|
102
|
+
}
|
|
103
|
+
defaultLocale() {
|
|
104
|
+
return this.#config?.defaultLocale;
|
|
105
|
+
}
|
|
106
|
+
defaultLanguage() {
|
|
107
|
+
return this.#config?.defaultLanguage;
|
|
108
|
+
}
|
|
109
|
+
currentLocale() {
|
|
110
|
+
return this.#config?.locale;
|
|
111
|
+
}
|
|
112
|
+
currentLanguage() {
|
|
113
|
+
return this.#config.language;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param {String} locale
|
|
119
|
+
* @returns {Globalize}
|
|
120
|
+
*/
|
|
121
|
+
getGlobalize(locale) {
|
|
122
|
+
return (0, _globalize.default)(this.#getCompatibleLocale(locale));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.default = BaseValidator;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _regex = require("../../utils/regex.js");
|
|
8
|
+
var _base = _interopRequireDefault(require("./base.js"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
class CurrencyValidator extends _base.default {
|
|
11
|
+
constructor() {
|
|
12
|
+
super('currency');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @override
|
|
18
|
+
*/
|
|
19
|
+
validate(string) {
|
|
20
|
+
return this.#isDefaultCurrency(string) || this.isInternationalized(string);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @override
|
|
26
|
+
*/
|
|
27
|
+
isInternationalized(string) {
|
|
28
|
+
return this.#isValidCurrency(this.currentLocale(), string);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @override
|
|
34
|
+
*/
|
|
35
|
+
buildConfig() {}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* check whether the given value is a valid percentage of the supplied locale
|
|
39
|
+
*
|
|
40
|
+
* @param {String} locale
|
|
41
|
+
* @param {String} string
|
|
42
|
+
* @returns {Boolean}
|
|
43
|
+
*/
|
|
44
|
+
#isValidCurrency(locale, string) {
|
|
45
|
+
const currencyCode = this.#getCurrencyCode(locale);
|
|
46
|
+
const currencySymbol = this.#getCurrencySymbol(locale, currencyCode);
|
|
47
|
+
const hasCurrencySymbolOrCode = this.#hasCurrencyCodeOrSymbol(currencyCode, currencySymbol, string);
|
|
48
|
+
if (!hasCurrencySymbolOrCode) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// strip currency code and symbol and then validate number
|
|
53
|
+
const clearNumber = this.#clearNumber(currencyCode, currencySymbol, string);
|
|
54
|
+
return !isNaN(this.getGlobalize(locale).numberParser()(clearNumber));
|
|
55
|
+
}
|
|
56
|
+
#hasCurrencyCodeOrSymbol(code, symbol, string) {
|
|
57
|
+
return new RegExp(`^(?:-)?(?:${code}|\\${symbol})(?:${(0, _regex.getSpacePattern)()})?(?:-)?[0-9,. ]+$`, 'gi').test(string) || new RegExp(`^(?:[- ]?)[0-9,. ]+(?:${(0, _regex.getSpacePattern)()})?(?:${code}|\\${symbol})$`, 'gi').test(string);
|
|
58
|
+
}
|
|
59
|
+
#clearNumber(code, symbol, string) {
|
|
60
|
+
return string.replace(new RegExp(`^(?:-)(?:${(0, _regex.getSpacePattern)()})?`, 'gi'), '').replace(new RegExp(`^(?:${(0, _regex.getSpacePattern)()})?(?:${code}|\\${symbol})`, 'gi'), '').replace(new RegExp(`^(?:-)(?:${(0, _regex.getSpacePattern)()})?`, 'gi'), '').replace(new RegExp(`(?:${(0, _regex.getSpacePattern)()})?(?:${code}|\\${symbol})$`, 'gi'), '').trim();
|
|
61
|
+
}
|
|
62
|
+
#getTerritory(locale) {
|
|
63
|
+
const maxLocale = this.getGlobalize(locale).cldr.supplemental(['likelySubtags', locale]) || locale;
|
|
64
|
+
return maxLocale.split(/[-_ ]/).pop();
|
|
65
|
+
}
|
|
66
|
+
#getCurrencyCode(locale) {
|
|
67
|
+
const territory = this.#getTerritory(locale);
|
|
68
|
+
const currencyData = this.getGlobalize(locale).cldr.supplemental('currencyData');
|
|
69
|
+
const currencies = currencyData.region[territory];
|
|
70
|
+
if (currencies) {
|
|
71
|
+
const currency = currencies.find(currency => {
|
|
72
|
+
const values = Object.values(currency)[0];
|
|
73
|
+
return !values._tender && (!values._to || new Date(values._to) >= new Date());
|
|
74
|
+
});
|
|
75
|
+
return currency ? Object.keys(currency)[0] : 'USD';
|
|
76
|
+
}
|
|
77
|
+
return 'USD';
|
|
78
|
+
}
|
|
79
|
+
#getCurrencySymbol(locale, currencyCode) {
|
|
80
|
+
const currencyData = this.getGlobalize(locale).cldr.main(`numbers/currencies/${currencyCode}`);
|
|
81
|
+
return currencyData?.symbol || '$';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* check whether the given value is a valid currency of default locale
|
|
86
|
+
*
|
|
87
|
+
* @param {String} string
|
|
88
|
+
* @returns {Boolean}
|
|
89
|
+
*/
|
|
90
|
+
#isDefaultCurrency(string) {
|
|
91
|
+
return this.#isValidCurrency(this.defaultLocale(), string);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.default = CurrencyValidator;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _luxon = require("luxon");
|
|
8
|
+
var _base = _interopRequireDefault(require("./base.js"));
|
|
9
|
+
var _chronoNode = require("../../utils/dateUtils/chronoNode.js");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
class DateValidator extends _base.default {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('date');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @override
|
|
19
|
+
*/
|
|
20
|
+
validate(string) {
|
|
21
|
+
return this.#isDefaultDate(string) || this.isInternationalized(string);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @override
|
|
27
|
+
*/
|
|
28
|
+
isInternationalized(string) {
|
|
29
|
+
return this.#isValidDate(this.isQaLocale() ? this.defaultLocale() : this.currentLocale(), string);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @override
|
|
35
|
+
*/
|
|
36
|
+
buildConfig() {}
|
|
37
|
+
#isValidDate(locale, string) {
|
|
38
|
+
return this.#verifyUsingGlobalize(locale, string) || this.#verifyUsingLuxon(locale, string) || this.#verifyUsingChrono(locale, string);
|
|
39
|
+
}
|
|
40
|
+
#isDefaultDate(string) {
|
|
41
|
+
return this.#isValidDate(this.defaultLocale(), string);
|
|
42
|
+
}
|
|
43
|
+
#verifyUsingGlobalize(locale, string) {
|
|
44
|
+
const formats = ['short', 'medium', 'long', 'full'];
|
|
45
|
+
for (let format of formats) {
|
|
46
|
+
// Try parsing as date
|
|
47
|
+
const dateParser = this.getGlobalize(locale).dateParser({
|
|
48
|
+
date: format
|
|
49
|
+
});
|
|
50
|
+
if (dateParser(string)) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
#verifyUsingLuxon(locale, string) {
|
|
57
|
+
const formats = [_luxon.DateTime.DATE_SHORT, _luxon.DateTime.DATE_MED, _luxon.DateTime.DATE_FULL, _luxon.DateTime.DATE_HUGE, _luxon.DateTime.DATE_MED_WITH_WEEKDAY];
|
|
58
|
+
for (let format of formats) {
|
|
59
|
+
const parsed = _luxon.DateTime.fromFormat(string, format, {
|
|
60
|
+
locale
|
|
61
|
+
});
|
|
62
|
+
if (parsed.isValid) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
#verifyUsingChrono(locale, string) {
|
|
69
|
+
return (0, _chronoNode.isValid)(this.isQaLocale() ? this.defaultLocale() : locale, string);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.default = DateValidator;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _luxon = require("luxon");
|
|
8
|
+
var _base = _interopRequireDefault(require("./base.js"));
|
|
9
|
+
var _chronoNode = require("../../utils/dateUtils/chronoNode.js");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
class DateTimeValidator extends _base.default {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('dateTime');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @override
|
|
19
|
+
*/
|
|
20
|
+
validate(string) {
|
|
21
|
+
return this.#isDefaultDateTime(string) || this.isInternationalized(string);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @override
|
|
27
|
+
*/
|
|
28
|
+
isInternationalized(string) {
|
|
29
|
+
return this.#isValidDateTime(this.isQaLocale() ? this.defaultLocale() : this.currentLocale(), string);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @override
|
|
35
|
+
*/
|
|
36
|
+
buildConfig() {}
|
|
37
|
+
#isValidDateTime(locale, string) {
|
|
38
|
+
return this.#verifyUsingGlobalize(locale, string) || this.#verifyUsingLuxon(locale, string) || this.#verifyUsingChrono(locale, string);
|
|
39
|
+
}
|
|
40
|
+
#isDefaultDateTime(string) {
|
|
41
|
+
return this.#isValidDateTime(this.defaultLocale(), string);
|
|
42
|
+
}
|
|
43
|
+
#verifyUsingGlobalize(locale, string) {
|
|
44
|
+
const formats = ['short', 'medium', 'long', 'full'];
|
|
45
|
+
for (let format of formats) {
|
|
46
|
+
// Try parsing as time
|
|
47
|
+
const timeParser = this.getGlobalize(locale).dateParser({
|
|
48
|
+
datetime: format
|
|
49
|
+
});
|
|
50
|
+
if (timeParser(string)) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
#verifyUsingLuxon(locale, string) {
|
|
57
|
+
const formats = [_luxon.DateTime.DATETIME_SHORT, _luxon.DateTime.DATETIME_SHORT_WITH_SECONDS, _luxon.DateTime.DATETIME_MED, _luxon.DateTime.DATETIME_MED_WITH_SECONDS, _luxon.DateTime.DATETIME_MED_WITH_WEEKDAY, _luxon.DateTime.DATETIME_FULL, _luxon.DateTime.DATETIME_FULL_WITH_SECONDS, _luxon.DateTime.DATETIME_HUGE, _luxon.DateTime.DATETIME_HUGE_WITH_SECONDS];
|
|
58
|
+
for (let format of formats) {
|
|
59
|
+
const parsed = _luxon.DateTime.fromFormat(string, format, {
|
|
60
|
+
locale
|
|
61
|
+
});
|
|
62
|
+
if (parsed.isValid) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
#verifyUsingChrono(locale, string) {
|
|
69
|
+
return (0, _chronoNode.isValid)(this.isQaLocale() ? this.defaultLocale() : locale, string);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.default = DateTimeValidator;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _constants = require("../../utils/constants.js");
|
|
8
|
+
var _config = _interopRequireDefault(require("../config.js"));
|
|
9
|
+
var _currency = _interopRequireDefault(require("./currency.js"));
|
|
10
|
+
var _date = _interopRequireDefault(require("./date.js"));
|
|
11
|
+
var _datetime = _interopRequireDefault(require("./datetime.js"));
|
|
12
|
+
var _number = _interopRequireDefault(require("./number.js"));
|
|
13
|
+
var _percentage = _interopRequireDefault(require("./percentage.js"));
|
|
14
|
+
var _string = _interopRequireDefault(require("./string.js"));
|
|
15
|
+
var _time = _interopRequireDefault(require("./time.js"));
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
class Validator {
|
|
18
|
+
static #issuesMap = {};
|
|
19
|
+
/**
|
|
20
|
+
* Collection of methods to validate and determine string issues
|
|
21
|
+
* @type {StringValidator}
|
|
22
|
+
*/
|
|
23
|
+
static #string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Collection of methods to validate and determine number issues
|
|
27
|
+
* @type {NumberValidator}
|
|
28
|
+
*/
|
|
29
|
+
static #number;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Collection of methods to validate and determine date issues
|
|
33
|
+
* @type {DateValidator}
|
|
34
|
+
*/
|
|
35
|
+
static #date;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Collection of methods to validate and determine date issues
|
|
39
|
+
* @type {TimeValidator}
|
|
40
|
+
*/
|
|
41
|
+
static #time;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Collection of methods to validate and determine dateTime issues
|
|
45
|
+
* @type {DateTimeValidator}
|
|
46
|
+
*/
|
|
47
|
+
static #dateTime;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Collection of methods to validate and determine currency issues
|
|
51
|
+
* @type {CurrencyValidator}
|
|
52
|
+
*/
|
|
53
|
+
static #currency;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Collection of methods to validate and determine percentage issues
|
|
57
|
+
* @type {PercentageValidator}
|
|
58
|
+
*/
|
|
59
|
+
static #percentage;
|
|
60
|
+
static load() {
|
|
61
|
+
Validator.#string = new _string.default();
|
|
62
|
+
Validator.#number = new _number.default();
|
|
63
|
+
Validator.#date = new _date.default();
|
|
64
|
+
Validator.#time = new _time.default();
|
|
65
|
+
Validator.#dateTime = new _datetime.default();
|
|
66
|
+
Validator.#currency = new _currency.default();
|
|
67
|
+
Validator.#percentage = new _percentage.default();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param {String} string
|
|
72
|
+
* @returns {Promise<String>} issue type
|
|
73
|
+
*/
|
|
74
|
+
static getIssueType(string) {
|
|
75
|
+
const locale = _config.default.getLocale();
|
|
76
|
+
if (locale) {
|
|
77
|
+
let type = _constants.I18N_STATUS.UNTRANSLATED;
|
|
78
|
+
if (!Validator.#issuesMap[locale]) {
|
|
79
|
+
Validator.#issuesMap[locale] = {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// return from cache
|
|
83
|
+
if (Validator.#issuesMap[locale][string]) {
|
|
84
|
+
return Validator.#issuesMap[locale][string];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// handle DNT, Auto Ignored, Ignored and Encoding cases
|
|
88
|
+
if (this.#string.isAutoIgnoredText(string)) {
|
|
89
|
+
type = _constants.I18N_STATUS.AUTO_IGNORE;
|
|
90
|
+
} else if (this.#string.isDntText(string)) {
|
|
91
|
+
type = _constants.I18N_STATUS.DNT;
|
|
92
|
+
} else if (this.#string.isIgnoredText(string)) {
|
|
93
|
+
type = _constants.I18N_STATUS.IGNORE;
|
|
94
|
+
} else if (this.#string.hasEncodingIssue(string)) {
|
|
95
|
+
type = _constants.I18N_STATUS.ENCODING_ISSUE;
|
|
96
|
+
}
|
|
97
|
+
// handle currency cases
|
|
98
|
+
else if (this.#currency.validate(string)) {
|
|
99
|
+
type = this.#currency.isInternationalized(string) ? _constants.I18N_STATUS.CURRENCY_LOCALIZED : _constants.I18N_STATUS.CURRENCY_NOT_LOCALIZED;
|
|
100
|
+
}
|
|
101
|
+
// handle percentage cases
|
|
102
|
+
else if (this.#percentage.validate(string)) {
|
|
103
|
+
type = this.#percentage.isInternationalized(string) ? _constants.I18N_STATUS.PERCENTAGE_LOCALIZED : _constants.I18N_STATUS.PERCENTAGE_NOT_LOCALIZED;
|
|
104
|
+
}
|
|
105
|
+
//handle number cases
|
|
106
|
+
else if (this.#number.validate(string)) {
|
|
107
|
+
type = this.#number.isInternationalized(string) ? _constants.I18N_STATUS.NUMBER_LOCALIZED : _constants.I18N_STATUS.NUMBER_NOT_LOCALIZED;
|
|
108
|
+
}
|
|
109
|
+
// handle date cases
|
|
110
|
+
else if (this.#date.validate(string)) {
|
|
111
|
+
type = this.#date.isInternationalized(string) ? _constants.I18N_STATUS.DATE_LOCALIZED : _constants.I18N_STATUS.DATE_NOT_LOCALIZED;
|
|
112
|
+
}
|
|
113
|
+
// handle time cases
|
|
114
|
+
else if (this.#time.validate(string)) {
|
|
115
|
+
type = this.#time.isInternationalized(string) ? _constants.I18N_STATUS.TIME_LOCALIZED : _constants.I18N_STATUS.TIME_NOT_LOCALIZED;
|
|
116
|
+
}
|
|
117
|
+
// handle dateTime cases
|
|
118
|
+
else if (this.#dateTime.validate(string)) {
|
|
119
|
+
type = this.#dateTime.isInternationalized(string) ? _constants.I18N_STATUS.DATE_TIME_LOCALIZED : _constants.I18N_STATUS.DATE_TIME_NOT_LOCALIZED;
|
|
120
|
+
}
|
|
121
|
+
// handle string cases
|
|
122
|
+
else if (this.#string.validate(string)) {
|
|
123
|
+
// handle QA strings
|
|
124
|
+
if (this.#string.isQaLocale()) {
|
|
125
|
+
if (this.#string.isFullQaLanguageText(string)) {
|
|
126
|
+
type = _constants.I18N_STATUS.STRING_LOCALIZED;
|
|
127
|
+
} else if (this.#string.isPartialQaLanguageText(string)) {
|
|
128
|
+
type = _constants.I18N_STATUS.STRING_PARTIALLY_LOCALIZED;
|
|
129
|
+
} else {
|
|
130
|
+
type = _constants.I18N_STATUS.STRING_NOT_LOCALIZED;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// handle string i18n cases
|
|
134
|
+
else if (!this.#string.isDefaultLocale() && this.#string.isSupportedLocale()) {
|
|
135
|
+
if (this.#string.isLocalized(string)) {
|
|
136
|
+
type = _constants.I18N_STATUS.STRING_LOCALIZED;
|
|
137
|
+
} else if (this.#string.isPartiallyLocalizedText(string)) {
|
|
138
|
+
type = _constants.I18N_STATUS.STRING_PARTIALLY_LOCALIZED;
|
|
139
|
+
} else if (!this.#string.isInternationalized(string)) {
|
|
140
|
+
type = _constants.I18N_STATUS.STRING_NOT_LOCALIZED;
|
|
141
|
+
} else {
|
|
142
|
+
type = _constants.I18N_STATUS.UNTRANSLATED;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} else if (this.#string.isDefaultLocale()) {
|
|
146
|
+
type = _constants.I18N_STATUS.AUTO_IGNORE;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// add to cache
|
|
150
|
+
Validator.#issuesMap[locale][string] = type;
|
|
151
|
+
return type;
|
|
152
|
+
}
|
|
153
|
+
return _constants.I18N_STATUS.UNTRANSLATED;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.default = Validator;
|