diff --git a/index.js b/index.js index 99b6f8e..d7cdb8f 100644 --- a/index.js +++ b/index.js @@ -18,9 +18,7 @@ const cache = new QuickLru({maxSize: 100_000}); const isObject = value => typeof value === 'object' && value !== null - && !(value instanceof RegExp) - && !(value instanceof Error) - && !(value instanceof Date); + && (Array.isArray(value) || Object.getPrototypeOf(value) === Object.prototype); const transform = (input, options = {}) => { if (!isObject(input)) { diff --git a/test.js b/test.js index a39d6c4..8470dbd 100644 --- a/test.js +++ b/test.js @@ -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'; @@ -136,6 +137,11 @@ test('use locale independent camel-case transformation', async t => { ); }); +test('do not deep convert data', t => { + const input = {foo: Buffer.from('foo')}; + t.true(camelcaseKeys(input, {deep: true}).foo instanceof Uint8Array); +}); + /** Executes the library with the given arguments and resolves with the parsed result.