/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/lib/string/index.ts
39 строк
978 B
Mehmood Ahmad
Reader: Fix previewing of feed items in List (#108223)
28 янв 2026, 12:51
Не верифицирован
28 янв 2026, 12:51
b6dfe7a
Код
Авторство
О чём код?
/** * Are two strings equal, when ignoring whitespace and case? * @param {string} a the first string * @param {string} b the second string */ export function areEqualIgnoringWhitespaceAndCase( a: string, b: string ) { // Are they equal without any manipulation? if ( a === b ) { return true; } // If we don't have strings for this part, bail out if ( ! a || ! b ) { return false; } a = a.replace( /[\s'.\-_"]/g, '' ); b = b.replace( /[\s'.\-_"]/g, '' ); return a.toLowerCase() === b.toLowerCase(); } export function getFirstGrapheme( input: string ) { if ( 'Segmenter' in Intl ) { const segmenter = new Intl.Segmenter(); const [ firstSegmentData ] = segmenter.segment( input ); return firstSegmentData?.segment ?? ''; } const codePoint = input.codePointAt( 0 ); if ( codePoint ) { return String.fromCodePoint( codePoint ); } return ''; } export function removeTrailingSlash( str: string = '' ): string { return str.replace( /\/+$/, '' ); }