1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-20 17:05:52 +01: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

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

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

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