UNPKG

naive-ui

Version:

A Vue 3 Component Library. Fairly Complete, Theme Customizable, Uses TypeScript, Fast

34 lines (33 loc) 882 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.splitAndMarkByRegex = splitAndMarkByRegex; // Generated by ChatGPT function splitAndMarkByRegex(str, regex) { const result = []; let lastIndex = 0; let match; // eslint-disable-next-line no-cond-assign while ((match = regex.exec(str)) !== null) { if (match.index > lastIndex) { result.push({ text: str.slice(lastIndex, match.index), isMatch: false }); } result.push({ text: match[0], isMatch: true }); lastIndex = regex.lastIndex; if (!regex.global) { break; } } if (lastIndex < str.length) { result.push({ text: str.slice(lastIndex), isMatch: false }); } return result; }