Skip to main content

Function: snakeCase()

snakeCase(key): string

Defined in: src/parsers/_normalize.ts:53

Convert an arbitrary key to snake_case. Handles camelCase, PascalCase, dot.separated, and runs of capitals (ERA -> era, homeRBI -> home_rbi).

Parameters​

key​

string

The source key.

Returns​

string

The snake_cased name: dots, spaces and - become _, runs of _ collapse to one, leading / trailing _ are trimmed, and the result is lower-cased.

Remarks​

Stricter than sdv-py's dl_utils.underscore (see underscore): it also normalises dots, whitespace and repeated / edge underscores, so it is not byte-for-byte py parity.

Example​

snakeCase("teams.home.team.id"); // "teams_home_team_id"
snakeCase("homeRBI"); // "home_rbi"