UNPKG

geneea-nlp-client

Version:

The TypeScript Client for Geneea Interpretor G3 API.

51 lines (50 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isSequential = isSequential; exports.isSorted = isSorted; exports.objToStr = objToStr; exports.serializeMap = serializeMap; /** Checks whether the nums sequence is a subsequence of integers, i.e. n, n+1, n+2, ... */ function isSequential(nums) { return nums.length > 1 ? nums.slice(1).every((x, i) => nums[i] === x - 1) : true; } /** Checks whether the nums sequence is sorted. */ function isSorted(nums) { return nums.length > 1 ? nums.slice(1).every((x, i) => nums[i] <= x) : true; } /** * Converts an object to a human-readable representation. * @param obj The target object. * @param props A sequence of object properties to include in the output. * @returns A human-readable string for the given object. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any function objToStr(obj, props) { var _a; // TODO: Cover all possible cases once reading from json is supported // and we can straightforwardly test the function. const name = obj.constructor.name; const values = []; for (const p of props) { let val = (_a = obj[p]) !== null && _a !== void 0 ? _a : null; if (val !== null) { if (val instanceof String) { val = `"${val}"`; } else if (Array.isArray(val)) { val = JSON.stringify(val); } values.push(`${p}=${val.toString()}`); } } return `${name}(${values.join(", ")})`; } /** * Converts a Map instance into an object with corresponding keys and values * or null if the map has no entries. */ function serializeMap(map) { return map.size > 0 ? Object.fromEntries(map) : null; }