-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utils): 新增 constantCase, pascalCase
- Loading branch information
Showing
5 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { constantCase } from './constantCase' | ||
|
||
describe('constantCase', () => { | ||
test('正常', () => { | ||
expect(constantCase('test string')).toBe('TEST_STRING') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { snakeCase } from 'lodash-es' | ||
|
||
/** | ||
* 转换文本为大写字符串,单词之间带有下划线。 | ||
* | ||
* @param text 要转换的文本 | ||
* @returns 返回结果 | ||
* @example | ||
* ```typescript | ||
* constantCase('test string') | ||
* // => TEST_STRING | ||
* ``` | ||
*/ | ||
export function constantCase(text: string): string { | ||
return snakeCase(text).toUpperCase() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { pascalCase } from './pascalCase' | ||
|
||
describe('pascalCase', () => { | ||
test('正常', () => { | ||
expect(pascalCase('test string')).toBe('TestString') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { camelCase, upperFirst } from 'lodash-es' | ||
|
||
/** | ||
* 转换文本为没有分隔符的大写单词字符串。 | ||
* | ||
* @param text 要转换的文本 | ||
* @returns 返回结果 | ||
* @example | ||
* ```typescript | ||
* pascalCase('test string') | ||
* // => TestString | ||
* ``` | ||
*/ | ||
export function pascalCase(text: string): string { | ||
return upperFirst(camelCase(text)) | ||
} |