]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Switch to `Set#has()`
authorXhmikosR <xhmikosr@gmail.com>
Sat, 2 May 2020 13:56:23 +0000 (16:56 +0300)
committerXhmikosR <xhmikosr@gmail.com>
Sat, 14 Nov 2020 13:54:50 +0000 (15:54 +0200)
.eslintrc.json
build/build-plugins.js
js/src/dom/event-handler.js
js/src/tooltip.js
js/src/util/sanitizer.js

index a4a22e5cd28d024b9a25ca44ca205db02c982eda..b53ecb1a8546373e97ae4a38818299f2a79f2176 100644 (file)
@@ -55,7 +55,6 @@
     "unicorn/prefer-node-remove": "off",
     "unicorn/prefer-optional-catch-binding": "off",
     "unicorn/prefer-query-selector": "off",
-    "unicorn/prefer-set-has": "off",
     "unicorn/prevent-abbreviations": "off"
   }
 }
index 6d9cdb33244766963a6d4a0490d48b6fd3ac2a3f..1f44a3b856223fd9101feab9205a917692839fff 100644 (file)
@@ -125,17 +125,17 @@ const getConfigByPluginKey = pluginKey => {
   }
 }
 
-const utilObjects = [
+const utilObjects = new Set([
   'Util',
   'Sanitizer'
-]
+])
 
-const domObjects = [
+const domObjects = new Set([
   'Data',
   'EventHandler',
   'Manipulator',
   'SelectorEngine'
-]
+])
 
 const build = async plugin => {
   console.log(`Building ${plugin} plugin...`)
@@ -144,11 +144,11 @@ const build = async plugin => {
   const pluginFilename = path.basename(bsPlugins[plugin])
   let pluginPath = rootPath
 
-  if (utilObjects.includes(plugin)) {
+  if (utilObjects.has(plugin)) {
     pluginPath = `${rootPath}/util/`
   }
 
-  if (domObjects.includes(plugin)) {
+  if (domObjects.has(plugin)) {
     pluginPath = `${rootPath}/dom/`
   }
 
index 64a061ae69acf16780dda46e2f33ab080a7c15fe..439a3f188123870c7276c7338502e53c3e22896d 100644 (file)
@@ -22,7 +22,7 @@ const customEvents = {
   mouseenter: 'mouseover',
   mouseleave: 'mouseout'
 }
-const nativeEvents = [
+const nativeEvents = new Set([
   'click',
   'dblclick',
   'mouseup',
@@ -69,7 +69,7 @@ const nativeEvents = [
   'error',
   'abort',
   'scroll'
-]
+])
 
 /**
  * ------------------------------------------------------------------------
@@ -151,7 +151,7 @@ function normalizeParams(originalTypeEvent, handler, delegationFn) {
     typeEvent = custom
   }
 
-  const isNative = nativeEvents.includes(typeEvent)
+  const isNative = nativeEvents.has(typeEvent)
 
   if (!isNative) {
     typeEvent = originalTypeEvent
@@ -273,7 +273,7 @@ const EventHandler = {
     const $ = getjQuery()
     const typeEvent = event.replace(stripNameRegex, '')
     const inNamespace = event !== typeEvent
-    const isNative = nativeEvents.includes(typeEvent)
+    const isNative = nativeEvents.has(typeEvent)
 
     let jQueryEvent
     let bubbles = true
index e4616f1f19eb189d8b9b7ae4f6d73e4caf2153e7..7b115a69bead6a9f5ada7f38bb7c6139850d8462 100644 (file)
@@ -39,7 +39,7 @@ const DATA_KEY = 'bs.tooltip'
 const EVENT_KEY = `.${DATA_KEY}`
 const CLASS_PREFIX = 'bs-tooltip'
 const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
-const DISALLOWED_ATTRIBUTES = ['sanitize', 'allowList', 'sanitizeFn']
+const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn'])
 
 const DefaultType = {
   animation: 'boolean',
@@ -679,7 +679,7 @@ class Tooltip {
     const dataAttributes = Manipulator.getDataAttributes(this.element)
 
     Object.keys(dataAttributes).forEach(dataAttr => {
-      if (DISALLOWED_ATTRIBUTES.includes(dataAttr)) {
+      if (DISALLOWED_ATTRIBUTES.has(dataAttr)) {
         delete dataAttributes[dataAttr]
       }
     })
index 27c8dcfb6a8dd4157afaa5733fc6b7341346f032..68469285abf265cf2697408b0e3f85a89ae55f30 100644 (file)
@@ -5,7 +5,7 @@
  * --------------------------------------------------------------------------
  */
 
-const uriAttrs = [
+const uriAttrs = new Set([
   'background',
   'cite',
   'href',
@@ -14,7 +14,7 @@ const uriAttrs = [
   'poster',
   'src',
   'xlink:href'
-]
+])
 
 const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i
 
@@ -36,7 +36,7 @@ const allowedAttribute = (attr, allowedAttributeList) => {
   const attrName = attr.nodeName.toLowerCase()
 
   if (allowedAttributeList.includes(attrName)) {
-    if (uriAttrs.includes(attrName)) {
+    if (uriAttrs.has(attrName)) {
       return Boolean(attr.nodeValue.match(SAFE_URL_PATTERN) || attr.nodeValue.match(DATA_URL_PATTERN))
     }