百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

snakecase-keys

> 编程语言
开源

将对象的键转换为蛇形小写

196 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

将对象的键转换为蛇形小写

snakecase-keys

Convert an object's keys to snake case

Install

bash
npm install snakecase-keys

Usage

javascript
import snakecaseKeys from 'snakecase-keys'

snakecaseKeys({ fooBar: 'baz' })
//=> { foo_bar: 'baz' }

snakecaseKeys({ 'foo-bar': true, nested: { fooBaz: 'bar' } })
//=> { foo_bar: true, nested: { foo_baz: 'bar' } }

API

snakecaseKeys(obj, options) -> object

obj

Required
Type: object | Array

A plain object or array of plain objects to transform into snake case (keys only).

options

Optional
Type: object

deep

Type: boolean
Default: true

Enables snake-casing of keys in nested objects.

exclude

Type: Array
Default: []

An array of strings or regular expressions matching keys that will be excluded from snake-casing.

shouldRecurse(key, val) -> boolean

Optional
Type: function

A function that determines if val should be recursed.

Requires deep: true.

parsingOptions

Type: object
Default: {}

Options object passed to the built-in snakeCase function from change-case. Available options include:

  • split: Custom function to split strings into words
  • locale: Locale for case conversion
  • separateNumbers: Whether to separate numbers (deprecated, use splitSeparateNumbers)
  • delimiter: Custom delimiter between words
  • prefixCharacters: Characters to preserve at start
  • suffixCharacters: Characters to preserve at end

See change-case for full documentation.

snakeCase

Optional Type: (key: string) => string

Custom function to convert a key to snake case. Use this to fully override the default behavior of the library and convert keys according to your own conventions. When provided, the return type will be a generic Record, since specific keys cannot be inferred from the custom function.

Related

  • camelcase-keys
  • kebabcase-keys

License

MIT © Ben Drucker

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言