説明
Example:
import {camelCase} from 'bun';
const camel = camelCase("hello world");
// "helloWorld"
TODO
-
Bun.camelCase("two words")->"twoWords" -
Bun.capitalCase("two words")->"Two Words" -
Bun.constantCase("two words")->"TWO_WORDS" -
Bun.dotCase("two words")->"two.words" -
Bun.kebabCase("two words")->"two-words" -
Bun.pascalCase("two words")->"TwoWords" -
Bun.snakeCase("two words")->"two_words" -
Bun.trainCase("two words")->"Two-Words"
Like change-case
Why?
This is useful for both bun:sqlite and bun:sql. We want to expose a way to convert column names from the version in the SQL query to what you want to use in your code.
This is a really common utility method otherwise.
If we need to build this for SQL clients, then we might as well expose it as a utility function in JS. We'll have to implement UTF-8, latin1, and UTF-16 versions regardless.
Implementation notes
It should probably be done in Zig, but it needs to accept a comptime parameter for output encoding so that it can be easily converted to a string for JS, or used in native code like for the SQL client. This means that it should support outputting as either a []const u8 or a bun.String.
Other notes
Briefly considered Bun.string as a namespace object to put these on, but the issue is we have Bun.stringWidth and it would be strange. I think keeping almost everything on the Bun global is nice since it can be both imported or used globally, and it's good for editor autocomplete to avoid namespaces. Our existing mechanism for lazy-loading functions makes this fine.