goodchuck-utils 1.2.0 → 1.3.0
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/dist/form/__tests__/formatter.test.d.ts +2 -0
- package/dist/form/__tests__/formatter.test.d.ts.map +1 -0
- package/dist/form/__tests__/formatter.test.js +74 -0
- package/dist/form/__tests__/helpers.test.d.ts +2 -0
- package/dist/form/__tests__/helpers.test.d.ts.map +1 -0
- package/dist/form/__tests__/helpers.test.js +42 -0
- package/dist/form/__tests__/validation.test.d.ts +2 -0
- package/dist/form/__tests__/validation.test.d.ts.map +1 -0
- package/dist/form/__tests__/validation.test.js +67 -0
- package/dist/form/formatter.d.ts +34 -0
- package/dist/form/formatter.d.ts.map +1 -0
- package/dist/form/formatter.js +76 -0
- package/dist/form/helpers.d.ts +16 -0
- package/dist/form/helpers.d.ts.map +1 -0
- package/dist/form/helpers.js +34 -0
- package/dist/form/index.d.ts +9 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +11 -0
- package/dist/form/validation.d.ts +33 -0
- package/dist/form/validation.d.ts.map +1 -0
- package/dist/form/validation.js +56 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +12 -0
- package/dist/hooks/useClickOutside.d.ts +49 -0
- package/dist/hooks/useClickOutside.d.ts.map +1 -0
- package/dist/hooks/useClickOutside.js +94 -0
- package/dist/hooks/useLocalStorage.d.ts +19 -0
- package/dist/hooks/useLocalStorage.d.ts.map +1 -0
- package/dist/hooks/useLocalStorage.js +91 -0
- package/dist/hooks/useMediaQuery.d.ts +56 -0
- package/dist/hooks/useMediaQuery.d.ts.map +1 -0
- package/dist/hooks/useMediaQuery.js +104 -0
- package/dist/hooks/useSessionStorage.d.ts +19 -0
- package/dist/hooks/useSessionStorage.d.ts.map +1 -0
- package/dist/hooks/useSessionStorage.js +85 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/string/__tests__/case.test.d.ts +2 -0
- package/dist/string/__tests__/case.test.d.ts.map +1 -0
- package/dist/string/__tests__/case.test.js +61 -0
- package/dist/string/__tests__/manipulation.test.d.ts +2 -0
- package/dist/string/__tests__/manipulation.test.d.ts.map +1 -0
- package/dist/string/__tests__/manipulation.test.js +109 -0
- package/dist/string/__tests__/validation.test.d.ts +2 -0
- package/dist/string/__tests__/validation.test.d.ts.map +1 -0
- package/dist/string/__tests__/validation.test.js +101 -0
- package/dist/string/case.d.ts +42 -0
- package/dist/string/case.d.ts.map +1 -0
- package/dist/string/case.js +71 -0
- package/dist/string/index.d.ts +9 -0
- package/dist/string/index.d.ts.map +1 -0
- package/dist/string/index.js +11 -0
- package/dist/string/manipulation.d.ts +61 -0
- package/dist/string/manipulation.d.ts.map +1 -0
- package/dist/string/manipulation.js +106 -0
- package/dist/string/validation.d.ts +79 -0
- package/dist/string/validation.d.ts.map +1 -0
- package/dist/string/validation.js +115 -0
- package/package.json +15 -1
- package/src/form/__tests__/formatter.test.ts +97 -0
- package/src/form/__tests__/helpers.test.ts +53 -0
- package/src/form/__tests__/validation.test.ts +84 -0
- package/src/form/formatter.ts +85 -0
- package/src/form/helpers.ts +44 -0
- package/src/form/index.ts +14 -0
- package/src/form/validation.ts +72 -0
- package/src/hooks/index.ts +14 -0
- package/src/hooks/useClickOutside.ts +114 -0
- package/src/hooks/useLocalStorage.ts +112 -0
- package/src/hooks/useMediaQuery.ts +116 -0
- package/src/hooks/useSessionStorage.ts +106 -0
- package/src/index.ts +9 -2
- package/src/string/__tests__/case.test.ts +78 -0
- package/src/string/__tests__/manipulation.test.ts +142 -0
- package/src/string/__tests__/validation.test.ts +128 -0
- package/src/string/case.ts +76 -0
- package/src/string/index.ts +14 -0
- package/src/string/manipulation.ts +124 -0
- package/src/string/validation.ts +126 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { truncate, normalizeWhitespace, slugify, randomString, repeat, reverse, stripHtml, padStart, padEnd, template, mask, } from '../manipulation';
|
|
3
|
+
describe('String Manipulation', () => {
|
|
4
|
+
describe('truncate', () => {
|
|
5
|
+
it('should truncate long strings', () => {
|
|
6
|
+
expect(truncate('Hello World', 5)).toBe('Hello...');
|
|
7
|
+
expect(truncate('Hello World', 20)).toBe('Hello World');
|
|
8
|
+
});
|
|
9
|
+
it('should use custom suffix', () => {
|
|
10
|
+
expect(truncate('Hello World', 5, '---')).toBe('Hello---');
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
describe('normalizeWhitespace', () => {
|
|
14
|
+
it('should normalize whitespace', () => {
|
|
15
|
+
expect(normalizeWhitespace(' hello world ')).toBe('hello world');
|
|
16
|
+
expect(normalizeWhitespace('hello\n\nworld')).toBe('hello world');
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe('slugify', () => {
|
|
20
|
+
it('should create URL-friendly slugs', () => {
|
|
21
|
+
expect(slugify('Hello World!')).toBe('hello-world');
|
|
22
|
+
expect(slugify('Hello World')).toBe('hello-world');
|
|
23
|
+
expect(slugify('Hello_World')).toBe('hello-world');
|
|
24
|
+
});
|
|
25
|
+
it('should preserve alphanumeric characters', () => {
|
|
26
|
+
expect(slugify('Test123 World')).toBe('test123-world');
|
|
27
|
+
});
|
|
28
|
+
it('should remove special characters', () => {
|
|
29
|
+
expect(slugify('Hello @#$ World!')).toBe('hello-world');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe('randomString', () => {
|
|
33
|
+
it('should generate random alphanumeric string', () => {
|
|
34
|
+
const result = randomString(10);
|
|
35
|
+
expect(result).toHaveLength(10);
|
|
36
|
+
expect(/^[a-zA-Z0-9]+$/.test(result)).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('should generate numeric only string', () => {
|
|
39
|
+
const result = randomString(10, 'numeric');
|
|
40
|
+
expect(result).toHaveLength(10);
|
|
41
|
+
expect(/^[0-9]+$/.test(result)).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
it('should generate alpha only string', () => {
|
|
44
|
+
const result = randomString(10, 'alpha');
|
|
45
|
+
expect(result).toHaveLength(10);
|
|
46
|
+
expect(/^[a-zA-Z]+$/.test(result)).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
it('should generate hex string', () => {
|
|
49
|
+
const result = randomString(10, 'hex');
|
|
50
|
+
expect(result).toHaveLength(10);
|
|
51
|
+
expect(/^[0-9a-f]+$/.test(result)).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('repeat', () => {
|
|
55
|
+
it('should repeat string', () => {
|
|
56
|
+
expect(repeat('ab', 3)).toBe('ababab');
|
|
57
|
+
expect(repeat('x', 5)).toBe('xxxxx');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('reverse', () => {
|
|
61
|
+
it('should reverse string', () => {
|
|
62
|
+
expect(reverse('hello')).toBe('olleh');
|
|
63
|
+
expect(reverse('12345')).toBe('54321');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe('stripHtml', () => {
|
|
67
|
+
it('should remove HTML tags', () => {
|
|
68
|
+
expect(stripHtml('<p>Hello</p>')).toBe('Hello');
|
|
69
|
+
expect(stripHtml('<p>Hello <strong>World</strong></p>')).toBe('Hello World');
|
|
70
|
+
expect(stripHtml('No tags here')).toBe('No tags here');
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('padStart', () => {
|
|
74
|
+
it('should pad string at start', () => {
|
|
75
|
+
expect(padStart('5', 3, '0')).toBe('005');
|
|
76
|
+
expect(padStart('abc', 5, 'x')).toBe('xxabc');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('padEnd', () => {
|
|
80
|
+
it('should pad string at end', () => {
|
|
81
|
+
expect(padEnd('5', 3, '0')).toBe('500');
|
|
82
|
+
expect(padEnd('abc', 5, 'x')).toBe('abcxx');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('template', () => {
|
|
86
|
+
it('should replace placeholders', () => {
|
|
87
|
+
expect(template('Hello {name}!', { name: 'World' })).toBe('Hello World!');
|
|
88
|
+
expect(template('I am {age} years old', { age: 25 })).toBe('I am 25 years old');
|
|
89
|
+
});
|
|
90
|
+
it('should keep unreplaced placeholders', () => {
|
|
91
|
+
expect(template('Hello {name}!', {})).toBe('Hello {name}!');
|
|
92
|
+
});
|
|
93
|
+
it('should handle multiple placeholders', () => {
|
|
94
|
+
expect(template('{greeting} {name}!', { greeting: 'Hi', name: 'John' })).toBe('Hi John!');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe('mask', () => {
|
|
98
|
+
it('should mask characters', () => {
|
|
99
|
+
expect(mask('1234567890', 3, 7)).toBe('123****890');
|
|
100
|
+
expect(mask('password', 2, 6)).toBe('pa****rd');
|
|
101
|
+
});
|
|
102
|
+
it('should use custom mask character', () => {
|
|
103
|
+
expect(mask('1234567890', 3, 7, 'x')).toBe('123xxxx890');
|
|
104
|
+
});
|
|
105
|
+
it('should mask to end if end not specified', () => {
|
|
106
|
+
expect(mask('1234567890', 5)).toBe('12345*****');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.test.d.ts","sourceRoot":"","sources":["../../../src/string/__tests__/validation.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { isEmpty, startsWith, endsWith, contains, isAlpha, isNumeric, isAlphanumeric, isLowerCase, isUpperCase, isJSON, isHexColor, isUUID, isBase64, } from '../validation';
|
|
3
|
+
describe('String Validation', () => {
|
|
4
|
+
describe('isEmpty', () => {
|
|
5
|
+
it('should detect empty strings', () => {
|
|
6
|
+
expect(isEmpty('')).toBe(true);
|
|
7
|
+
expect(isEmpty(' ')).toBe(true);
|
|
8
|
+
expect(isEmpty('hello')).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
describe('startsWith', () => {
|
|
12
|
+
it('should check if string starts with substring', () => {
|
|
13
|
+
expect(startsWith('hello', 'he')).toBe(true);
|
|
14
|
+
expect(startsWith('hello', 'ho')).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('endsWith', () => {
|
|
18
|
+
it('should check if string ends with substring', () => {
|
|
19
|
+
expect(endsWith('hello', 'lo')).toBe(true);
|
|
20
|
+
expect(endsWith('hello', 'he')).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe('contains', () => {
|
|
24
|
+
it('should check if string contains substring', () => {
|
|
25
|
+
expect(contains('hello world', 'world')).toBe(true);
|
|
26
|
+
expect(contains('hello world', 'foo')).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe('isAlpha', () => {
|
|
30
|
+
it('should validate alphabetic strings', () => {
|
|
31
|
+
expect(isAlpha('hello')).toBe(true);
|
|
32
|
+
expect(isAlpha('Hello')).toBe(true);
|
|
33
|
+
expect(isAlpha('hello123')).toBe(false);
|
|
34
|
+
expect(isAlpha('hello_world')).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('isNumeric', () => {
|
|
38
|
+
it('should validate numeric strings', () => {
|
|
39
|
+
expect(isNumeric('123')).toBe(true);
|
|
40
|
+
expect(isNumeric('123.45')).toBe(false);
|
|
41
|
+
expect(isNumeric('abc')).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe('isAlphanumeric', () => {
|
|
45
|
+
it('should validate alphanumeric strings', () => {
|
|
46
|
+
expect(isAlphanumeric('hello123')).toBe(true);
|
|
47
|
+
expect(isAlphanumeric('hello')).toBe(true);
|
|
48
|
+
expect(isAlphanumeric('123')).toBe(true);
|
|
49
|
+
expect(isAlphanumeric('hello_123')).toBe(false);
|
|
50
|
+
expect(isAlphanumeric('hello-123')).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('isLowerCase', () => {
|
|
54
|
+
it('should detect lowercase strings', () => {
|
|
55
|
+
expect(isLowerCase('hello')).toBe(true);
|
|
56
|
+
expect(isLowerCase('Hello')).toBe(false);
|
|
57
|
+
expect(isLowerCase('HELLO')).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('isUpperCase', () => {
|
|
61
|
+
it('should detect uppercase strings', () => {
|
|
62
|
+
expect(isUpperCase('HELLO')).toBe(true);
|
|
63
|
+
expect(isUpperCase('Hello')).toBe(false);
|
|
64
|
+
expect(isUpperCase('hello')).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe('isJSON', () => {
|
|
68
|
+
it('should validate JSON strings', () => {
|
|
69
|
+
expect(isJSON('{"name":"John"}')).toBe(true);
|
|
70
|
+
expect(isJSON('[1,2,3]')).toBe(true);
|
|
71
|
+
expect(isJSON('"hello"')).toBe(true);
|
|
72
|
+
expect(isJSON('not json')).toBe(false);
|
|
73
|
+
expect(isJSON('{invalid}')).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe('isHexColor', () => {
|
|
77
|
+
it('should validate hex color codes', () => {
|
|
78
|
+
expect(isHexColor('#fff')).toBe(true);
|
|
79
|
+
expect(isHexColor('#ffffff')).toBe(true);
|
|
80
|
+
expect(isHexColor('#FFF')).toBe(true);
|
|
81
|
+
expect(isHexColor('#ABC123')).toBe(true);
|
|
82
|
+
expect(isHexColor('fff')).toBe(false);
|
|
83
|
+
expect(isHexColor('#gggggg')).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe('isUUID', () => {
|
|
87
|
+
it('should validate UUID strings', () => {
|
|
88
|
+
expect(isUUID('123e4567-e89b-12d3-a456-426614174000')).toBe(true);
|
|
89
|
+
expect(isUUID('550e8400-e29b-41d4-a716-446655440000')).toBe(true);
|
|
90
|
+
expect(isUUID('not-a-uuid')).toBe(false);
|
|
91
|
+
expect(isUUID('123e4567-e89b-12d3')).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('isBase64', () => {
|
|
95
|
+
it('should validate base64 strings', () => {
|
|
96
|
+
expect(isBase64('SGVsbG8gV29ybGQ=')).toBe(true);
|
|
97
|
+
expect(isBase64('dGVzdA==')).toBe(true);
|
|
98
|
+
expect(isBase64('not base64')).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String Case Conversion Utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 첫 글자를 대문자로 변환
|
|
6
|
+
* @example capitalize('hello world') // 'Hello world'
|
|
7
|
+
*/
|
|
8
|
+
export declare function capitalize(str: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* 모든 단어의 첫 글자를 대문자로 변환
|
|
11
|
+
* @example capitalizeWords('hello world') // 'Hello World'
|
|
12
|
+
*/
|
|
13
|
+
export declare function capitalizeWords(str: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* camelCase로 변환
|
|
16
|
+
* @example camelCase('hello world') // 'helloWorld'
|
|
17
|
+
* @example camelCase('hello-world') // 'helloWorld'
|
|
18
|
+
*/
|
|
19
|
+
export declare function camelCase(str: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* PascalCase로 변환
|
|
22
|
+
* @example pascalCase('hello world') // 'HelloWorld'
|
|
23
|
+
*/
|
|
24
|
+
export declare function pascalCase(str: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* snake_case로 변환
|
|
27
|
+
* @example snakeCase('helloWorld') // 'hello_world'
|
|
28
|
+
* @example snakeCase('Hello World') // 'hello_world'
|
|
29
|
+
*/
|
|
30
|
+
export declare function snakeCase(str: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* kebab-case로 변환
|
|
33
|
+
* @example kebabCase('helloWorld') // 'hello-world'
|
|
34
|
+
* @example kebabCase('Hello World') // 'hello-world'
|
|
35
|
+
*/
|
|
36
|
+
export declare function kebabCase(str: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* CONSTANT_CASE로 변환
|
|
39
|
+
* @example constantCase('helloWorld') // 'HELLO_WORLD'
|
|
40
|
+
*/
|
|
41
|
+
export declare function constantCase(str: string): string;
|
|
42
|
+
//# sourceMappingURL=case.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"case.d.ts","sourceRoot":"","sources":["../../src/string/case.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI7C;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO7C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO7C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String Case Conversion Utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 첫 글자를 대문자로 변환
|
|
6
|
+
* @example capitalize('hello world') // 'Hello world'
|
|
7
|
+
*/
|
|
8
|
+
export function capitalize(str) {
|
|
9
|
+
if (!str)
|
|
10
|
+
return str;
|
|
11
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 모든 단어의 첫 글자를 대문자로 변환
|
|
15
|
+
* @example capitalizeWords('hello world') // 'Hello World'
|
|
16
|
+
*/
|
|
17
|
+
export function capitalizeWords(str) {
|
|
18
|
+
if (!str)
|
|
19
|
+
return str;
|
|
20
|
+
return str.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* camelCase로 변환
|
|
24
|
+
* @example camelCase('hello world') // 'helloWorld'
|
|
25
|
+
* @example camelCase('hello-world') // 'helloWorld'
|
|
26
|
+
*/
|
|
27
|
+
export function camelCase(str) {
|
|
28
|
+
return str
|
|
29
|
+
.toLowerCase()
|
|
30
|
+
.replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase());
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* PascalCase로 변환
|
|
34
|
+
* @example pascalCase('hello world') // 'HelloWorld'
|
|
35
|
+
*/
|
|
36
|
+
export function pascalCase(str) {
|
|
37
|
+
return capitalize(camelCase(str));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* snake_case로 변환
|
|
41
|
+
* @example snakeCase('helloWorld') // 'hello_world'
|
|
42
|
+
* @example snakeCase('Hello World') // 'hello_world'
|
|
43
|
+
*/
|
|
44
|
+
export function snakeCase(str) {
|
|
45
|
+
return str
|
|
46
|
+
.replace(/([A-Z])/g, '_$1')
|
|
47
|
+
.replace(/[\s-]+/g, '_')
|
|
48
|
+
.replace(/_+/g, '_')
|
|
49
|
+
.replace(/^_/, '')
|
|
50
|
+
.toLowerCase();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* kebab-case로 변환
|
|
54
|
+
* @example kebabCase('helloWorld') // 'hello-world'
|
|
55
|
+
* @example kebabCase('Hello World') // 'hello-world'
|
|
56
|
+
*/
|
|
57
|
+
export function kebabCase(str) {
|
|
58
|
+
return str
|
|
59
|
+
.replace(/([A-Z])/g, '-$1')
|
|
60
|
+
.replace(/[\s_]+/g, '-')
|
|
61
|
+
.replace(/-+/g, '-')
|
|
62
|
+
.replace(/^-/, '')
|
|
63
|
+
.toLowerCase();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* CONSTANT_CASE로 변환
|
|
67
|
+
* @example constantCase('helloWorld') // 'HELLO_WORLD'
|
|
68
|
+
*/
|
|
69
|
+
export function constantCase(str) {
|
|
70
|
+
return snakeCase(str).toUpperCase();
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,QAAQ,CAAC;AAGvB,cAAc,gBAAgB,CAAC;AAG/B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for string case conversion, manipulation, and validation.
|
|
5
|
+
*/
|
|
6
|
+
// Case conversion utilities
|
|
7
|
+
export * from './case';
|
|
8
|
+
// Manipulation utilities
|
|
9
|
+
export * from './manipulation';
|
|
10
|
+
// Validation utilities
|
|
11
|
+
export * from './validation';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String Manipulation Utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 문자열을 지정된 길이로 자르고 말줄임표 추가
|
|
6
|
+
* @example truncate('Hello World', 5) // 'Hello...'
|
|
7
|
+
*/
|
|
8
|
+
export declare function truncate(str: string, length: number, suffix?: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* 문자열 양쪽 공백 제거 및 연속된 공백을 하나로
|
|
11
|
+
* @example normalizeWhitespace(' hello world ') // 'hello world'
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeWhitespace(str: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* URL 친화적인 슬러그 생성
|
|
16
|
+
* @example slugify('Hello World!') // 'hello-world'
|
|
17
|
+
* @example slugify('Test123 World') // 'test123-world'
|
|
18
|
+
*/
|
|
19
|
+
export declare function slugify(str: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* 랜덤 문자열 생성
|
|
22
|
+
* @param length - 생성할 문자열 길이
|
|
23
|
+
* @param charset - 사용할 문자 집합 ('alphanumeric', 'alpha', 'numeric', 'hex')
|
|
24
|
+
*/
|
|
25
|
+
export declare function randomString(length: number, charset?: 'alphanumeric' | 'alpha' | 'numeric' | 'hex'): string;
|
|
26
|
+
/**
|
|
27
|
+
* 문자열 반복
|
|
28
|
+
* @example repeat('ab', 3) // 'ababab'
|
|
29
|
+
*/
|
|
30
|
+
export declare function repeat(str: string, count: number): string;
|
|
31
|
+
/**
|
|
32
|
+
* 문자열 뒤집기
|
|
33
|
+
* @example reverse('hello') // 'olleh'
|
|
34
|
+
*/
|
|
35
|
+
export declare function reverse(str: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* 문자열에서 HTML 태그 제거
|
|
38
|
+
* @example stripHtml('<p>Hello <strong>World</strong></p>') // 'Hello World'
|
|
39
|
+
*/
|
|
40
|
+
export declare function stripHtml(str: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* 문자열을 특정 길이로 패딩
|
|
43
|
+
* @example padStart('5', 3, '0') // '005'
|
|
44
|
+
*/
|
|
45
|
+
export declare function padStart(str: string, length: number, fillString?: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* 문자열을 특정 길이로 패딩 (오른쪽)
|
|
48
|
+
* @example padEnd('5', 3, '0') // '500'
|
|
49
|
+
*/
|
|
50
|
+
export declare function padEnd(str: string, length: number, fillString?: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* 템플릿 문자열 치환
|
|
53
|
+
* @example template('Hello {name}!', { name: 'World' }) // 'Hello World!'
|
|
54
|
+
*/
|
|
55
|
+
export declare function template(str: string, values: Record<string, any>): string;
|
|
56
|
+
/**
|
|
57
|
+
* 마스킹 (특정 위치의 문자를 *로 변경)
|
|
58
|
+
* @example mask('1234567890', 3, 7) // '123****890'
|
|
59
|
+
*/
|
|
60
|
+
export declare function mask(str: string, start: number, end?: number, maskChar?: string): string;
|
|
61
|
+
//# sourceMappingURL=manipulation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manipulation.d.ts","sourceRoot":"","sources":["../../src/string/manipulation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAc,GAAG,MAAM,CAGpF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ3C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,cAAc,GAAG,OAAO,GAAG,SAAS,GAAG,KAAsB,GACrE,MAAM,CAgBR;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAE,MAAY,GAAG,MAAM,CAEtF;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAE,MAAY,GAAG,MAAM,CAEpF;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAIzE;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAY,GAAG,MAAM,CAO7F"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String Manipulation Utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 문자열을 지정된 길이로 자르고 말줄임표 추가
|
|
6
|
+
* @example truncate('Hello World', 5) // 'Hello...'
|
|
7
|
+
*/
|
|
8
|
+
export function truncate(str, length, suffix = '...') {
|
|
9
|
+
if (str.length <= length)
|
|
10
|
+
return str;
|
|
11
|
+
return str.slice(0, length) + suffix;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 문자열 양쪽 공백 제거 및 연속된 공백을 하나로
|
|
15
|
+
* @example normalizeWhitespace(' hello world ') // 'hello world'
|
|
16
|
+
*/
|
|
17
|
+
export function normalizeWhitespace(str) {
|
|
18
|
+
return str.trim().replace(/\s+/g, ' ');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* URL 친화적인 슬러그 생성
|
|
22
|
+
* @example slugify('Hello World!') // 'hello-world'
|
|
23
|
+
* @example slugify('Test123 World') // 'test123-world'
|
|
24
|
+
*/
|
|
25
|
+
export function slugify(str) {
|
|
26
|
+
return str
|
|
27
|
+
.toLowerCase()
|
|
28
|
+
.trim()
|
|
29
|
+
.replace(/[^\w\s-]/g, '')
|
|
30
|
+
.replace(/[\s_]+/g, '-')
|
|
31
|
+
.replace(/-+/g, '-')
|
|
32
|
+
.replace(/^-+|-+$/g, '');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 랜덤 문자열 생성
|
|
36
|
+
* @param length - 생성할 문자열 길이
|
|
37
|
+
* @param charset - 사용할 문자 집합 ('alphanumeric', 'alpha', 'numeric', 'hex')
|
|
38
|
+
*/
|
|
39
|
+
export function randomString(length, charset = 'alphanumeric') {
|
|
40
|
+
const charsets = {
|
|
41
|
+
alphanumeric: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
|
|
42
|
+
alpha: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
|
43
|
+
numeric: '0123456789',
|
|
44
|
+
hex: '0123456789abcdef',
|
|
45
|
+
};
|
|
46
|
+
const chars = charsets[charset];
|
|
47
|
+
let result = '';
|
|
48
|
+
for (let i = 0; i < length; i++) {
|
|
49
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 문자열 반복
|
|
55
|
+
* @example repeat('ab', 3) // 'ababab'
|
|
56
|
+
*/
|
|
57
|
+
export function repeat(str, count) {
|
|
58
|
+
return str.repeat(count);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 문자열 뒤집기
|
|
62
|
+
* @example reverse('hello') // 'olleh'
|
|
63
|
+
*/
|
|
64
|
+
export function reverse(str) {
|
|
65
|
+
return str.split('').reverse().join('');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 문자열에서 HTML 태그 제거
|
|
69
|
+
* @example stripHtml('<p>Hello <strong>World</strong></p>') // 'Hello World'
|
|
70
|
+
*/
|
|
71
|
+
export function stripHtml(str) {
|
|
72
|
+
return str.replace(/<[^>]*>/g, '');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 문자열을 특정 길이로 패딩
|
|
76
|
+
* @example padStart('5', 3, '0') // '005'
|
|
77
|
+
*/
|
|
78
|
+
export function padStart(str, length, fillString = ' ') {
|
|
79
|
+
return str.padStart(length, fillString);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 문자열을 특정 길이로 패딩 (오른쪽)
|
|
83
|
+
* @example padEnd('5', 3, '0') // '500'
|
|
84
|
+
*/
|
|
85
|
+
export function padEnd(str, length, fillString = ' ') {
|
|
86
|
+
return str.padEnd(length, fillString);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 템플릿 문자열 치환
|
|
90
|
+
* @example template('Hello {name}!', { name: 'World' }) // 'Hello World!'
|
|
91
|
+
*/
|
|
92
|
+
export function template(str, values) {
|
|
93
|
+
return str.replace(/\{(\w+)\}/g, (match, key) => {
|
|
94
|
+
return values[key] !== undefined ? String(values[key]) : match;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 마스킹 (특정 위치의 문자를 *로 변경)
|
|
99
|
+
* @example mask('1234567890', 3, 7) // '123****890'
|
|
100
|
+
*/
|
|
101
|
+
export function mask(str, start, end, maskChar = '*') {
|
|
102
|
+
const endPos = end ?? str.length;
|
|
103
|
+
return (str.slice(0, start) +
|
|
104
|
+
maskChar.repeat(endPos - start) +
|
|
105
|
+
str.slice(endPos));
|
|
106
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String Validation Utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 빈 문자열 또는 공백만 있는지 확인
|
|
6
|
+
* @example isEmpty('') // true
|
|
7
|
+
* @example isEmpty(' ') // true
|
|
8
|
+
* @example isEmpty('hello') // false
|
|
9
|
+
*/
|
|
10
|
+
export declare function isEmpty(str: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 문자열이 특정 문자로 시작하는지 확인
|
|
13
|
+
* @example startsWith('hello', 'he') // true
|
|
14
|
+
*/
|
|
15
|
+
export declare function startsWith(str: string, searchString: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* 문자열이 특정 문자로 끝나는지 확인
|
|
18
|
+
* @example endsWith('hello', 'lo') // true
|
|
19
|
+
*/
|
|
20
|
+
export declare function endsWith(str: string, searchString: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 문자열에 특정 문자열이 포함되어 있는지 확인
|
|
23
|
+
* @example contains('hello world', 'world') // true
|
|
24
|
+
*/
|
|
25
|
+
export declare function contains(str: string, searchString: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* 알파벳만 포함하는지 확인
|
|
28
|
+
* @example isAlpha('hello') // true
|
|
29
|
+
* @example isAlpha('hello123') // false
|
|
30
|
+
*/
|
|
31
|
+
export declare function isAlpha(str: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* 숫자만 포함하는지 확인
|
|
34
|
+
* @example isNumeric('123') // true
|
|
35
|
+
* @example isNumeric('123.45') // false
|
|
36
|
+
*/
|
|
37
|
+
export declare function isNumeric(str: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* 알파벳과 숫자만 포함하는지 확인
|
|
40
|
+
* @example isAlphanumeric('hello123') // true
|
|
41
|
+
* @example isAlphanumeric('hello_123') // false
|
|
42
|
+
*/
|
|
43
|
+
export declare function isAlphanumeric(str: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 소문자만 포함하는지 확인
|
|
46
|
+
* @example isLowerCase('hello') // true
|
|
47
|
+
* @example isLowerCase('Hello') // false
|
|
48
|
+
*/
|
|
49
|
+
export declare function isLowerCase(str: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* 대문자만 포함하는지 확인
|
|
52
|
+
* @example isUpperCase('HELLO') // true
|
|
53
|
+
* @example isUpperCase('Hello') // false
|
|
54
|
+
*/
|
|
55
|
+
export declare function isUpperCase(str: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* JSON 형식인지 확인
|
|
58
|
+
* @example isJSON('{"name":"John"}') // true
|
|
59
|
+
* @example isJSON('not json') // false
|
|
60
|
+
*/
|
|
61
|
+
export declare function isJSON(str: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 16진수 색상 코드인지 확인
|
|
64
|
+
* @example isHexColor('#fff') // true
|
|
65
|
+
* @example isHexColor('#ffffff') // true
|
|
66
|
+
* @example isHexColor('fff') // false
|
|
67
|
+
*/
|
|
68
|
+
export declare function isHexColor(str: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* UUID 형식인지 확인
|
|
71
|
+
* @example isUUID('123e4567-e89b-12d3-a456-426614174000') // true
|
|
72
|
+
*/
|
|
73
|
+
export declare function isUUID(str: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Base64 인코딩된 문자열인지 확인
|
|
76
|
+
* @example isBase64('SGVsbG8gV29ybGQ=') // true
|
|
77
|
+
*/
|
|
78
|
+
export declare function isBase64(str: string): boolean;
|
|
79
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/string/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAErE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO3C;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAM7C"}
|