@central-design-system/components 3.0.0-alpha.3 → 3.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/scss/themes/index.ts +1 -1
- package/src/utils/__test__/helper.test.ts +59 -0
- package/src/utils/__test__/mocks/helper.mock.ts +362 -0
- package/src/utils/__test__/mocks/propFactory.mock.ts +88 -0
- package/src/utils/__test__/propFactory.test.ts +9 -0
- package/src/utils/anchor.ts +76 -0
- package/src/utils/animation.ts +62 -0
- package/src/utils/box.ts +39 -0
- package/src/utils/cache.ts +12 -0
- package/src/utils/changeCase/__test__/lowerCase.test.ts +12 -0
- package/src/utils/changeCase/__test__/mocks/lowerCase.mock.ts +80 -0
- package/src/utils/changeCase/__test__/mocks/noCase.mock.ts +131 -0
- package/src/utils/changeCase/__test__/mocks/paramCase.mock.ts +39 -0
- package/src/utils/changeCase/__test__/mocks/pascalCase.mock.ts +46 -0
- package/src/utils/changeCase/__test__/noCase.test.ts +8 -0
- package/src/utils/changeCase/__test__/paramCase.test.ts +8 -0
- package/src/utils/changeCase/__test__/pascalCase.test.ts +8 -0
- package/src/utils/changeCase/lowerCase.ts +56 -0
- package/src/utils/changeCase/noCase.ts +45 -0
- package/src/utils/changeCase/paramCase.ts +11 -0
- package/src/utils/changeCase/pascalCase.ts +24 -0
- package/src/utils/date.ts +1100 -0
- package/src/utils/dom.ts +24 -0
- package/src/utils/getCurrentInstance.ts +43 -0
- package/src/utils/getScrollParent.ts +29 -0
- package/src/utils/globals.ts +8 -0
- package/src/utils/helpers.ts +311 -0
- package/src/utils/index.ts +19 -0
- package/src/utils/propsFactory.ts +92 -0
package/src/utils/box.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export class Box {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
|
|
7
|
+
constructor({ x, y, width, height }: { x: number; y: number; width: number; height: number }) {
|
|
8
|
+
this.x = x;
|
|
9
|
+
this.y = y;
|
|
10
|
+
this.width = width;
|
|
11
|
+
this.height = height;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get top() {
|
|
15
|
+
return this.y;
|
|
16
|
+
}
|
|
17
|
+
get bottom() {
|
|
18
|
+
return this.y + this.height;
|
|
19
|
+
}
|
|
20
|
+
get left() {
|
|
21
|
+
return this.x;
|
|
22
|
+
}
|
|
23
|
+
get right() {
|
|
24
|
+
return this.x + this.width;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getOverflow(a: Box, b: Box) {
|
|
29
|
+
return {
|
|
30
|
+
x: {
|
|
31
|
+
before: Math.max(0, b.left - a.left),
|
|
32
|
+
after: Math.max(0, a.right - b.right)
|
|
33
|
+
},
|
|
34
|
+
y: {
|
|
35
|
+
before: Math.max(0, b.top - a.top),
|
|
36
|
+
after: Math.max(0, a.bottom - b.bottom)
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function useCache() {
|
|
2
|
+
const cache: Record<string, any> = new Map();
|
|
3
|
+
|
|
4
|
+
return {
|
|
5
|
+
getCache: function (key: string, obj: any) {
|
|
6
|
+
return cache[key] || (cache[key] = obj);
|
|
7
|
+
},
|
|
8
|
+
getCacheWithFn: function (key: string, fn: () => any) {
|
|
9
|
+
return cache[key] || (cache[key] = fn());
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { lowerCaseMock, localeLowerCaseMock } from './mocks/lowerCase.mock';
|
|
2
|
+
import { localeLowerCase, lowerCase } from '../lowerCase';
|
|
3
|
+
|
|
4
|
+
describe('lowerCase.ts', () => {
|
|
5
|
+
it.each(lowerCaseMock)('should be to lower case - #%#', ({ initial, expected }) => {
|
|
6
|
+
expect(lowerCase(initial)).toBe(expected);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it.each(localeLowerCaseMock)('should be to locale lower case - #%#', ({ initial, expected, locale }) => {
|
|
10
|
+
expect(localeLowerCase(initial, locale)).toBe(expected);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { IMockDataProvider } from '@/types/vitest';
|
|
2
|
+
|
|
3
|
+
export const lowerCaseMock: IMockDataProvider[] = [
|
|
4
|
+
{
|
|
5
|
+
name: 'lowerCase',
|
|
6
|
+
initial: 'FOO',
|
|
7
|
+
expected: 'foo'
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: 'lowerCase',
|
|
11
|
+
initial: 'hEllO',
|
|
12
|
+
expected: 'hello'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'lowerCase',
|
|
16
|
+
initial: '123BAR',
|
|
17
|
+
expected: '123bar'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'lowerCase',
|
|
21
|
+
initial: 'ТЕКСТ',
|
|
22
|
+
expected: 'текст'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'lowerCase',
|
|
26
|
+
initial: 'тЕкСт',
|
|
27
|
+
expected: 'текст'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'lowerCase',
|
|
31
|
+
initial: 'Some_Foo',
|
|
32
|
+
expected: 'some_foo'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'lowerCase',
|
|
36
|
+
initial: 'SOME-FOO',
|
|
37
|
+
expected: 'some-foo'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'lowerCase',
|
|
41
|
+
initial: ' FOO',
|
|
42
|
+
expected: ' foo'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'lowerCase',
|
|
46
|
+
initial: 'HI how Are You?',
|
|
47
|
+
expected: 'hi how are you?'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'lowerCase',
|
|
51
|
+
initial: 'test string',
|
|
52
|
+
expected: 'test string'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'lowerCase',
|
|
56
|
+
initial: '',
|
|
57
|
+
expected: ''
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
export const localeLowerCaseMock: IMockDataProvider[] = [
|
|
62
|
+
{
|
|
63
|
+
name: 'lowerCase',
|
|
64
|
+
initial: 'FOO',
|
|
65
|
+
expected: 'foo',
|
|
66
|
+
locale: 'en'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'lowerCase',
|
|
70
|
+
initial: 'ФУУ',
|
|
71
|
+
expected: 'фуу',
|
|
72
|
+
locale: 'ru'
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'lowerCase',
|
|
76
|
+
initial: 'STRING',
|
|
77
|
+
expected: 'strıng',
|
|
78
|
+
locale: 'tr'
|
|
79
|
+
}
|
|
80
|
+
];
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { IMockDataProvider } from '@/types/vitest';
|
|
2
|
+
|
|
3
|
+
export const noCaseMock: IMockDataProvider[] = [
|
|
4
|
+
{
|
|
5
|
+
name: 'noCase',
|
|
6
|
+
initial: 'test',
|
|
7
|
+
expected: 'test'
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: 'noCase',
|
|
11
|
+
initial: 'testString',
|
|
12
|
+
expected: 'test string'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'noCase',
|
|
16
|
+
initial: 'testString_1_2_3',
|
|
17
|
+
expected: 'test string 1 2 3'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'noCase',
|
|
21
|
+
initial: 'x_256',
|
|
22
|
+
expected: 'x 256'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'noCase',
|
|
26
|
+
initial: 'anHTMLTag',
|
|
27
|
+
expected: 'an html tag'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'noCase',
|
|
31
|
+
initial: 'ID123String',
|
|
32
|
+
expected: 'id123 string'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'noCase',
|
|
36
|
+
initial: 'Id123String',
|
|
37
|
+
expected: 'id123 string'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'noCase',
|
|
41
|
+
initial: 'foo bar123',
|
|
42
|
+
expected: 'foo bar123'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'noCase',
|
|
46
|
+
initial: 'a1bStar',
|
|
47
|
+
expected: 'a1b star'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'noCase',
|
|
51
|
+
initial: ' test ',
|
|
52
|
+
expected: 'test'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'noCase',
|
|
56
|
+
initial: 'CONSTANT_CASE ',
|
|
57
|
+
expected: 'constant case'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'noCase',
|
|
61
|
+
initial: 'CONST123_FOO',
|
|
62
|
+
expected: 'const123 foo'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'noCase',
|
|
66
|
+
initial: 'FOO_bar',
|
|
67
|
+
expected: 'foo bar'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'noCase',
|
|
71
|
+
initial: 'XMLHttpRequest',
|
|
72
|
+
expected: 'xml http request'
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'noCase',
|
|
76
|
+
initial: 'IQueryAArgs',
|
|
77
|
+
expected: 'i query a args'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'noCase',
|
|
81
|
+
initial: 'dot.case',
|
|
82
|
+
expected: 'dot case'
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'noCase',
|
|
86
|
+
initial: 'path/case',
|
|
87
|
+
expected: 'path case'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'noCase',
|
|
91
|
+
initial: 'snake_case',
|
|
92
|
+
expected: 'snake case'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'noCase',
|
|
96
|
+
initial: 'snake_case123',
|
|
97
|
+
expected: 'snake case123'
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'noCase',
|
|
101
|
+
initial: 'snake_case_123',
|
|
102
|
+
expected: 'snake case 123'
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'noCase',
|
|
106
|
+
initial: 'version 0.45.0',
|
|
107
|
+
expected: 'version 0 45 0'
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'noCase',
|
|
111
|
+
initial: 'version 0..78..9',
|
|
112
|
+
expected: 'version 0 78 9'
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'noCase',
|
|
116
|
+
initial: 'version 4_99/4',
|
|
117
|
+
expected: 'version 4 99 4'
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: 'noCase',
|
|
121
|
+
initial: 'camel2019',
|
|
122
|
+
expected: 'camel 2019',
|
|
123
|
+
options: { splitRegexp: /([a-z])([A-Z0-9])/g }
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'noCase',
|
|
127
|
+
initial: 'minifyURLs',
|
|
128
|
+
expected: 'minify urls',
|
|
129
|
+
options: { splitRegexp: /([a-z])([A-Z0-9])/g }
|
|
130
|
+
}
|
|
131
|
+
];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IMockDataProvider } from '@/types/vitest';
|
|
2
|
+
|
|
3
|
+
export const paramCaseMock: IMockDataProvider[] = [
|
|
4
|
+
{
|
|
5
|
+
name: 'paramCase',
|
|
6
|
+
initial: '',
|
|
7
|
+
expected: ''
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: 'paramCase',
|
|
11
|
+
initial: 'test',
|
|
12
|
+
expected: 'test'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'paramCase',
|
|
16
|
+
initial: 'test string',
|
|
17
|
+
expected: 'test-string'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'paramCase',
|
|
21
|
+
initial: 'Test String',
|
|
22
|
+
expected: 'test-string'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'paramCase',
|
|
26
|
+
initial: 'TestV2',
|
|
27
|
+
expected: 'test-v2'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'paramCase',
|
|
31
|
+
initial: 'version 1.2.10',
|
|
32
|
+
expected: 'version-1-2-10'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'paramCase',
|
|
36
|
+
initial: 'version 1.21.0',
|
|
37
|
+
expected: 'version-1-21-0'
|
|
38
|
+
}
|
|
39
|
+
];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { IMockDataProvider } from '@/types/vitest';
|
|
2
|
+
import { pascalCaseTransformMerge } from '@components/utils';
|
|
3
|
+
|
|
4
|
+
export const pascalCaseMock: IMockDataProvider[] = [
|
|
5
|
+
{
|
|
6
|
+
name: 'pascalCase',
|
|
7
|
+
initial: '',
|
|
8
|
+
expected: ''
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: 'pascalCase',
|
|
12
|
+
initial: 'test',
|
|
13
|
+
expected: 'Test'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'pascalCase',
|
|
17
|
+
initial: 'test string',
|
|
18
|
+
expected: 'TestString'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'pascalCase',
|
|
22
|
+
initial: 'Test String',
|
|
23
|
+
expected: 'TestString'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'pascalCase',
|
|
27
|
+
initial: 'TestV2',
|
|
28
|
+
expected: 'TestV2'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'pascalCase',
|
|
32
|
+
initial: 'version 1.2.10',
|
|
33
|
+
expected: 'Version_1_2_10'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'pascalCase',
|
|
37
|
+
initial: 'version 1.21.0',
|
|
38
|
+
expected: 'Version_1_21_0'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'pascalCase',
|
|
42
|
+
initial: 'version 1.21.0',
|
|
43
|
+
expected: 'Version1210',
|
|
44
|
+
options: { transform: pascalCaseTransformMerge }
|
|
45
|
+
}
|
|
46
|
+
];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { noCaseMock } from './mocks/noCase.mock';
|
|
2
|
+
import { noCase } from '../noCase';
|
|
3
|
+
|
|
4
|
+
describe('noCase.ts', () => {
|
|
5
|
+
it.each(noCaseMock)('should be to no case - #%#', ({ initial, expected, options }) => {
|
|
6
|
+
expect(noCase(initial, options)).toBe(expected);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { paramCaseMock } from './mocks/paramCase.mock';
|
|
2
|
+
import { paramCase } from '../paramCase';
|
|
3
|
+
|
|
4
|
+
describe('paramCase.ts', () => {
|
|
5
|
+
it.each(paramCaseMock)('should be to param case - #%#', ({ initial, expected, options }) => {
|
|
6
|
+
expect(paramCase(initial, options)).toBe(expected);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { pascalCaseMock } from './mocks/pascalCase.mock';
|
|
2
|
+
import { pascalCase } from '../pascalCase';
|
|
3
|
+
|
|
4
|
+
describe('pascalCase.ts', () => {
|
|
5
|
+
it.each(pascalCaseMock)('should be to pascal case - #%#', ({ initial, expected, options }) => {
|
|
6
|
+
expect(pascalCase(initial, options)).toBe(expected);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale character mapping rules.
|
|
3
|
+
*/
|
|
4
|
+
interface Locale {
|
|
5
|
+
regexp: RegExp;
|
|
6
|
+
map: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
|
|
11
|
+
*/
|
|
12
|
+
const SUPPORTED_LOCALE: Record<string, Locale> = {
|
|
13
|
+
tr: {
|
|
14
|
+
regexp: /\u0130|\u0049|\u0049\u0307/g,
|
|
15
|
+
map: {
|
|
16
|
+
İ: '\u0069',
|
|
17
|
+
I: '\u0131',
|
|
18
|
+
İ: '\u0069'
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
az: {
|
|
22
|
+
regexp: /\u0130/g,
|
|
23
|
+
map: {
|
|
24
|
+
İ: '\u0069',
|
|
25
|
+
I: '\u0131',
|
|
26
|
+
İ: '\u0069'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
lt: {
|
|
30
|
+
regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g,
|
|
31
|
+
map: {
|
|
32
|
+
I: '\u0069\u0307',
|
|
33
|
+
J: '\u006A\u0307',
|
|
34
|
+
Į: '\u012F\u0307',
|
|
35
|
+
Ì: '\u0069\u0307\u0300',
|
|
36
|
+
Í: '\u0069\u0307\u0301',
|
|
37
|
+
Ĩ: '\u0069\u0307\u0303'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Localized lower case.
|
|
44
|
+
*/
|
|
45
|
+
export function localeLowerCase(str: string, locale: string) {
|
|
46
|
+
const lang = SUPPORTED_LOCALE[locale.toLowerCase()];
|
|
47
|
+
if (lang) return lowerCase(str.replace(lang.regexp, (m) => lang.map[m]));
|
|
48
|
+
return lowerCase(str);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Lower case as a function.
|
|
53
|
+
*/
|
|
54
|
+
export function lowerCase(str: string) {
|
|
55
|
+
return str.toLowerCase();
|
|
56
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { lowerCase } from './lowerCase';
|
|
2
|
+
|
|
3
|
+
export interface IChangeCaseOptions {
|
|
4
|
+
splitRegexp?: RegExp | RegExp[];
|
|
5
|
+
stripRegexp?: RegExp | RegExp[];
|
|
6
|
+
delimiter?: string;
|
|
7
|
+
transform?: (part: string, index: number, parts: string[]) => string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
|
|
11
|
+
const DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
12
|
+
|
|
13
|
+
// Remove all non-word characters.
|
|
14
|
+
const DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Normalize the string into something other libraries can manipulate easier.
|
|
18
|
+
*/
|
|
19
|
+
export function noCase(input: string, options: IChangeCaseOptions = {}) {
|
|
20
|
+
const {
|
|
21
|
+
splitRegexp = DEFAULT_SPLIT_REGEXP,
|
|
22
|
+
stripRegexp = DEFAULT_STRIP_REGEXP,
|
|
23
|
+
transform = lowerCase,
|
|
24
|
+
delimiter = ' '
|
|
25
|
+
} = options;
|
|
26
|
+
|
|
27
|
+
const result = replace(replace(input, splitRegexp, '$1\0$2'), stripRegexp, '\0');
|
|
28
|
+
let start = 0;
|
|
29
|
+
let end = result.length;
|
|
30
|
+
|
|
31
|
+
// Trim the delimiter from around the output string.
|
|
32
|
+
while (result.charAt(start) === '\0') start++;
|
|
33
|
+
while (result.charAt(end - 1) === '\0') end--;
|
|
34
|
+
|
|
35
|
+
// Transform each token independently.
|
|
36
|
+
return result.slice(start, end).split('\0').map(transform).join(delimiter);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Replace `re` in the input string with the replacement value.
|
|
41
|
+
*/
|
|
42
|
+
function replace(input: string, re: RegExp | RegExp[], value: string) {
|
|
43
|
+
if (re instanceof RegExp) return input.replace(re, value);
|
|
44
|
+
return re.reduce((input, re) => input.replace(re, value), input);
|
|
45
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { noCase } from './noCase';
|
|
2
|
+
import type { IChangeCaseOptions } from './noCase';
|
|
3
|
+
|
|
4
|
+
export type { IChangeCaseOptions };
|
|
5
|
+
|
|
6
|
+
export function paramCase(input: string, options: IChangeCaseOptions = {}) {
|
|
7
|
+
return noCase(input, {
|
|
8
|
+
delimiter: '-',
|
|
9
|
+
...options
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { noCase, IChangeCaseOptions } from './noCase';
|
|
2
|
+
|
|
3
|
+
export type { IChangeCaseOptions };
|
|
4
|
+
|
|
5
|
+
export function pascalCaseTransform(input: string, index: number) {
|
|
6
|
+
const firstChar = input.charAt(0);
|
|
7
|
+
const lowerChars = input.substr(1).toLowerCase();
|
|
8
|
+
if (index > 0 && firstChar >= '0' && firstChar <= '9') {
|
|
9
|
+
return `_${firstChar}${lowerChars}`;
|
|
10
|
+
}
|
|
11
|
+
return `${firstChar.toUpperCase()}${lowerChars}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function pascalCaseTransformMerge(input: string) {
|
|
15
|
+
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function pascalCase(input: string, options: IChangeCaseOptions = {}) {
|
|
19
|
+
return noCase(input, {
|
|
20
|
+
delimiter: '',
|
|
21
|
+
transform: pascalCaseTransform,
|
|
22
|
+
...options
|
|
23
|
+
});
|
|
24
|
+
}
|