UNPKG

@itwin/presentation-shared

Version:

The package contains types and utilities used across different iTwin.js Presentation packages.

153 lines 5.16 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import { compareStrings, Id64 } from "@itwin/core-bentley"; /** @public */ export var InstanceKey; (function (InstanceKey) { /** * Checks whether the two given instance keys are equal. * @public */ function equals(lhs, rhs) { return lhs.className === rhs.className && lhs.id === rhs.id; } InstanceKey.equals = equals; /** * Compares two given instance keys. * @returns *- `0` if they are equal *- `negative value` if lhs key is less than rhs key *- `positive value` if lhs key is more than rhs key */ function compare(lhs, rhs) { const classNameCompareResult = compareStrings(lhs.className, rhs.className); if (classNameCompareResult !== 0) { return classNameCompareResult; } return compareStrings(lhs.id, rhs.id); } InstanceKey.compare = compare; })(InstanceKey || (InstanceKey = {})); /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare export var PrimitiveValue; (function (PrimitiveValue) { /** * Checks whether the given value is a `Point2d`. * @note Since `Point3d` is a superset of `Point2d`, this function will return `true` for `Point3d` as well. * @public */ function isPoint2d(value) { if (typeof value !== "object") { return false; } const pt = value; return pt.x !== undefined && pt.y !== undefined; } PrimitiveValue.isPoint2d = isPoint2d; /** * Checks whether the given value is a `Point3d`. * @public */ function isPoint3d(value) { if (typeof value !== "object") { return false; } const pt = value; return pt.x !== undefined && pt.y !== undefined && pt.z !== undefined; } PrimitiveValue.isPoint3d = isPoint3d; })(PrimitiveValue || (PrimitiveValue = {})); /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare export var TypedPrimitiveValue; (function (TypedPrimitiveValue) { /** * A function for a creating a `TypedPrimitiveValue` object. * @throws Error if primitive type and value are incompatible. * @public */ function create(value, type, koqName, extendedType) { switch (type) { case "Integer": case "Long": if (typeof value === "number") { return { type, extendedType, value, }; } break; case "Double": if (typeof value === "number") { return { type, koqName, extendedType, value, }; } break; case "Boolean": if (typeof value === "boolean") { return { type, extendedType, value, }; } break; case "Id": if (typeof value === "string" && Id64.isId64(value)) { return { type, extendedType, value, }; } break; case "String": if (typeof value === "string") { return { type, extendedType, value, }; } break; case "DateTime": if (typeof value === "string" || typeof value === "number" || value instanceof Date) { return { type, extendedType, value, }; } break; case "Point3d": if (PrimitiveValue.isPoint3d(value)) { return { type, extendedType, value, }; } break; case "Point2d": if (PrimitiveValue.isPoint2d(value)) { return { type, extendedType, value, }; } break; } throw new Error(`PrimitiveValueType ${type} isn't compatible with value ${JSON.stringify(value)}`); } TypedPrimitiveValue.create = create; })(TypedPrimitiveValue || (TypedPrimitiveValue = {})); //# sourceMappingURL=Values.js.map