]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
dom/manipulator.js: minor simplification. (#28358)
authorXhmikosR <xhmikosr@gmail.com>
Tue, 26 Feb 2019 11:13:01 +0000 (13:13 +0200)
committerGitHub <noreply@github.com>
Tue, 26 Feb 2019 11:13:01 +0000 (13:13 +0200)
Combine two checks since we return the same value for both.

js/src/dom/manipulator.js

index 31d0252c651d126e2ef93e9737e9cef177164f7f..6c7df694257e66809ea9e16f0b501487857292de 100644 (file)
@@ -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) {