Skip to content

Feature request: make knexSnakeCaseMappers behavior with multiple consecutive uppercase letters configurable #1676

@brianmcd

Description

@brianmcd

First off, thanks so much for your work on Objection. It's really a great piece of work.

The issue I'm running into is that the current knexSnakeCaseMappers implementation converts strings like isALevel to is_alevel, isBLevel to is_blevel, etc. This means that if you have a column like is_a_level or is_b_level, you can't access it when using knexSnakeCaseMappers (as far as I can tell, at least). isBLevel and isBlevel both get mapped to the same thing: is_blevel.

It looks like the code adds a special case for when there are two or more consecutive uppercase letters here:

// Multiple consecutive upper case characters shouldn't add underscores.
// For example "fooBAR" should be converted to "foo_bar".
if (prevChar === prevUpperChar && prevUpperChar !== prevLowerChar) {
out += lowerChar;
} else {
out += '_' + lowerChar;
}

Would it make sense to add a parameter to disable this special case, similar to how you handled underscoreBeforeDigits?

function snakeCase(str, { upperCase = false, underscoreBeforeDigits = false } = {}) {

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions