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 @@ -16,7 +16,8 @@ export default class KDBush {
1616 * @param {ArrayBufferLike } data
1717 */
1818 static from ( data ) {
19- if ( ! ( data instanceof ArrayBuffer ) && ! ( data instanceof SharedArrayBuffer ) ) {
19+ // @ts -expect-error duck typing array buffers
20+ if ( ! data || data . byteLength === undefined || data . buffer ) {
2021 throw new Error ( 'Data must be an instance of ArrayBuffer or SharedArrayBuffer.' ) ;
2122 }
2223 const [ magic , versionAndType ] = new Uint8Array ( data , 0 , 2 ) ;
@@ -62,12 +63,13 @@ export default class KDBush {
6263 throw new Error ( `Unexpected typed array class: ${ ArrayType } .` ) ;
6364 }
6465
65- if ( ( data instanceof ArrayBuffer ) || ( data instanceof SharedArrayBuffer ) ) { // reconstruct an index from a buffer
66+ if ( data ) { // reconstruct an index from a buffer
6667 this . data = data ;
6768 this . ids = new this . IndexArrayType ( this . data , HEADER_SIZE , numItems ) ;
6869 this . coords = new this . ArrayType ( this . data , HEADER_SIZE + idsByteSize + padCoords , numItems * 2 ) ;
6970 this . _pos = numItems * 2 ;
7071 this . _finished = true ;
72+
7173 } else { // initialize a new index
7274 this . data = new ArrayBufferType ( HEADER_SIZE + coordsByteSize + idsByteSize + padCoords ) ;
7375 this . ids = new this . IndexArrayType ( this . data , HEADER_SIZE , numItems ) ;
You can’t perform that action at this time.
0 commit comments