diff options
author | XhmikosR <xhmikosr@gmail.com> | 2019-02-26 14:13:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-26 14:13:01 +0300 |
commit | f7b55da4509e62b559f1e8181cf4b03e964775a4 (patch) | |
tree | 3d03d625096f708396b18f6258ead11d24d08046 /js | |
parent | 7933ee32821bbdf606be5e2d526b27a05934b53b (diff) |
dom/manipulator.js: minor simplification. (#28358)
Combine two checks since we return the same value for both.
Diffstat (limited to 'js')
-rw-r--r-- | js/src/dom/manipulator.js | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/js/src/dom/manipulator.js b/js/src/dom/manipulator.js index 31d0252c65..6c7df69425 100644 --- a/js/src/dom/manipulator.js +++ b/js/src/dom/manipulator.js @@ -5,18 +5,20 @@ * -------------------------------------------------------------------------- */ -const regexDataKey = /[A-Z]/g - function normalizeData(val) { if (val === 'true') { return true - } else if (val === 'false') { + } + + if (val === 'false') { return false - } else if (val === 'null') { - return null - } else if (val === Number(val).toString()) { + } + + if (val === Number(val).toString()) { return Number(val) - } else if (val === '') { + } + + if (val === '' || val === 'null') { return null } @@ -24,7 +26,7 @@ function normalizeData(val) { } function normalizeDataKey(key) { - return key.replace(regexDataKey, (chr) => chr.toLowerCase()) + return key.replace(/[A-Z]/g, (chr) => chr.toLowerCase()) } const Manipulator = { @@ -45,18 +47,15 @@ const Manipulator = { ...element.dataset } - Object.keys(attributes) - .forEach((key) => { - attributes[key] = normalizeData(attributes[key]) - }) + Object.keys(attributes).forEach((key) => { + attributes[key] = normalizeData(attributes[key]) + }) return attributes }, getDataAttribute(element, key) { - return normalizeData(element - .getAttribute(`data-${normalizeDataKey(key)}`) - ) + return normalizeData(element.getAttribute(`data-${normalizeDataKey(key)}`)) }, offset(element) { |