Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not deep convert buffers #126

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const cache = new QuickLru({maxSize: 100_000});
const isObject = value =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name here no longer makes any sense.

typeof value === 'object'
&& value !== null
&& !(value instanceof RegExp)
&& !(value instanceof Error)
&& !(value instanceof Date);
&& (Array.isArray(value) || Object.getPrototypeOf(value) === Object.prototype);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move Object.getPrototypeOf(value) === Object.prototype out into a const function to improve readability by giving it a name.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I think the behavior should be documented.


const transform = (input, options = {}) => {
if (!isObject(input)) {
Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import process from 'node:process';
import {promisify} from 'node:util';
import {execFile} from 'node:child_process';
import {Buffer} from 'node:buffer';
import test from 'ava';
import camelcaseKeys from './index.js';

Expand Down Expand Up @@ -136,6 +137,11 @@ test('use locale independent camel-case transformation', async t => {
);
});

test('do not deep convert buffer', t => {
const input = {foo: Buffer.from('foo')};
t.true(camelcaseKeys(input, {deep: true}).foo instanceof Buffer);
});

/**
Executes the library with the given arguments and resolves with the parsed result.

Expand Down