Switch to `Set#has()`

This commit is contained in:
XhmikosR 2020-05-02 16:56:23 +03:00
parent 2e758f64cf
commit 6d7bc54d22
5 changed files with 15 additions and 16 deletions

View File

@ -55,7 +55,6 @@
"unicorn/prefer-node-remove": "off", "unicorn/prefer-node-remove": "off",
"unicorn/prefer-optional-catch-binding": "off", "unicorn/prefer-optional-catch-binding": "off",
"unicorn/prefer-query-selector": "off", "unicorn/prefer-query-selector": "off",
"unicorn/prefer-set-has": "off",
"unicorn/prevent-abbreviations": "off" "unicorn/prevent-abbreviations": "off"
} }
} }

View File

@ -125,17 +125,17 @@ const getConfigByPluginKey = pluginKey => {
} }
} }
const utilObjects = [ const utilObjects = new Set([
'Util', 'Util',
'Sanitizer' 'Sanitizer'
] ])
const domObjects = [ const domObjects = new Set([
'Data', 'Data',
'EventHandler', 'EventHandler',
'Manipulator', 'Manipulator',
'SelectorEngine' 'SelectorEngine'
] ])
const build = async plugin => { const build = async plugin => {
console.log(`Building ${plugin} plugin...`) console.log(`Building ${plugin} plugin...`)
@ -144,11 +144,11 @@ const build = async plugin => {
const pluginFilename = path.basename(bsPlugins[plugin]) const pluginFilename = path.basename(bsPlugins[plugin])
let pluginPath = rootPath let pluginPath = rootPath
if (utilObjects.includes(plugin)) { if (utilObjects.has(plugin)) {
pluginPath = `${rootPath}/util/` pluginPath = `${rootPath}/util/`
} }
if (domObjects.includes(plugin)) { if (domObjects.has(plugin)) {
pluginPath = `${rootPath}/dom/` pluginPath = `${rootPath}/dom/`
} }

View File

@ -22,7 +22,7 @@ const customEvents = {
mouseenter: 'mouseover', mouseenter: 'mouseover',
mouseleave: 'mouseout' mouseleave: 'mouseout'
} }
const nativeEvents = [ const nativeEvents = new Set([
'click', 'click',
'dblclick', 'dblclick',
'mouseup', 'mouseup',
@ -69,7 +69,7 @@ const nativeEvents = [
'error', 'error',
'abort', 'abort',
'scroll' 'scroll'
] ])
/** /**
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
@ -151,7 +151,7 @@ function normalizeParams(originalTypeEvent, handler, delegationFn) {
typeEvent = custom typeEvent = custom
} }
const isNative = nativeEvents.includes(typeEvent) const isNative = nativeEvents.has(typeEvent)
if (!isNative) { if (!isNative) {
typeEvent = originalTypeEvent typeEvent = originalTypeEvent
@ -273,7 +273,7 @@ const EventHandler = {
const $ = getjQuery() const $ = getjQuery()
const typeEvent = event.replace(stripNameRegex, '') const typeEvent = event.replace(stripNameRegex, '')
const inNamespace = event !== typeEvent const inNamespace = event !== typeEvent
const isNative = nativeEvents.includes(typeEvent) const isNative = nativeEvents.has(typeEvent)
let jQueryEvent let jQueryEvent
let bubbles = true let bubbles = true

View File

@ -39,7 +39,7 @@ const DATA_KEY = 'bs.tooltip'
const EVENT_KEY = `.${DATA_KEY}` const EVENT_KEY = `.${DATA_KEY}`
const CLASS_PREFIX = 'bs-tooltip' const CLASS_PREFIX = 'bs-tooltip'
const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g') 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 = { const DefaultType = {
animation: 'boolean', animation: 'boolean',
@ -679,7 +679,7 @@ class Tooltip {
const dataAttributes = Manipulator.getDataAttributes(this.element) const dataAttributes = Manipulator.getDataAttributes(this.element)
Object.keys(dataAttributes).forEach(dataAttr => { Object.keys(dataAttributes).forEach(dataAttr => {
if (DISALLOWED_ATTRIBUTES.includes(dataAttr)) { if (DISALLOWED_ATTRIBUTES.has(dataAttr)) {
delete dataAttributes[dataAttr] delete dataAttributes[dataAttr]
} }
}) })

View File

@ -5,7 +5,7 @@
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
const uriAttrs = [ const uriAttrs = new Set([
'background', 'background',
'cite', 'cite',
'href', 'href',
@ -14,7 +14,7 @@ const uriAttrs = [
'poster', 'poster',
'src', 'src',
'xlink:href' 'xlink:href'
] ])
const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i
@ -36,7 +36,7 @@ const allowedAttribute = (attr, allowedAttributeList) => {
const attrName = attr.nodeName.toLowerCase() const attrName = attr.nodeName.toLowerCase()
if (allowedAttributeList.includes(attrName)) { 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)) return Boolean(attr.nodeValue.match(SAFE_URL_PATTERN) || attr.nodeValue.match(DATA_URL_PATTERN))
} }