# snakeCase

# Description

转换字符串 string 为 _ 连接

# Params

string

# Return

string

# Depend

import words from './words.js'
import toString from './toString.js'

words 源码分析

toString 源码分析

# Code

const snakeCase = (string) => (
  words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => (
    result + (index ? '_' : '') + word.toLowerCase()
  ), '')
)

# Analyze

kebabCase 类似,拼接符换成了 _

# Example

console.log(snakeCase('snakeCase')) // snake_case