Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 17x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { splitByCase } from './splitByCase'
/**
* format string to snake case
*
* @param text
* @returns snake case string
*
* {@link https://lodash.com/docs#snakeCase}
*/
export function snakeCase(text: string) {
return splitByCase(text).map(word => word.toLocaleLowerCase()).join('_')
}
Eif (import.meta.vitest) {
const { test, expect } = import.meta.vitest
test('snakeCase', () => {
expect(snakeCase('useXx')).toBe('use_xx')
expect(snakeCase('usexx')).toBe('usexx')
expect(snakeCase('use-xx')).toBe('use_xx')
expect(snakeCase('use xx')).toBe('use_xx')
expect(snakeCase('UseXx')).toBe('use_xx')
expect(snakeCase('use_xx')).toBe('use_xx')
expect(snakeCase('Use Xx')).toBe('use_xx')
expect(snakeCase('Use-Xx')).toBe('use_xx')
expect(snakeCase('USE XX')).toBe('use_xx')
})
}
|