mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: snakecase conversion for strings with numbers (#8111)
This commit is contained in:
parent
22676a04c3
commit
749511d981
@ -22,7 +22,7 @@ export function snakeCase(str: string): string{
|
||||
// ABc -> a_bc
|
||||
.replace(/([A-Z])([A-Z])([a-z])/g, "$1_$2$3")
|
||||
// aC -> a_c
|
||||
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
||||
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
@ -48,6 +48,14 @@ describe("StringUtils", () => {
|
||||
expect(actual).to.be.equal(expected, `Failed for Input: ${input}`);
|
||||
});
|
||||
|
||||
it("should correctly convert strings with numbers", () => {
|
||||
const input = "device1Status";
|
||||
const expected = "device1_status";
|
||||
const actual = snakeCase(input);
|
||||
|
||||
expect(actual).to.be.equal(expected, `Failed for Input: ${input}`);
|
||||
});
|
||||
|
||||
it("should match the examples given in the older implementation", () => {
|
||||
// Pulled from https://regex101.com/r/QeSm2I/1
|
||||
const examples = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user