UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

31 lines (30 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stepsEqual = exports.isPunctuation = exports.isWhitespace = exports.isLetter = void 0; const LETTER_REGEX = /(\p{Letter}|\d|_)/u; const WHITESPACE_REGEX = /\s/; const isLetter = (char) => LETTER_REGEX.test(char[0]); exports.isLetter = isLetter; const isWhitespace = (char) => WHITESPACE_REGEX.test(char[0]); exports.isWhitespace = isWhitespace; const isPunctuation = (char) => !(0, exports.isLetter)(char) && !(0, exports.isWhitespace)(char); exports.isPunctuation = isPunctuation; /** * Compares two block slice types, ignores tag discriminants. */ const stepsEqual = (a, b) => { const lenA = a.length; const lenB = b.length; if (lenA !== lenB) return false; for (let i = 0; i < lenA; i++) { const stepA = a[i]; const stepB = b[i]; const tagA = Array.isArray(stepA) ? stepA[0] : stepA; const tagB = Array.isArray(stepB) ? stepB[0] : stepB; if (tagA !== tagB) return false; } return true; }; exports.stepsEqual = stepsEqual;