swc/bundler/tests/.cache/untrusted/170d6d69b2fe9111d507d4c00eb437fc151f4e13.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

37 lines
874 B
TypeScript

// Loaded from https://raw.githubusercontent.com/lodash/lodash/master/snakeCase.js
import words from './words.js'
import toString from './toString.js'
/**
* Converts `string` to
* [snake case](https://en.wikipedia.org/wiki/Snake_case).
*
* @since 3.0.0
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the snake cased string.
* @see camelCase, lowerCase, kebabCase, startCase, upperCase, upperFirst
* @example
*
* snakeCase('Foo Bar')
* // => 'foo_bar'
*
* snakeCase('fooBar')
* // => 'foo_bar'
*
* snakeCase('--FOO-BAR--')
* // => 'foo_bar'
*
* snakeCase('foo2bar')
* // => 'foo_2_bar'
*/
const snakeCase = (string) => (
words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => (
result + (index ? '_' : '') + word.toLowerCase()
), '')
)
export default snakeCase