How to use @bentley/imodeljs-quantity - 10 common examples

To help you get started, we’ve selected a few @bentley/imodeljs-quantity examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / core / frontend / src / QuantityFormatter.ts View on Github external
public async findUnit(unitLabel: string, unitFamily?: string): Promise {
    for (const entry of unitData) {
      if (unitFamily) {
        if (entry.unitFamily !== unitFamily)
          continue;
      }
      if (entry.displayLabel === unitLabel || entry.name === unitLabel) {
        const unitProps = new BasicUnit(entry.name, entry.displayLabel, entry.unitFamily, entry.altDisplayLabels);
        return Promise.resolve(unitProps);
      }

      if (entry.altDisplayLabels && entry.altDisplayLabels.length > 0) {
        if (entry.altDisplayLabels.findIndex((ref) => ref === unitLabel) !== -1) {
          const unitProps = new BasicUnit(entry.name, entry.displayLabel, entry.unitFamily, entry.altDisplayLabels);
          return Promise.resolve(unitProps);
        }
      }
    }

    return Promise.resolve(new BadUnit());
  }
github imodeljs / imodeljs / core / frontend / src / QuantityFormatter.ts View on Github external
public async getUnitsByFamily(unitFamily: string): Promise {
    const units: UnitProps[] = [];
    for (const entry of unitData) {
      if (entry.unitFamily !== unitFamily)
        continue;
      units.push(new BasicUnit(entry.name, entry.displayLabel, entry.unitFamily, entry.altDisplayLabels));
    }
    return Promise.resolve(units);
  }
github imodeljs / imodeljs / core / frontend / src / QuantityFormatter.ts View on Github external
public async findUnitByName(unitName: string): Promise {
    const unitDataEntry = this.findUnitDefinition(unitName);
    if (unitDataEntry) {
      return Promise.resolve(new BasicUnit(unitDataEntry.name, unitDataEntry.displayLabel, unitDataEntry.unitFamily, unitDataEntry.altDisplayLabels));
    }
    return Promise.resolve(new BadUnit());
  }
github imodeljs / imodeljs / core / frontend / src / QuantityFormatter.ts View on Github external
continue;
      }
      if (entry.displayLabel === unitLabel || entry.name === unitLabel) {
        const unitProps = new BasicUnit(entry.name, entry.displayLabel, entry.unitFamily, entry.altDisplayLabels);
        return Promise.resolve(unitProps);
      }

      if (entry.altDisplayLabels && entry.altDisplayLabels.length > 0) {
        if (entry.altDisplayLabels.findIndex((ref) => ref === unitLabel) !== -1) {
          const unitProps = new BasicUnit(entry.name, entry.displayLabel, entry.unitFamily, entry.altDisplayLabels);
          return Promise.resolve(unitProps);
        }
      }
    }

    return Promise.resolve(new BadUnit());
  }
github imodeljs / imodeljs / core / frontend / src / QuantityFormatter.ts View on Github external
public async findUnitByName(unitName: string): Promise {
    const unitDataEntry = this.findUnitDefinition(unitName);
    if (unitDataEntry) {
      return Promise.resolve(new BasicUnit(unitDataEntry.name, unitDataEntry.displayLabel, unitDataEntry.unitFamily, unitDataEntry.altDisplayLabels));
    }
    return Promise.resolve(new BadUnit());
  }
github imodeljs / imodeljs / core / frontend / src / QuantityFormatter.ts View on Github external
protected async loadFormatSpecsForQuantityTypes(useImperial: boolean): Promise {
    const typeArray: QuantityType[] = [QuantityType.Length, QuantityType.Angle, QuantityType.Area, QuantityType.Volume, QuantityType.LatLong, QuantityType.Coordinate, QuantityType.Stationing, QuantityType.LengthSurvey, QuantityType.LengthEngineering];
    const activeMap = useImperial ? this._imperialFormatSpecsByType : this._metricFormatSpecsByType;
    activeMap.clear();

    for (const quantityType of typeArray) {
      const formatPromise = this.getFormatByQuantityType(quantityType, useImperial);
      const unitPromise = this.getUnitByQuantityType(quantityType);
      const [format, unit] = await Promise.all([formatPromise, unitPromise]);
      const spec = await FormatterSpec.create(format.name, format, this, unit);
      activeMap.set(quantityType, spec);
    }
    return Promise.resolve();
  }
github imodeljs / imodeljs / core / frontend / src / QuantityFormatter.ts View on Github external
protected async loadParsingSpecsForQuantityTypes(useImperial: boolean): Promise {
    const typeArray: QuantityType[] = [QuantityType.Length, QuantityType.Angle, QuantityType.Area, QuantityType.Volume, QuantityType.LatLong, QuantityType.Coordinate, QuantityType.Stationing, QuantityType.LengthSurvey, QuantityType.LengthEngineering];
    const activeMap = useImperial ? this._imperialParserSpecsByType : this._metricUnitParserSpecsByType;
    activeMap.clear();

    for (const quantityType of typeArray) {
      const formatPromise = this.getFormatByQuantityType(quantityType, useImperial);
      const unitPromise = this.getUnitByQuantityType(quantityType);
      const [format, outUnit] = await Promise.all([formatPromise, unitPromise]);
      const parserSpec = await ParserSpec.create(format, this, outUnit);
      activeMap.set(quantityType, parserSpec);
    }
    return Promise.resolve();
  }
github imodeljs / imodeljs / core / frontend / src / QuantityFormatter.ts View on Github external
protected async loadStdFormat(type: QuantityType, imperial: boolean): Promise {
    let formatData: any;

    const formatArray = imperial ? defaultsFormats.imperial : defaultsFormats.metric;
    for (const entry of formatArray) {
      if (entry.type === type as number) {
        formatData = entry.format;
        const format = new Format("stdFormat");
        await format.fromJson(this, formatData);
        return Promise.resolve(format);
      }
    }
    throw new BentleyError(BentleyStatus.ERROR, "IModelApp must define a formatsProvider class to provide formats for tools");
  }
github imodeljs / imodeljs / core / frontend / src / QuantityFormatter.ts View on Github external
public formatQuantity(magnitude: number, formatSpec: FormatterSpec): string {
    return Formatter.formatQuantity(magnitude, formatSpec);
  }
github imodeljs / imodeljs / core / frontend / src / QuantityFormatter.ts View on Github external
public parseIntoQuantityValue(inString: string, parserSpec: ParserSpec): ParseResult {
    return Parser.parseQuantityString(inString, parserSpec);
  }