Skip to content

Commit

Permalink
prevent non string keys
Browse files Browse the repository at this point in the history
  • Loading branch information
pawel-id committed Mar 3, 2024
1 parent fa0911d commit 44adf7c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import assert from 'node:assert'

/**
* Lower first letter of the string.
*/
Expand Down Expand Up @@ -49,7 +51,7 @@ function _lowerCamelCase(name: string) {
* @param obj object to traverse
* @param fn function to apply
*/
export function morph(
function morph(
obj: any,
fn: (key: string, value: any) => { key: string; value: any }
) {
Expand All @@ -60,6 +62,8 @@ export function morph(
}
} else {
for (let [key, value] of Object.entries(obj)) {
// technically this should never happen here, but let's be safe
assert(typeof key === 'string', 'Only string keys are supported')
if (typeof value === 'object') {
morph(value, fn)
} else {
Expand Down

0 comments on commit 44adf7c

Please sign in to comment.