Skip to content

Commit

Permalink
feat(utils): 新增 constantCase, pascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Nov 18, 2020
1 parent ce35843 commit 3f78d8d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/utils/constantCase.test.ts
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')
})
})
16 changes: 16 additions & 0 deletions src/utils/constantCase.ts
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()
}
2 changes: 2 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from 'lodash-es'
export * from './base64'
export * from './bindEvent'
export * from './chooseFile'
export * from './constantCase'
export * from './copyTextToClipboard'
export * from './createSubmit'
export * from './createUrlQueryString'
Expand Down Expand Up @@ -42,6 +43,7 @@ export * from './move'
export * from './omitStrict'
export * from './onceMeanwhile'
export * from './parseUrlQueryString'
export * from './pascalCase'
export * from './pickStrict'
export * from './placeKitten'
export * from './readFile'
Expand Down
7 changes: 7 additions & 0 deletions src/utils/pascalCase.test.ts
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')
})
})
16 changes: 16 additions & 0 deletions src/utils/pascalCase.ts
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))
}

0 comments on commit 3f78d8d

Please sign in to comment.