From baae8b6f23523459187dd53cbfc561cb604d43a7 Mon Sep 17 00:00:00 2001 From: mesqueeb Date: Wed, 5 Jun 2024 10:38:09 +0900 Subject: [PATCH] feat: add russian language support (@lordoys) --- src/utils.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 33845cc..865aae9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,7 +4,8 @@ // lower case ranges // [à-öø-ÿ] -export const magicSplit = /^[a-zà-öø-ÿ]+|[A-ZÀ-ÖØ-ß][a-zà-öø-ÿ]+|[a-zà-öø-ÿ]+|[0-9]+|[A-ZÀ-ÖØ-ß]+(?![a-zà-öø-ÿ])/g +export const magicSplit = + /^[a-zà-öø-ÿа-я]+|[A-ZÀ-ÖØ-ßА-Я][a-zà-öø-ÿа-я]+|[a-zà-öø-ÿа-я]+|[0-9]+|[A-ZÀ-ÖØ-ßА-Я]+(?![a-zà-öø-ÿа-я])/g export const spaceSplit = /\S+/g /** @@ -12,7 +13,7 @@ export const spaceSplit = /\S+/g */ export function getPartsAndIndexes( string: string, - splitRegex: RegExp + splitRegex: RegExp, ): { parts: string[] prefixes: string[] @@ -48,7 +49,7 @@ export function getPartsAndIndexes( */ export function splitAndPrefix( string: string, - options?: { keepSpecialCharacters?: boolean; keep?: string[]; prefix?: string } + options?: { keepSpecialCharacters?: boolean; keep?: string[]; prefix?: string }, ): string[] { const { keepSpecialCharacters = false, keep, prefix = '' } = options || {} const normalString = string.trim().normalize('NFC') @@ -63,7 +64,9 @@ export function splitAndPrefix( if (keepSpecialCharacters === false) { if (keep) { - part = part.normalize('NFD').replace(new RegExp(`[^a-zA-ZØßø0-9${keep.join('')}]`, 'g'), '') + part = part + .normalize('NFD') + .replace(new RegExp(`[^a-zA-ZØßø0-9${keep.join('')}]`, 'g'), '') } if (!keep) { part = part.normalize('NFD').replace(/[^a-zA-ZØßø0-9]/g, '') @@ -106,5 +109,8 @@ export function splitAndPrefix( export function capitaliseWord(string: string): string { const match = string.matchAll(magicSplit).next().value const firstLetterIndex = match ? match.index : 0 - return string.slice(0, firstLetterIndex + 1).toUpperCase() + string.slice(firstLetterIndex + 1).toLowerCase() + return ( + string.slice(0, firstLetterIndex + 1).toUpperCase() + + string.slice(firstLetterIndex + 1).toLowerCase() + ) }