File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -775,3 +775,15 @@ test("z.promise", async () => {
775
775
// // @ts -expect-error
776
776
// schema.assertOutput<string>();
777
777
// });
778
+
779
+ test ( "isPlainObject" , ( ) => {
780
+ expect ( z . core . util . isPlainObject ( { } ) ) . toEqual ( true ) ;
781
+ expect ( z . core . util . isPlainObject ( Object . create ( null ) ) ) . toEqual ( true ) ;
782
+ expect ( z . core . util . isPlainObject ( [ ] ) ) . toEqual ( false ) ;
783
+ expect ( z . core . util . isPlainObject ( new Date ( ) ) ) . toEqual ( false ) ;
784
+ expect ( z . core . util . isPlainObject ( null ) ) . toEqual ( false ) ;
785
+ expect ( z . core . util . isPlainObject ( undefined ) ) . toEqual ( false ) ;
786
+ expect ( z . core . util . isPlainObject ( "string" ) ) . toEqual ( false ) ;
787
+ expect ( z . core . util . isPlainObject ( 123 ) ) . toEqual ( false ) ;
788
+ expect ( z . core . util . isPlainObject ( Symbol ( ) ) ) . toEqual ( false ) ;
789
+ } ) ;
Original file line number Diff line number Diff line change @@ -333,7 +333,11 @@ export const allowsEval: { value: boolean } = cached(() => {
333
333
} ) ;
334
334
335
335
export function isPlainObject ( data : any ) : data is Record < PropertyKey , unknown > {
336
- return typeof data === "object" && data !== null && Object . getPrototypeOf ( data ) === Object . prototype ;
336
+ return (
337
+ typeof data === "object" &&
338
+ data !== null &&
339
+ ( Object . getPrototypeOf ( data ) === Object . prototype || Object . getPrototypeOf ( data ) === null )
340
+ ) ;
337
341
}
338
342
339
343
export function numKeys ( data : any ) : number {
You can’t perform that action at this time.
0 commit comments