json-joy
Version:
Collection of libraries for building collaborative editing apps.
24 lines (23 loc) • 788 B
JavaScript
const LETTER_REGEX = /(\p{Letter}|\d|_)/u;
const WHITESPACE_REGEX = /\s/;
export const isLetter = (char) => LETTER_REGEX.test(char[0]);
export const isWhitespace = (char) => WHITESPACE_REGEX.test(char[0]);
export const isPunctuation = (char) => !isLetter(char) && !isWhitespace(char);
/**
* Compares two block slice types, ignores tag discriminants.
*/
export 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;
};