From 5270e559ca5ef1fe16d295cc57276f014cd9ef09 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Fri, 10 May 2024 11:26:12 -0400 Subject: [PATCH] fix(pydeck-carto): Use local isPureObject (#8880) --- .../carto/src/api/request-with-parameters.ts | 2 +- modules/carto/src/utils.ts | 5 ++++ test/modules/carto/utils.spec.ts | 26 ++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/modules/carto/src/api/request-with-parameters.ts b/modules/carto/src/api/request-with-parameters.ts index f11cf4c95ea..44350c82b16 100644 --- a/modules/carto/src/api/request-with-parameters.ts +++ b/modules/carto/src/api/request-with-parameters.ts @@ -1,4 +1,4 @@ -import {isPureObject} from '@loaders.gl/core'; +import {isPureObject} from '../utils'; import {CartoAPIError} from './carto-api-error'; import {DEFAULT_HEADERS, DEFAULT_PARAMETERS, MAX_GET_LENGTH} from './common'; import type {APIErrorContext} from './types'; diff --git a/modules/carto/src/utils.ts b/modules/carto/src/utils.ts index 0b329b3efa2..971179e17b9 100644 --- a/modules/carto/src/utils.ts +++ b/modules/carto/src/utils.ts @@ -59,3 +59,8 @@ export function scaleIdentity() { return scale; } + +export const isObject: (x: unknown) => boolean = x => x !== null && typeof x === 'object'; + +export const isPureObject: (x: any) => boolean = x => + isObject(x) && x.constructor === {}.constructor; diff --git a/test/modules/carto/utils.spec.ts b/test/modules/carto/utils.spec.ts index 38898d10cc3..e3dc878995c 100644 --- a/test/modules/carto/utils.spec.ts +++ b/test/modules/carto/utils.spec.ts @@ -1,5 +1,11 @@ import test from 'tape-promise/tape'; -import {createBinaryProxy, getWorkerUrl, scaleIdentity} from '@deck.gl/carto/utils'; +import { + createBinaryProxy, + getWorkerUrl, + scaleIdentity, + isObject, + isPureObject +} from '@deck.gl/carto/utils'; test('createBinaryProxy', async t => { const binary = { @@ -54,3 +60,21 @@ test('scaleIdentity', async t => { t.end(); }); + +test('isObject', t => { + class TestClass {} + t.equal(isObject({}), true, 'object is object'); + t.equal(isObject(3), false, 'number is not object'); + t.equal(isObject([]), true, 'array is object'); + t.equal(isObject(new TestClass()), true, 'class instance is object'); + t.end(); +}); + +test('isPureObject', t => { + class TestClass {} + t.equal(isPureObject({}), true, 'object is pure'); + t.equal(isPureObject(3), false, 'number is not pure'); + t.equal(isPureObject([]), false, 'array is not pure'); + t.equal(isPureObject(new TestClass()), false, 'class instance is not pure'); + t.end(); +});