New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@qudtlib/core

Package Overview
Dependencies
Maintainers
0
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qudtlib/core - npm Package Compare versions

Comparing version

to
6.8.0

8

dist/cjs/factorUnit.js

@@ -5,2 +5,3 @@ "use strict";

const utils_js_1 = require("./utils.js");
const dimensionVector_js_1 = require("./dimensionVector.js");
/**

@@ -155,2 +156,9 @@ * Combines a {@link Unit} and an exponent; some Units are a combination of {@link FactorUnit}s. If

}
getDimensionVector() {
if ((0, utils_js_1.isNullish)(this.unit.dimensionVectorIri)) {
return undefined;
}
const dv = new dimensionVector_js_1.DimensionVector(this.unit.dimensionVectorIri);
return dv.multiply(this.exponent);
}
static ofUnit(unit) {

@@ -157,0 +165,0 @@ return new FactorUnit(unit, 1);

34

dist/cjs/factorUnits.js

@@ -7,2 +7,3 @@ "use strict";

const unit_js_1 = require("./unit.js");
const dimensionVector_js_1 = require("./dimensionVector.js");
/**

@@ -14,2 +15,4 @@ * Class representing a set of FactorUnits and a conversionMultiplier, so the units can be

constructor(factorUnits, scaleFactor = utils_js_1.ONE) {
this.normalized = undefined;
this.dimensionVector = undefined;
this.factorUnits = factorUnits;

@@ -124,2 +127,5 @@ this.scaleFactor = scaleFactor;

normalize() {
if (!(0, utils_js_1.isNullish)(this.normalized)) {
return this.normalized;
}
let normalized = null;

@@ -136,3 +142,4 @@ if (this.hasFactorUnits()) {

}
return normalized.scale(this.scaleFactor);
this.normalized = normalized.scale(this.scaleFactor);
return this.normalized;
}

@@ -178,2 +185,27 @@ expand() {

}
getDimensionVector() {
if ((0, utils_js_1.isNullish)(this.dimensionVector)) {
this.dimensionVector = this.computeDimensionVector();
}
return this.dimensionVector;
}
computeDimensionVector() {
if ((0, utils_js_1.isNullish)(this.factorUnits) || this.factorUnits.length == 0) {
return dimensionVector_js_1.DimensionVector.DIMENSIONLESS;
}
let dv = undefined;
for (const fu of this.factorUnits) {
const factorUnitFeatureVector = fu.getDimensionVector();
if ((0, utils_js_1.isNullish)(factorUnitFeatureVector)) {
throw new Error(`Cannot compute dimension vector of factor units ${this.toString()}: ${fu.unit.getIriAbbreviated()} does not have a dimension vector`);
}
if ((0, utils_js_1.isNullish)(dv)) {
dv = factorUnitFeatureVector;
}
else {
dv = dv.combine(factorUnitFeatureVector);
}
}
return dv;
}
denominatorFactors() {

@@ -180,0 +212,0 @@ return this.factorUnits

@@ -11,3 +11,2 @@ "use strict";

const quantityValue_js_1 = require("./quantityValue.js");
3;
const qudtNamespaces_js_1 = require("./qudtNamespaces.js");

@@ -20,3 +19,17 @@ class QudtlibConfig {

this.systemsOfUnits = new Map();
this.unitsByDimensionVector = new Map();
}
indexUnitsByDimensionVector() {
this.units.forEach((u) => {
const dimVector = u.dimensionVectorIri;
if (!(0, utils_js_1.isNullish)(dimVector)) {
let unitsWithSameDimVector = this.unitsByDimensionVector.get(dimVector);
if ((0, utils_js_1.isNullish)(unitsWithSameDimVector)) {
unitsWithSameDimVector = [];
this.unitsByDimensionVector.set(dimVector, unitsWithSameDimVector);
}
unitsWithSameDimVector.push(u);
}
});
}
}

@@ -358,3 +371,8 @@ exports.QudtlibConfig = QudtlibConfig;

const matchingUnits = [];
for (const unit of exports.config.units.values()) {
const unitsWithSameDimVector = this.getUnitsByDimensionVector(initialFactorUnitSelection.getDimensionVector());
if ((0, utils_js_1.isNullish)(unitsWithSameDimVector) ||
unitsWithSameDimVector.length == 0) {
return [];
}
for (const unit of unitsWithSameDimVector) {
if (unit.matches(initialFactorUnitSelection)) {

@@ -367,2 +385,22 @@ matchingUnits.push(unit);

}
static getUnitsByDimensionVector(dimVector) {
let dimVectorIri = undefined;
if (typeof dimVector === "string") {
dimVectorIri = dimVector;
}
else {
dimVectorIri = dimVector.getDimensionVectorIri();
}
const unitsWithSameDimVector = exports.config.unitsByDimensionVector.get(dimVectorIri);
if ((0, utils_js_1.isNullish)(unitsWithSameDimVector)) {
return [];
}
return unitsWithSameDimVector;
}
static getUnitsWithSameDimensionVector(unit) {
if ((0, utils_js_1.isNullish)(unit.dimensionVectorIri)) {
throw new Error(`unit ${unit.getIriAbbreviated()} does not have a dimension vector iri`);
}
return this.getUnitsByDimensionVector(unit.dimensionVectorIri);
}
/**

@@ -380,3 +418,3 @@ * Returns the unit resulting from scaling the specified `unit` with the specified `prefix`.

const theUnit = baseUnit instanceof unit_js_1.Unit ? baseUnit : this.unitRequired(baseUnit);
for (const u of exports.config.units.values()) {
for (const u of this.getUnitsWithSameDimensionVector(theUnit)) {
if (u.prefix?.equals(thePrefix) && u.scalingOf?.equals(theUnit)) {

@@ -383,0 +421,0 @@ return u;

@@ -5,2 +5,3 @@ import { SupportsEquals } from "./baseTypes.js";

import { Decimal } from "decimal.js";
import { DimensionVector } from "./dimensionVector.js";
/**

@@ -44,4 +45,5 @@ * Combines a {@link Unit} and an exponent; some Units are a combination of {@link FactorUnit}s. If

static getAllPossibleFactorUnitCombinations(factorUnits: FactorUnit[]): FactorUnit[][];
getDimensionVector(): DimensionVector | undefined;
static ofUnit(unit: Unit): FactorUnit;
}
//# sourceMappingURL=factorUnit.d.ts.map

@@ -5,2 +5,3 @@ import { SupportsEquals } from "./baseTypes.js";

import { Decimal } from "decimal.js";
import { DimensionVector } from "./dimensionVector.js";
/**

@@ -14,2 +15,4 @@ * Class representing a set of FactorUnits and a conversionMultiplier, so the units can be

readonly scaleFactor: Decimal;
private normalized?;
private dimensionVector?;
constructor(factorUnits: FactorUnit[], scaleFactor?: Decimal);

@@ -69,2 +72,4 @@ static ofUnit(unit: Unit): FactorUnits;

denominator(): FactorUnits;
getDimensionVector(): DimensionVector;
private computeDimensionVector;
private denominatorFactors;

@@ -71,0 +76,0 @@ getLocalname(): string;

@@ -1,2 +0,3 @@

import { arrayDeduplicate, arrayEqualsIgnoreOrdering, checkInteger, compareUsingEquals, } from "./utils.js";
import { arrayDeduplicate, arrayEqualsIgnoreOrdering, checkInteger, compareUsingEquals, isNullish, } from "./utils.js";
import { DimensionVector } from "./dimensionVector.js";
/**

@@ -151,2 +152,9 @@ * Combines a {@link Unit} and an exponent; some Units are a combination of {@link FactorUnit}s. If

}
getDimensionVector() {
if (isNullish(this.unit.dimensionVectorIri)) {
return undefined;
}
const dv = new DimensionVector(this.unit.dimensionVectorIri);
return dv.multiply(this.exponent);
}
static ofUnit(unit) {

@@ -153,0 +161,0 @@ return new FactorUnit(unit, 1);

import { FactorUnit } from "./factorUnit.js";
import { arrayEqualsIgnoreOrdering, compareUsingEquals, isNullish, ONE, } from "./utils.js";
import { Unit } from "./unit.js";
import { DimensionVector } from "./dimensionVector.js";
/**

@@ -10,2 +11,4 @@ * Class representing a set of FactorUnits and a conversionMultiplier, so the units can be

constructor(factorUnits, scaleFactor = ONE) {
this.normalized = undefined;
this.dimensionVector = undefined;
this.factorUnits = factorUnits;

@@ -120,2 +123,5 @@ this.scaleFactor = scaleFactor;

normalize() {
if (!isNullish(this.normalized)) {
return this.normalized;
}
let normalized = null;

@@ -132,3 +138,4 @@ if (this.hasFactorUnits()) {

}
return normalized.scale(this.scaleFactor);
this.normalized = normalized.scale(this.scaleFactor);
return this.normalized;
}

@@ -174,2 +181,27 @@ expand() {

}
getDimensionVector() {
if (isNullish(this.dimensionVector)) {
this.dimensionVector = this.computeDimensionVector();
}
return this.dimensionVector;
}
computeDimensionVector() {
if (isNullish(this.factorUnits) || this.factorUnits.length == 0) {
return DimensionVector.DIMENSIONLESS;
}
let dv = undefined;
for (const fu of this.factorUnits) {
const factorUnitFeatureVector = fu.getDimensionVector();
if (isNullish(factorUnitFeatureVector)) {
throw new Error(`Cannot compute dimension vector of factor units ${this.toString()}: ${fu.unit.getIriAbbreviated()} does not have a dimension vector`);
}
if (isNullish(dv)) {
dv = factorUnitFeatureVector;
}
else {
dv = dv.combine(factorUnitFeatureVector);
}
}
return dv;
}
denominatorFactors() {

@@ -176,0 +208,0 @@ return this.factorUnits

@@ -8,3 +8,2 @@ import { Unit } from "./unit.js";

import { QuantityValue } from "./quantityValue.js";
3;
import { QudtNamespaces } from "./qudtNamespaces.js";

@@ -17,3 +16,17 @@ export class QudtlibConfig {

this.systemsOfUnits = new Map();
this.unitsByDimensionVector = new Map();
}
indexUnitsByDimensionVector() {
this.units.forEach((u) => {
const dimVector = u.dimensionVectorIri;
if (!isNullish(dimVector)) {
let unitsWithSameDimVector = this.unitsByDimensionVector.get(dimVector);
if (isNullish(unitsWithSameDimVector)) {
unitsWithSameDimVector = [];
this.unitsByDimensionVector.set(dimVector, unitsWithSameDimVector);
}
unitsWithSameDimVector.push(u);
}
});
}
}

@@ -354,3 +367,8 @@ export const config = new QudtlibConfig();

const matchingUnits = [];
for (const unit of config.units.values()) {
const unitsWithSameDimVector = this.getUnitsByDimensionVector(initialFactorUnitSelection.getDimensionVector());
if (isNullish(unitsWithSameDimVector) ||
unitsWithSameDimVector.length == 0) {
return [];
}
for (const unit of unitsWithSameDimVector) {
if (unit.matches(initialFactorUnitSelection)) {

@@ -363,2 +381,22 @@ matchingUnits.push(unit);

}
static getUnitsByDimensionVector(dimVector) {
let dimVectorIri = undefined;
if (typeof dimVector === "string") {
dimVectorIri = dimVector;
}
else {
dimVectorIri = dimVector.getDimensionVectorIri();
}
const unitsWithSameDimVector = config.unitsByDimensionVector.get(dimVectorIri);
if (isNullish(unitsWithSameDimVector)) {
return [];
}
return unitsWithSameDimVector;
}
static getUnitsWithSameDimensionVector(unit) {
if (isNullish(unit.dimensionVectorIri)) {
throw new Error(`unit ${unit.getIriAbbreviated()} does not have a dimension vector iri`);
}
return this.getUnitsByDimensionVector(unit.dimensionVectorIri);
}
/**

@@ -376,3 +414,3 @@ * Returns the unit resulting from scaling the specified `unit` with the specified `prefix`.

const theUnit = baseUnit instanceof Unit ? baseUnit : this.unitRequired(baseUnit);
for (const u of config.units.values()) {
for (const u of this.getUnitsWithSameDimensionVector(theUnit)) {
if (u.prefix?.equals(thePrefix) && u.scalingOf?.equals(theUnit)) {

@@ -379,0 +417,0 @@ return u;

@@ -10,2 +10,3 @@ import { Unit } from "./unit.js";

import { SystemOfUnits } from "./systemOfUnits.js";
import { DimensionVector } from "./dimensionVector.js";
export declare class QudtlibConfig {

@@ -16,3 +17,5 @@ readonly units: Map<string, Unit>;

readonly systemsOfUnits: Map<string, SystemOfUnits>;
readonly unitsByDimensionVector: Map<string, Array<Unit>>;
constructor();
indexUnitsByDimensionVector(): void;
}

@@ -131,2 +134,4 @@ export declare const config: QudtlibConfig;

private static findMatchingUnits;
static getUnitsByDimensionVector(dimVector: DimensionVector | string): Array<Unit>;
static getUnitsWithSameDimensionVector(unit: Unit): Unit[];
/**

@@ -133,0 +138,0 @@ * Returns the unit resulting from scaling the specified `unit` with the specified `prefix`.

4

package.json
{
"name": "@qudtlib/core",
"version": "6.7.0",
"version": "6.8.0",
"description": "Data model for QUDTLib",

@@ -55,3 +55,3 @@ "main": "dist/cjs/qudtlib.js",

},
"gitHead": "ecc88a4fe9c3fbec7d9ef5930bfb6ecee9f945dd"
"gitHead": "5e8fc71cef2549d9bcdc7128450924bca239bdd6"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet