UNPKG

@itwin/presentation-hierarchies

Version:

A package for creating hierarchies based on data in iTwin.js iModels.

69 lines 2.7 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import "./DisposePolyfill.js"; import naturalCompare from "natural-compare-lite"; /** * This is a logging namespace for public log messages that may be interesting to consumers. * @internal */ export const LOGGING_NAMESPACE = "Presentation.Hierarchies"; /** * This is a logging namespace for public performance-related log messages that may be interesting to consumers. * @internal */ export const LOGGING_NAMESPACE_PERFORMANCE = `${LOGGING_NAMESPACE}.Performance`; /** * This is a logging namespace for internal log messages that are only interesting to package contributors, * but not the consumers. * @internal */ export const LOGGING_NAMESPACE_INTERNAL = "Presentation.HierarchiesInternal"; /** * This is a logging namespace for internal performance-related log messages that are only interesting * to package contributors, but not the consumers. * @internal */ export const LOGGING_NAMESPACE_PERFORMANCE_INTERNAL = `${LOGGING_NAMESPACE_INTERNAL}.Performance`; /** @internal */ export function createOperatorLoggingNamespace(operatorName, baseCategory) { return `${baseCategory}.Operators.${operatorName}`; } /** @internal */ /* v8 ignore start */ export function createNodeIdentifierForLogging(node) { if (!node) { return "<root>"; } const { label, key } = node; const parentKeys = "parentKeys" in node ? node.parentKeys : "<unknown>"; return JSON.stringify({ label, key, parentKeys }); } /* v8 ignore stop */ /** @internal */ export function hasChildren(node) { return node.children === true || (Array.isArray(node.children) && node.children.length > 0); } /** @internal */ export function compareNodesByLabel(lhs, rhs) { return naturalCompare(lhs.label.toLocaleLowerCase(), rhs.label.toLocaleLowerCase()); } /** * A helper that disposes the given object, if it's disposable. * * The first option is to dispose using the deprecated `dispose` method if it exists on the object. * If not, we use the new `Symbol.dispose` method. If that doesn't exist either, the object is * considered as non-disposable and nothing is done with it. * * @internal */ export function safeDispose(disposable) { if ("dispose" in disposable) { disposable.dispose(); } else if (Symbol.dispose in disposable) { disposable[Symbol.dispose](); } } //# sourceMappingURL=Common.js.map