4
4
// lower case ranges
5
5
// [à-öø-ÿ]
6
6
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
8
9
export const spaceSplit = / \S + / g
9
10
10
11
/**
11
12
* A string.matchAll function that will return an array of "string parts" and the indexes at which it split each part
12
13
*/
13
14
export function getPartsAndIndexes (
14
15
string : string ,
15
- splitRegex : RegExp
16
+ splitRegex : RegExp ,
16
17
) : {
17
18
parts : string [ ]
18
19
prefixes : string [ ]
@@ -48,7 +49,7 @@ export function getPartsAndIndexes(
48
49
*/
49
50
export function splitAndPrefix (
50
51
string : string ,
51
- options ?: { keepSpecialCharacters ?: boolean ; keep ?: string [ ] ; prefix ?: string }
52
+ options ?: { keepSpecialCharacters ?: boolean ; keep ?: string [ ] ; prefix ?: string } ,
52
53
) : string [ ] {
53
54
const { keepSpecialCharacters = false , keep, prefix = '' } = options || { }
54
55
const normalString = string . trim ( ) . normalize ( 'NFC' )
@@ -63,7 +64,9 @@ export function splitAndPrefix(
63
64
64
65
if ( keepSpecialCharacters === false ) {
65
66
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' ) , '' )
67
70
}
68
71
if ( ! keep ) {
69
72
part = part . normalize ( 'NFD' ) . replace ( / [ ^ a - z A - Z Ø ß ø 0 - 9 ] / g, '' )
@@ -106,5 +109,8 @@ export function splitAndPrefix(
106
109
export function capitaliseWord ( string : string ) : string {
107
110
const match = string . matchAll ( magicSplit ) . next ( ) . value
108
111
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
+ )
110
116
}
0 commit comments