Skip to content

Commit

Permalink
fix: snake_case is_object type predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jan 28, 2025
1 parent 9ef0f9a commit 29bb49d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type SnakeCaseKeys<T> =
}
: T;

export function camelize<T extends Record<string, unknow>>(
export function camelize<T extends Record<string, unknown>>(
source: T,
depth: boolean | number = true,
): SnakeCaseKeys<T> {
Expand All @@ -69,7 +69,11 @@ export function camelize<T extends Record<string, unknow>>(
for (const key of Object.keys(source)) {
const value = source[key];
const camelizedKey = depth ? camelize_str(key) : key;
target[camelizedKey] = camelize(value, d);
if (is_object(value)) {
target[camelizedKey] = camelize(value, d);
} else {
target[camelizedKey] = value;
}
}
} else {
return source as SnakeCaseKeys<T>;
Expand Down Expand Up @@ -166,7 +170,7 @@ export function mutate<T extends object[]>(
return target as Merge<T>;
}

export function snake_case<T extends Record<string, unknow>>(
export function snake_case<T extends Record<string, unknown>>(
source: T,
depth: boolean | number = true,
): SnakeCaseKeys<T> {
Expand All @@ -176,7 +180,11 @@ export function snake_case<T extends Record<string, unknow>>(
for (const key of Object.keys(source)) {
const value = source[key];
const snakeKey = depth ? snake_case_str(key) : key;
target[snakeKey] = snake_case(value, d);
if (is_object(value)) {
target[snakeKey] = snake_case(value, d);
} else {
target[snakeKey] = value;
}
}
} else {
return source as SnakeCaseKeys<T>;
Expand Down

0 comments on commit 29bb49d

Please sign in to comment.