Skip to content

Commit baae8b6

Browse files
committed
feat: add russian language support (@lordoys)
1 parent 921f5b4 commit baae8b6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/utils.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
// lower case ranges
55
// [à-öø-ÿ]
66

7-
export const magicSplit = /^[a-zà-öø-ÿ]+|[A-ZÀ-ÖØ-ß][a-zà-öø-ÿ]+|[a-zà-öø-ÿ]+|[0-9]+|[A-ZÀ-ÖØ-ß]+(?![a-zà-öø-ÿ])/g
7+
export const magicSplit =
8+
/^[a-zà-öø-ÿа-я]+|[A-ZÀ-ÖØ-ßА-Я][a-zà-öø-ÿа-я]+|[a-zà-öø-ÿа-я]+|[0-9]+|[A-ZÀ-ÖØ-ßА-Я]+(?![a-zà-öø-ÿа-я])/g
89
export const spaceSplit = /\S+/g
910

1011
/**
1112
* A string.matchAll function that will return an array of "string parts" and the indexes at which it split each part
1213
*/
1314
export function getPartsAndIndexes(
1415
string: string,
15-
splitRegex: RegExp
16+
splitRegex: RegExp,
1617
): {
1718
parts: string[]
1819
prefixes: string[]
@@ -48,7 +49,7 @@ export function getPartsAndIndexes(
4849
*/
4950
export function splitAndPrefix(
5051
string: string,
51-
options?: { keepSpecialCharacters?: boolean; keep?: string[]; prefix?: string }
52+
options?: { keepSpecialCharacters?: boolean; keep?: string[]; prefix?: string },
5253
): string[] {
5354
const { keepSpecialCharacters = false, keep, prefix = '' } = options || {}
5455
const normalString = string.trim().normalize('NFC')
@@ -63,7 +64,9 @@ export function splitAndPrefix(
6364

6465
if (keepSpecialCharacters === false) {
6566
if (keep) {
66-
part = part.normalize('NFD').replace(new RegExp(`[^a-zA-ZØßø0-9${keep.join('')}]`, 'g'), '')
67+
part = part
68+
.normalize('NFD')
69+
.replace(new RegExp(`[^a-zA-ZØßø0-9${keep.join('')}]`, 'g'), '')
6770
}
6871
if (!keep) {
6972
part = part.normalize('NFD').replace(/[^a-zA-ZØßø0-9]/g, '')
@@ -106,5 +109,8 @@ export function splitAndPrefix(
106109
export function capitaliseWord(string: string): string {
107110
const match = string.matchAll(magicSplit).next().value
108111
const firstLetterIndex = match ? match.index : 0
109-
return string.slice(0, firstLetterIndex + 1).toUpperCase() + string.slice(firstLetterIndex + 1).toLowerCase()
112+
return (
113+
string.slice(0, firstLetterIndex + 1).toUpperCase() +
114+
string.slice(firstLetterIndex + 1).toLowerCase()
115+
)
110116
}

0 commit comments

Comments
 (0)