All files / roosterjs-content-model-dom/lib/modelApi/common hasSpacesOnly.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13    1x             1x 3338x    
// A regex to match text that only has space and CR
// We use real space char " " (\u0020) here but not "\s" since "\s" will also match " " (\u00A0) which is something we need to keep
const SPACE_TEXT_REGEX = /^[\r\n\t ]*$/;
 
/**
 * @internal
 * Check if the given string only has space, including line breaks.
 * @param txt The string to check
 */
export function hasSpacesOnly(txt: string): boolean {
    return SPACE_TEXT_REGEX.test(txt);
}