* Parse a template content and return an array of unique region objects * @param {string} content * @returns {Array}
(content)
| 85 | * @returns {Array} |
| 86 | */ |
| 87 | function parseRegions(content) { |
| 88 | const regionRegex = /{{3}\s*region\s+.*?name=["|']([\w-]+)["|'].*?}{3}?/g; |
| 89 | const translationRegex = /{{3}.*?\stranslation=["|'](i18n.RegionName.([\w-])+)["|'].*?}{3}?/g; |
| 90 | const regions = new Set(); |
| 91 | let regionMatch; |
| 92 | const translationMatch = translationRegex.exec(content); |
| 93 | // eslint-disable-next-line |
| 94 | while ((regionMatch = regionRegex.exec(content))) { |
| 95 | const regionData = {}; |
| 96 | // eslint-disable-next-line prefer-destructuring |
| 97 | regionData.name = regionMatch[1]; |
| 98 | // If there is a translation match and regionName match is valid, add data to region |
| 99 | if (translationMatch && regionMatch[1]) { |
| 100 | // eslint-disable-next-line prefer-destructuring |
| 101 | regionData.translation = translationMatch[1]; |
| 102 | } |
| 103 | if (!checkDuplicateRegionName(regions, regionData)) { |
| 104 | regions.add(regionData); |
| 105 | } |
| 106 | } |
| 107 | const regionArray = Array.from(regions); |
| 108 | return regionArray.map(({ name, translation }) => ({ name, translation })); |
| 109 | } |
| 110 | /** |
| 111 | * Returns an object of regions for the manifest file |
| 112 | * @param {Object} templates |
no test coverage detected