0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-04-15 03:02:51 -05:00

fix(core): fix bug about isObject function (#3647)

This commit is contained in:
薄涛 2023-02-23 18:24:26 +08:00 committed by GitHub
parent 1641dc3325
commit 378e907d53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 7 deletions

View file

@ -0,0 +1,5 @@
---
'@verdaccio/core': patch
---
fix(core): fix `isObject` function.`isObject(true)` should return false.

View file

@ -95,14 +95,15 @@ export function normalizeMetadata(manifest: Manifest, name: string): Manifest {
* @return {Boolean} * @return {Boolean}
*/ */
export function isObject(obj: any): boolean { export function isObject(obj: any): boolean {
if (obj === null || typeof obj === 'undefined' || typeof obj === 'string') { // if (obj === null || typeof obj === 'undefined' || typeof obj === 'string') {
return false; // return false;
} // }
return ( // return (
(typeof obj === 'object' || typeof obj.prototype === 'undefined') && // (typeof obj === 'object' || typeof obj.prototype === 'undefined') &&
Array.isArray(obj) === false // Array.isArray(obj) === false
); // );
return Object.prototype.toString.call(obj) === '[object Object]';
} }
export function validatePassword( export function validatePassword(

View file

@ -31,6 +31,7 @@ describe('isObject', () => {
expect(isObject(['foo'])).toBeFalsy(); expect(isObject(['foo'])).toBeFalsy();
expect(isObject(null)).toBeFalsy(); expect(isObject(null)).toBeFalsy();
expect(isObject(undefined)).toBeFalsy(); expect(isObject(undefined)).toBeFalsy();
expect(isObject(true)).toBeFalsy();
}); });
}); });