UNPKG

@bookbox/core

Version:

Bookbox — e-book format

21 lines (20 loc) 524 B
/** * разбивает текст по границам пробельных символов */ export function getTextTokens(text) { const notWords = text.match(/\s+/g); if (!notWords) { return [text]; } const tokens = []; let tail = text; for (const notWord of notWords) { const i = tail.indexOf(notWord); tokens.push(tail.slice(0, i), notWord); tail = tail.slice(i + notWord.length); } if (tail) { tokens.push(tail); } return tokens; }