diff --git a/src/button/index.tsx b/src/button/index.tsx index b130f3fe4..6d43b461a 100644 --- a/src/button/index.tsx +++ b/src/button/index.tsx @@ -124,7 +124,7 @@ export default createComponent({ } // hide border when color is linear-gradient - if (color.indexOf('gradient') !== -1) { + if (color.includes('gradient')) { style.border = 0; } else { style.borderColor = color; diff --git a/src/cascader/index.tsx b/src/cascader/index.tsx index 547dd9abb..6e10b74a4 100644 --- a/src/cascader/index.tsx +++ b/src/cascader/index.tsx @@ -252,7 +252,7 @@ export default createComponent({ const values = state.tabs.map( (tab) => tab.selectedOption?.[valueKey] ); - if (values.indexOf(value) !== -1) { + if (values.includes(value)) { return; } } diff --git a/src/checkbox/index.tsx b/src/checkbox/index.tsx index f63e50ad0..de8341ed7 100644 --- a/src/checkbox/index.tsx +++ b/src/checkbox/index.tsx @@ -36,7 +36,7 @@ export default createComponent({ if (checked) { const overlimit = max && value.length >= max; - if (!overlimit && value.indexOf(name) === -1) { + if (!overlimit && !value.includes(name)) { value.push(name); if (props.bindGroup) { diff --git a/src/collapse/index.tsx b/src/collapse/index.tsx index a5b0237be..cbefdf1b2 100644 --- a/src/collapse/index.tsx +++ b/src/collapse/index.tsx @@ -73,7 +73,7 @@ export default createComponent({ return accordion ? modelValue === name - : (modelValue as Array).indexOf(name) !== -1; + : (modelValue as Array).includes(name); }; linkChildren({ toggle, isExpanded }); diff --git a/src/count-down/utils.ts b/src/count-down/utils.ts index ce66f1fbb..772032dac 100644 --- a/src/count-down/utils.ts +++ b/src/count-down/utils.ts @@ -5,36 +5,36 @@ export function parseFormat(format: string, currentTime: CurrentTime): string { const { days } = currentTime; let { hours, minutes, seconds, milliseconds } = currentTime; - if (format.indexOf('DD') === -1) { - hours += days * 24; - } else { + if (format.includes('DD')) { format = format.replace('DD', padZero(days)); + } else { + hours += days * 24; } - if (format.indexOf('HH') === -1) { - minutes += hours * 60; - } else { + if (format.includes('HH')) { format = format.replace('HH', padZero(hours)); + } else { + minutes += hours * 60; } - if (format.indexOf('mm') === -1) { - seconds += minutes * 60; - } else { + if (format.includes('mm')) { format = format.replace('mm', padZero(minutes)); - } - - if (format.indexOf('ss') === -1) { - milliseconds += seconds * 1000; } else { - format = format.replace('ss', padZero(seconds)); + seconds += minutes * 60; } - if (format.indexOf('S') !== -1) { + if (format.includes('ss')) { + format = format.replace('ss', padZero(seconds)); + } else { + milliseconds += seconds * 1000; + } + + if (format.includes('S')) { const ms = padZero(milliseconds, 3); - if (format.indexOf('SSS') !== -1) { + if (format.includes('SSS')) { format = format.replace('SSS', ms); - } else if (format.indexOf('SS') !== -1) { + } else if (format.includes('SS')) { format = format.replace('SS', ms.slice(0, 2)); } else { format = format.replace('S', ms.charAt(0)); diff --git a/src/empty/index.tsx b/src/empty/index.tsx index 520f5ee7d..e32c0335b 100644 --- a/src/empty/index.tsx +++ b/src/empty/index.tsx @@ -27,7 +27,7 @@ export default createComponent({ return Network; } - if (PRESET_IMAGES.indexOf(image) !== -1) { + if (PRESET_IMAGES.includes(image)) { image = `https://img01.yzcdn.cn/vant/empty-image-${image}.png`; } diff --git a/src/form/index.tsx b/src/form/index.tsx index c022baee0..82fe71824 100644 --- a/src/form/index.tsx +++ b/src/form/index.tsx @@ -50,7 +50,7 @@ export default createComponent({ const getFieldsByNames = (names?: string[]) => { if (names) { - return children.filter((field) => names.indexOf(field.name) !== -1); + return children.filter((field) => names.includes(field.name)); } return children; }; diff --git a/src/icon/index.tsx b/src/icon/index.tsx index 82849f5bb..3e65ca84e 100644 --- a/src/icon/index.tsx +++ b/src/icon/index.tsx @@ -5,7 +5,7 @@ import Badge from '../badge'; const [createComponent, bem] = createNamespace('icon'); function isImage(name?: string) { - return name ? name.indexOf('/') !== -1 : false; + return name ? name.includes('/') : false; } export default createComponent({ diff --git a/src/pull-refresh/index.tsx b/src/pull-refresh/index.tsx index a3b51c80b..45b9b4c54 100644 --- a/src/pull-refresh/index.tsx +++ b/src/pull-refresh/index.tsx @@ -121,7 +121,7 @@ export default createComponent({ const nodes = []; - if (TEXT_STATUS.indexOf(status) !== -1) { + if (TEXT_STATUS.includes(status)) { nodes.push(
{getStatusText()}
); } if (status === 'loading') { diff --git a/src/share-sheet/index.tsx b/src/share-sheet/index.tsx index 541063de0..d3ade3033 100644 --- a/src/share-sheet/index.tsx +++ b/src/share-sheet/index.tsx @@ -34,7 +34,7 @@ const popupKeys = [ ] as const; function getIconURL(icon: string) { - if (PRESET_ICONS.indexOf(icon) !== -1) { + if (PRESET_ICONS.includes(icon)) { return `https://img01.yzcdn.cn/vant/share-sheet-${icon}.png`; } return icon; diff --git a/src/stepper/index.tsx b/src/stepper/index.tsx index 74d84df47..3653c42d1 100644 --- a/src/stepper/index.tsx +++ b/src/stepper/index.tsx @@ -190,7 +190,7 @@ export default createComponent({ let formatted = formatNumber(String(value), !props.integer); // limit max decimal length - if (isDef(decimalLength) && formatted.indexOf('.') !== -1) { + if (isDef(decimalLength) && formatted.includes('.')) { const pair = formatted.split('.'); formatted = `${pair[0]}.${pair[1].slice(0, +decimalLength)}`; } diff --git a/src/tree-select/index.tsx b/src/tree-select/index.tsx index abedfef3e..9134e1fd1 100644 --- a/src/tree-select/index.tsx +++ b/src/tree-select/index.tsx @@ -65,7 +65,7 @@ export default createComponent({ setup(props, { emit, slots }) { const isActiveItem = (id: number | string) => { return Array.isArray(props.activeId) - ? props.activeId.indexOf(id) !== -1 + ? props.activeId.includes(id) : props.activeId === id; }; diff --git a/src/utils/format/unit.ts b/src/utils/format/unit.ts index 5b0aaede8..3444a527b 100644 --- a/src/utils/format/unit.ts +++ b/src/utils/format/unit.ts @@ -66,13 +66,13 @@ export function unitToPx(value: string | number): number { } if (inBrowser) { - if (value.indexOf('rem') !== -1) { + if (value.includes('rem')) { return convertRem(value); } - if (value.indexOf('vw') !== -1) { + if (value.includes('vw')) { return convertVw(value); } - if (value.indexOf('vh') !== -1) { + if (value.includes('vh')) { return convertVh(value); } }