Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runtime-core/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('asSnakeCase', () => {
expect(asSnakeCase({ firstName: 'Jane', totalScore: 10 })).toEqual({ first_name: 'Jane', total_score: 10 });
});

it.fails('should keep keys that are already snake_case, so the result matches SnakeCasedProperties<T>', () => {
it('should keep keys that are already snake_case, so the result matches SnakeCasedProperties<T>', () => {
expect(asSnakeCase({ age: 30, first_name: 'Jane', lastName: 'Doe' })).toEqual({
age: 30,
first_name: 'Jane',
Expand Down
4 changes: 1 addition & 3 deletions packages/runtime-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import type { SnakeCasedProperties } from 'type-fest';
export function asSnakeCase<T extends { [key: string]: any }>(target: T) {
const result: { [key: string]: any } = {};
for (const key in target) {
if (snakeCase(key) !== key) {
result[snakeCase(key)] = target[key];
}
result[snakeCase(key)] = target[key];
}
return result as SnakeCasedProperties<T>;
}