UNPKG

@itwin/presentation-shared

Version:

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

156 lines 5.42 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); exports.TypedPrimitiveValue = exports.PrimitiveValue = exports.InstanceKey = void 0; const core_bentley_1 = require("@itwin/core-bentley"); /** @public */ 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 = (0, core_bentley_1.compareStrings)(lhs.className, rhs.className); if (classNameCompareResult !== 0) { return classNameCompareResult; } return (0, core_bentley_1.compareStrings)(lhs.id, rhs.id); } InstanceKey.compare = compare; })(InstanceKey || (exports.InstanceKey = InstanceKey = {})); /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare 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 || (exports.PrimitiveValue = PrimitiveValue = {})); /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare 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" && core_bentley_1.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 || (exports.TypedPrimitiveValue = TypedPrimitiveValue = {})); //# sourceMappingURL=Values.js.map