UNPKG

@geoapify/route-planner-sdk

Version:

A TypeScript SDK for the Geoapify Route Planner API that simplifies route optimization requests, and helps visualize and edit resulting routes.

24 lines (23 loc) 882 B
export class Utils { static cleanObject(obj) { if (Array.isArray(obj)) { // Remove empty arrays, otherwise clean elements recursively return obj.length > 0 ? obj.map(Utils.cleanObject) : undefined; } else if (obj !== null && typeof obj === "object") { // Remove empty objects and undefined values recursively const cleanedObj = Object.entries(obj).reduce((acc, [key, value]) => { const cleanedValue = Utils.cleanObject(value); if (cleanedValue !== undefined) { acc[key] = cleanedValue; } return acc; }, {}); return Object.keys(cleanedObj).length > 0 ? cleanedObj : undefined; } return obj; } static cloneObject(obj) { return JSON.parse(JSON.stringify(obj)); } }