File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed
Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -299,14 +299,16 @@ class Database {
299299 }
300300
301301 push ( key , valueLike , options = { } ) {
302+ const has = this . has ( key , options ) ;
303+ if ( ! has ) return this . set ( key , ! Array . isArray ( valueLike ) ? [ valueLike ] : valueLike , options ) ;
304+
302305 const data = this . get ( key , options ) ;
303- if ( ! data ) return this . set ( key , ! Array . isArray ( valueLike ) ? [ valueLike ] : valueLike , options ) ;
304306 if ( ! Array . isArray ( data ) ) throw new TypeError ( "Cannot use push with non-array type" ) ;
305307 if ( Array . isArray ( valueLike ) ) {
306308 const n = data . concat ( valueLike ) ;
307309 return this . set ( key , n , options ) ;
308310 }
309- const res = [ ] ;
311+ const res = [ ... data ] ;
310312 res . push ( valueLike ) ;
311313 return this . set ( key , res , options ) ;
312314 }
You can’t perform that action at this time.
0 commit comments