Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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());
}
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);
}
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());
}