Skip to content

Commit 953051b

Browse files
committed
js: config.js: Refactor attribute name normalization for i18n data attributes
1 parent 65f7143 commit 953051b

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

isso/js/app/config.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,24 @@ for (var i = 0; i < js.length; i++) {
1717
var attr = js[i].attributes[j];
1818
if (/^data-isso-/.test(attr.name)) {
1919

20+
// Normalize underscores to dashes so that language-specific
21+
// strings can be caught better later on, e.g.
22+
// data-isso-postbox-text-text-PT_BR becomes postbox-text-text-pt-br.
23+
// Also note that attr.name only gives lowercase strings as per HTML
24+
// spec, e.g. data-isso-FOO-Bar becomes foo-bar, but since the test
25+
// environment's jest-environment-jsdom seemingly does not follow
26+
// that convention, convert to lowercase here anyway.
27+
const attrName = attr.name.substring(10)
28+
.replace(/_/g, '-')
29+
.toLowerCase()
30+
2031
// Replace escaped newline characters in the attribute value with actual newline characters
2132
const attrValue = attr.value.replace(/\\n/g, '\n');
2233

2334
try {
24-
// Normalize underscores to dashes so that language-specific
25-
// strings can be caught better later on,
26-
// e.g. data-isso-postbox-text-text-PT_BR becomes
27-
// postbox-text-text-pt-br.
28-
// Also note that attr.name only gives lowercase strings as per
29-
// HTML spec, e.g. data-isso-FOO-Bar becomes foo-bar, but since
30-
// the test environment's jest-environment-jsdom seemingly does
31-
// not follow that convention, convert to lowercase here anyway.
32-
config[attr.name.substring(10)
33-
.replace(/_/g, '-')
34-
.toLowerCase()] = JSON.parse(attrValue);
35+
config[attrName] = JSON.parse(attrValue);
3536
} catch (ex) {
36-
config[attr.name.substring(10)
37-
.replace(/_/g, '-')
38-
.toLowerCase()] = attrValue;
37+
config[attrName] = attrValue;
3938
}
4039
}
4140
}

0 commit comments

Comments
 (0)