π Prefer RegExp#test() over String#match() and RegExp#exec().
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π§π‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.
When you want to know whether a pattern is found in a string, use RegExp#test() instead of String#match() and RegExp#exec(), as it exclusively returns a boolean and therefore is more efficient.
// β
if (string.match(/unicorn/)) {}
// β
if (/unicorn/.exec(string)) {}
// β
if (/unicorn/.test(string)) {}<template>
<!-- β -->
<div v-if="/unicorn/.exec(string)">Vue</div>
<!-- β
-->
<div v-if="/unicorn/.test(string)">Vue</div>
</template>