@zeesoft/i18n-verify 2.1.4 → 2.1.7

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.
Files changed (61) hide show
  1. package/dist/genrc.mjs +1 -0
  2. package/dist/i18n.mjs +1 -0
  3. package/dist/index.mjs +1 -0
  4. package/package.json +25 -17
  5. package/postinstall.js +28 -0
  6. package/readme.md +21 -1
  7. package/dist/driver/adapters/cypress.js +0 -161
  8. package/dist/driver/adapters/nightwatch.js +0 -160
  9. package/dist/driver/adapters/selenium.js +0 -90
  10. package/dist/driver/adapters/webdriver.io.js +0 -81
  11. package/dist/driver/baseDriver.js +0 -93
  12. package/dist/driver/factory.js +0 -27
  13. package/dist/index.js +0 -52
  14. package/dist/lib/config.js +0 -102
  15. package/dist/lib/i18n.js +0 -259
  16. package/dist/lib/reports.js +0 -140
  17. package/dist/lib/validator/base.js +0 -125
  18. package/dist/lib/validator/currency.js +0 -94
  19. package/dist/lib/validator/date.js +0 -72
  20. package/dist/lib/validator/datetime.js +0 -72
  21. package/dist/lib/validator/index.js +0 -156
  22. package/dist/lib/validator/number.js +0 -58
  23. package/dist/lib/validator/percentage.js +0 -78
  24. package/dist/lib/validator/string.js +0 -172
  25. package/dist/lib/validator/time.js +0 -72
  26. package/dist/template/report.html +0 -1678
  27. package/dist/utils/cache.js +0 -47
  28. package/dist/utils/common.js +0 -18
  29. package/dist/utils/configFile.js +0 -65
  30. package/dist/utils/constants.js +0 -148
  31. package/dist/utils/cypress.js +0 -120
  32. package/dist/utils/dateUtils/chronoNode.js +0 -52
  33. package/dist/utils/file.js +0 -61
  34. package/dist/utils/graphic.js +0 -57
  35. package/dist/utils/logs.js +0 -79
  36. package/dist/utils/objects/cacheData.js +0 -72
  37. package/dist/utils/objects/metaData.js +0 -29
  38. package/dist/utils/objects/reportData.js +0 -30
  39. package/dist/utils/objects/statData.js +0 -380
  40. package/dist/utils/objects/stringData.js +0 -64
  41. package/dist/utils/objects/stringInfo.js +0 -51
  42. package/dist/utils/regex.js +0 -8
  43. package/dist/utils/reportFactory/base.js +0 -59
  44. package/dist/utils/reportFactory/html/index.js +0 -51
  45. package/dist/utils/reportFactory/html/template/body.js +0 -117
  46. package/dist/utils/reportFactory/html/template/css.js +0 -476
  47. package/dist/utils/reportFactory/html/template/html.js +0 -63
  48. package/dist/utils/reportFactory/html/template/javascript/data.js +0 -66
  49. package/dist/utils/reportFactory/html/template/javascript/global.js +0 -45
  50. package/dist/utils/reportFactory/html/template/javascript/grid.js +0 -129
  51. package/dist/utils/reportFactory/html/template/javascript/index.js +0 -22
  52. package/dist/utils/reportFactory/html/template/javascript/insight.js +0 -248
  53. package/dist/utils/reportFactory/html/template/javascript/log.js +0 -19
  54. package/dist/utils/reportFactory/html/template/javascript/menuBar.js +0 -123
  55. package/dist/utils/reportFactory/html/template/javascript/overview.js +0 -818
  56. package/dist/utils/reportFactory/index.js +0 -36
  57. package/dist/utils/reportFactory/table.js +0 -95
  58. package/dist/utils/resource.js +0 -58
  59. package/dist/utils/runtime.js +0 -36
  60. package/dist/utils/scripts/genreport.js +0 -1
  61. package/dist/utils/scripts/postinstall.js +0 -22
package/dist/lib/i18n.js DELETED
@@ -1,259 +0,0 @@
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("./reports.js"));
11
- var _graphic = _interopRequireDefault(require("../utils/graphic.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.isElementPresent(ele))) {
72
- let str;
73
- try {
74
- str = await this.#driver.getElementString(ele);
75
- try {
76
- await this.#generateReports({
77
- verificationArea,
78
- ele,
79
- img_name,
80
- str,
81
- desc
82
- });
83
- } catch (reportError) {
84
- _logs.default.error('Error generating report of element:', reportError);
85
- }
86
- } catch (textError) {
87
- _logs.default.error('Error getting text of element:', textError);
88
- }
89
- } else {
90
- _logs.default.error('No element found:', locator);
91
- }
92
- }
93
- async #getElements(verificationArea, xpaths, img_name, desc) {
94
- const eles = await this.#driver.getElements(xpaths);
95
- if (eles.length > 0) {
96
- for (const el of eles) {
97
- if (await this.#driver.isElementPresent(el)) {
98
- let uiStrings;
99
- try {
100
- uiStrings = await this.#driver.getElementStrings(el);
101
- try {
102
- for (const str of uiStrings) {
103
- await this.#generateReports({
104
- verificationArea,
105
- el,
106
- img_name,
107
- str,
108
- desc
109
- });
110
- }
111
- } catch (reportError) {
112
- _logs.default.error('Error generating report of element:', reportError);
113
- }
114
- } catch (textError) {
115
- _logs.default.error('Error getting text of elements:', textError);
116
- }
117
- }
118
- }
119
- }
120
- if (await this.#driver.checkIfIframeIsPresent()) {
121
- const iframes = await this.#driver.getElements('//iframe');
122
- _logs.default.debug(`Total ${iframes.length} iframes are located on the ${desc}`);
123
- await this.#verifyIframeElements({
124
- iframes,
125
- img_name,
126
- desc
127
- });
128
- }
129
- }
130
- async #generateReports({
131
- verificationArea,
132
- el,
133
- img_name,
134
- str,
135
- desc,
136
- iframePresent = false
137
- }) {
138
- //TODO: in some cases, the str is having 0
139
- //needs more inspection
140
- if (typeof str !== 'string' || !str || Number(str) === 0) {
141
- return;
142
- }
143
- const i18nStatus = _index.default.getIssueType(str),
144
- src_img = (0, _file.joinPaths)(_reports.default.reviewedReports(str, img_name), img_name);
145
- _reports.default.incrementCount(_constants.I18N_STATUS.REVIEWED, str, src_img, desc);
146
- if (i18nStatus && src_img && typeof _reports.default[i18nStatus] === 'function') {
147
- const color = this.#defineColor(i18nStatus, str),
148
- dest_img = (0, _file.joinPaths)(_reports.default[i18nStatus](str, img_name), img_name);
149
- _reports.default.incrementCount(i18nStatus, str, dest_img, desc);
150
- this.#driver.onScreenStringHighlight(el, color);
151
- await this.#highlightReports({
152
- verificationArea,
153
- el,
154
- color,
155
- src_img,
156
- dest_img,
157
- str,
158
- iframePresent,
159
- desc
160
- });
161
- }
162
- }
163
- async #highlightReports({
164
- verificationArea,
165
- el,
166
- color,
167
- src_img,
168
- dest_img,
169
- str,
170
- iframePresent,
171
- desc
172
- }) {
173
- try {
174
- if (_fs.default.existsSync(src_img) && !_fs.default.existsSync(dest_img)) {
175
- _fs.default.copyFileSync(src_img, dest_img);
176
- } else if (!_fs.default.existsSync(dest_img) && !_fs.default.existsSync(src_img)) {
177
- await this.#captureCurrentScreen(src_img);
178
- _fs.default.copyFileSync(src_img, dest_img);
179
- }
180
- } catch (error) {
181
- _logs.default.error(`zee-error#2 - ${src_img} is not exists and unable to capture screenshot`);
182
- }
183
- let areaRec;
184
- let eleRec = await this.#getRect(el);
185
- const areaColor = _constants.COLOR.GRB_BLUE;
186
- if (iframePresent) {
187
- areaRec = verificationArea;
188
- const keysToUpdate = ['x', 'y'];
189
- for (const key of keysToUpdate) {
190
- if (key in eleRec && key in areaRec) {
191
- eleRec[key] = areaRec[key] + eleRec[key];
192
- }
193
- }
194
- } else {
195
- const area = await this.#driver.getElement(verificationArea);
196
- areaRec = await this.#getRect(area);
197
- }
198
- await _graphic.default.drawRectangle(areaRec, areaColor, dest_img);
199
- await _graphic.default.drawRectangle(eleRec, color, dest_img);
200
- }
201
- async #captureCurrentScreen(imagePath) {
202
- await this.#driver.captureScreenshot(imagePath);
203
- }
204
- async #getRect(el) {
205
- const elObj = await this.#driver.getElementDimension(el);
206
- return {
207
- x: elObj[0],
208
- y: elObj[1],
209
- height: elObj[2],
210
- width: elObj[3]
211
- };
212
- }
213
- #defineColor(i18nStatus, str) {
214
- _logs.default.debug(`${str}${_constants.STATUS_COLOR[i18nStatus][1]} ${_constants.STATUS_INFO[i18nStatus]}${'\x1b[0m'}`);
215
- return _constants.STATUS_COLOR[i18nStatus][0];
216
- }
217
- async #verifyIframeElements({
218
- iframes,
219
- img_name,
220
- desc
221
- }) {
222
- for (const iframe of iframes) {
223
- const frameID = await this.#driver.getElementID(iframe);
224
- if (frameID && frameID !== '') {
225
- const verificationArea = await this.#getRect(iframe);
226
- this.#driver.switchIframe(frameID);
227
- this.#driver.pause(2);
228
- const iframeBody = await this.#driver.getElement('//body');
229
- await this.#driver.isElementPresent(iframeBody);
230
- if (!(await this.#driver.checkIfIframeBodyIsEmpty())) {
231
- const iframeElements = await this.#driver.getElements('//*[normalize-space(text())]');
232
- if (iframeElements.length > 0) {
233
- for (const el of iframeElements) {
234
- if (await this.#driver.isElementPresent(el)) {
235
- let uiStrings = await this.#driver.getElementStrings(el);
236
- try {
237
- for (const str of uiStrings) {
238
- await this.#generateReports({
239
- verificationArea,
240
- el,
241
- img_name,
242
- str,
243
- desc,
244
- iframePresent: true
245
- });
246
- }
247
- } catch (reportError) {
248
- _logs.default.error('Error generating report of iframe elements:', reportError);
249
- }
250
- }
251
- }
252
- }
253
- }
254
- }
255
- await this.#driver.switchToParentframe();
256
- }
257
- }
258
- }
259
- exports.default = I18nVerify;
@@ -1,140 +0,0 @@
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 _config = _interopRequireDefault(require("./config.js"));
9
- var _file = require("../utils/file.js");
10
- var _constants = require("../utils/constants.js");
11
- var _index = _interopRequireDefault(require("../utils/reportFactory/index.js"));
12
- var _cacheData = _interopRequireDefault(require("../utils/objects/cacheData.js"));
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- class Reports {
15
- static #baseReportPath;
16
- static #reportTimeStamp;
17
- static setup() {
18
- Reports.#reportTimeStamp = Reports.#dateTime();
19
- const rootFolder = _path.default.resolve();
20
- Reports.#baseReportPath = (0, _file.joinPaths)(rootFolder, _config.default.getL10nReportsPath(), Reports.#reportTimeStamp);
21
- }
22
- static getReportTimeStamp() {
23
- return Reports.#reportTimeStamp;
24
- }
25
- static getReportPath() {
26
- return Reports.#baseReportPath;
27
- }
28
- static reviewedReports(str = null, imgName = null) {
29
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.REVIEWED, str, imgName);
30
- }
31
- static [_constants.I18N_STATUS.STRING_LOCALIZED](str, imgName) {
32
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.STRING_LOCALIZED, str, imgName);
33
- }
34
- static [_constants.I18N_STATUS.STRING_NOT_LOCALIZED](str, imgName) {
35
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.STRING_NOT_LOCALIZED, str, imgName);
36
- }
37
- static [_constants.I18N_STATUS.STRING_PARTIALLY_LOCALIZED](str, imgName) {
38
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.STRING_PARTIALLY_LOCALIZED, str, imgName);
39
- }
40
- static [_constants.I18N_STATUS.DNT](str, imgName) {
41
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.DNT, str, imgName);
42
- }
43
- static [_constants.I18N_STATUS.IGNORE](str, imgName) {
44
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.IGNORE, str, imgName);
45
- }
46
- static [_constants.I18N_STATUS.AUTO_IGNORE](str, imgName) {
47
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.AUTO_IGNORE, str, imgName);
48
- }
49
- static [_constants.I18N_STATUS.UNTRANSLATED](str, imgName) {
50
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.UNTRANSLATED, str, imgName);
51
- }
52
- static [_constants.I18N_STATUS.ENCODING_ISSUE](str, imgName) {
53
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.ENCODING_ISSUE, str, imgName);
54
- }
55
- static [_constants.I18N_STATUS.DATE_TIME_LOCALIZED](str, imgName) {
56
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.DATE_TIME_LOCALIZED, str, imgName);
57
- }
58
- static [_constants.I18N_STATUS.DATE_TIME_NOT_LOCALIZED](str, imgName) {
59
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.DATE_TIME_NOT_LOCALIZED, str, imgName);
60
- }
61
- static [_constants.I18N_STATUS.DATE_LOCALIZED](str, imgName) {
62
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.DATE_LOCALIZED, str, imgName);
63
- }
64
- static [_constants.I18N_STATUS.DATE_NOT_LOCALIZED](str, imgName) {
65
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.DATE_NOT_LOCALIZED, str, imgName);
66
- }
67
- static [_constants.I18N_STATUS.TIME_LOCALIZED](str, imgName) {
68
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.TIME_LOCALIZED, str, imgName);
69
- }
70
- static [_constants.I18N_STATUS.TIME_NOT_LOCALIZED](str, imgName) {
71
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.TIME_NOT_LOCALIZED, str, imgName);
72
- }
73
- static [_constants.I18N_STATUS.CURRENCY_LOCALIZED](str, imgName) {
74
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.CURRENCY_LOCALIZED, str, imgName);
75
- }
76
- static [_constants.I18N_STATUS.CURRENCY_NOT_LOCALIZED](str, imgName) {
77
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.CURRENCY_NOT_LOCALIZED, str, imgName);
78
- }
79
- static [_constants.I18N_STATUS.PERCENTAGE_LOCALIZED](str, imgName) {
80
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.PERCENTAGE_LOCALIZED, str, imgName);
81
- }
82
- static [_constants.I18N_STATUS.PERCENTAGE_NOT_LOCALIZED](str, imgName) {
83
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.PERCENTAGE_NOT_LOCALIZED, str, imgName);
84
- }
85
- static [_constants.I18N_STATUS.NUMBER_LOCALIZED](str, imgName) {
86
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.NUMBER_LOCALIZED, str, imgName);
87
- }
88
- static [_constants.I18N_STATUS.NUMBER_NOT_LOCALIZED](str, imgName) {
89
- return Reports.#generateFullReportPath(_constants.I18N_STATUS.NUMBER_NOT_LOCALIZED, str, imgName);
90
- }
91
- static incrementCount(type, str, imgPath, desc) {
92
- if (_constants.REPORT_COUNTS.hasOwnProperty(type)) {
93
- _constants.REPORT_COUNTS[type]++;
94
- _cacheData.default.addString(str, type, desc, imgPath.replace(Reports.#baseReportPath, ''));
95
- }
96
- }
97
- static #dateTime() {
98
- const now = new Date();
99
- const year = now.getFullYear();
100
- const month = String(now.getMonth() + 1).padStart(2, '0');
101
- const day = String(now.getDate()).padStart(2, '0');
102
- const hours = String(now.getHours()).padStart(2, '0');
103
- const minutes = String(now.getMinutes()).padStart(2, '0');
104
- const timeStamp = `${year}-${month}-${day}-${hours}-${minutes}`;
105
- return timeStamp;
106
- }
107
- static #generateFullReportPath = (type, str, imgName) => {
108
- const _screenshotPath = (0, _file.joinPaths)(Reports.#baseReportPath, _config.default.getLocale(), 'screenshots', String(type).toLowerCase());
109
- (0, _file.ensureDirectoryExists)(_screenshotPath, _constants.DEBUG_MODE);
110
- const _stringsPath = (0, _file.joinPaths)(Reports.#baseReportPath, _config.default.getLocale(), 'strings');
111
- (0, _file.ensureDirectoryExists)(_stringsPath, _constants.DEBUG_MODE);
112
- if (str !== null && str !== undefined) {
113
- let content = '';
114
- if ((0, _file.pathExists)((0, _file.joinPaths)(_stringsPath, type + '.txt'))) {
115
- const existingContent = (0, _file.getFileContent)((0, _file.joinPaths)(_stringsPath, type + '.txt'));
116
- if (existingContent.includes(imgName)) {
117
- content += str;
118
- } else {
119
- content += `\n|<<<<<<<<<<<<<------${imgName}------>>>>>>>>>>>>>|\n`;
120
- content += str;
121
- }
122
- } else {
123
- content += `\n|<<<<<<<<<<<<<------${imgName}------>>>>>>>>>>>>>|\n`;
124
- content += str;
125
- }
126
- (0, _file.addContentToFile)((0, _file.joinPaths)(_stringsPath, type + '.txt'), content);
127
- }
128
- return _screenshotPath;
129
- };
130
- static #generateReport(type) {
131
- _index.default.export(type, Reports.#baseReportPath);
132
- }
133
- static generateHtml() {
134
- Reports.#generateReport(_constants.SUPPORTED_REPORT_TYPES.HTML);
135
- }
136
- static generateAsciiTable() {
137
- Reports.#generateReport(_constants.SUPPORTED_REPORT_TYPES.ASCII_TABLE);
138
- }
139
- }
140
- exports.default = Reports;
@@ -1,125 +0,0 @@
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;
@@ -1,94 +0,0 @@
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;
@@ -1,72 +0,0 @@
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;