Closed binary-person closed 3 years ago
pardon me, but there's one more I forgot to mention. the setAttribute
should also be case-insensitive
const { parse } = require('node-html-parser');
const assert = require('assert');
const allLowerCase = parse('<a onclick="listener()"></a>');
allLowerCase.childNodes[0].setAttribute('onCLICK', 'newListener()');
// setAttribute's first argument should be auto-converted to lower case
assert.strictEqual(allLowerCase.toString(), '<a onclick="newListener()"></a>');
const capitalized = parse('<a onClick="listener()"></a>');
capitalized.childNodes[0].setAttribute('onclick', 'newSecondListener()');
// setAttribute should change onclick's attribute regardless of case
assert.strictEqual(capitalized.toString(), '<a onclick="newSecondListener()"></a>');
My bad.
the last test doesn't work, but I think that's alright. thank you!
when parsing, I suggest that the users be given the option to convert all the attributes to lower case because of a performance penalty cost, similar to the option
lowerCaseTagName
.