corva-convert-units
Advanced tools
Comparing version 1.18.1 to 1.19.0
# Changelog | ||
## [1.19.0](https://github.com/corva-ai/corva-convert-units/compare/v1.18.1...v1.19.0) (2024-08-09) | ||
### Features | ||
* **DRI-1234:** added new aliases ([#54](https://github.com/corva-ai/corva-convert-units/issues/54)) ([f5c8377](https://github.com/corva-ai/corva-convert-units/commit/f5c8377df4cb367048bfc72d1d021a008935acb7)) | ||
* **FUS-1116:** add method to convert alias into unit key ([#52](https://github.com/corva-ai/corva-convert-units/issues/52)) ([6716de3](https://github.com/corva-ai/corva-convert-units/commit/6716de31b6fbcf10b1496f3283cb28d5ca4caebf)) | ||
## [1.18.1](https://github.com/corva-ai/corva-convert-units/compare/v1.18.0...v1.18.1) (2024-07-08) | ||
@@ -4,0 +12,0 @@ |
@@ -23,3 +23,4 @@ // NOTE: Source PR not merged yet into 'convert-units': | ||
aliases: [ | ||
"deg" | ||
"deg", | ||
"degrees", | ||
] | ||
@@ -26,0 +27,0 @@ }, |
@@ -43,3 +43,3 @@ /** | ||
"rpm", | ||
"rev/m" | ||
"rev/m", | ||
] | ||
@@ -46,0 +46,0 @@ }, |
@@ -71,3 +71,12 @@ const { g } = require("../constants"); | ||
aliases: ['kPa/m'], | ||
} | ||
}, | ||
'mg/l': { | ||
name: { | ||
singular: 'Milligram per Liter', | ||
plural: 'Milligrams per Liter', | ||
display: 'mg/l' | ||
}, | ||
to_anchor: 1 / 1000000, | ||
aliases: ['mg/l', 'mg/L'], | ||
}, | ||
}; | ||
@@ -83,3 +92,3 @@ | ||
to_anchor: 1, | ||
aliases: ['lb/gal', 'lbm/gal', 'lbm/galUS', 'lbs/galUS'], | ||
aliases: ['lb/gal', 'lbm/gal', 'lbm/galUS', 'lbs/galUS', 'lbs_per_gal'], | ||
}, | ||
@@ -173,11 +182,2 @@ /** | ||
}, | ||
'mg/l': { | ||
name: { | ||
singular: 'Milligram per Liter', | ||
plural: 'Milligrams per Liter', | ||
display: 'mg/l' | ||
}, | ||
to_anchor: 1 / 1000000, | ||
aliases: ['mg/l', 'mg/L'], | ||
}, | ||
}; | ||
@@ -184,0 +184,0 @@ |
@@ -79,3 +79,3 @@ var metric, imperial; | ||
}, | ||
nd32: { | ||
'32nd': { | ||
name: { | ||
@@ -82,0 +82,0 @@ singular: '1/32 part of an Inch', |
@@ -102,2 +102,13 @@ var metric, imperial; | ||
] | ||
}, | ||
klbs: { | ||
name: { | ||
singular: 'Kilopound', | ||
plural: 'Kilopounds', | ||
display: 'klbs' | ||
}, | ||
to_anchor: 1000, | ||
aliases: [ | ||
"klbs", | ||
] | ||
} | ||
@@ -104,0 +115,0 @@ }; |
@@ -158,3 +158,3 @@ var metric, imperial; | ||
aliases: [ | ||
"hsf" | ||
"hsf", "lbf/100 ft2", "lbf/100ft2", "lbf/(100·ft²)", "lb/100ft2" | ||
] | ||
@@ -161,0 +161,0 @@ } |
@@ -10,3 +10,5 @@ const metric = { | ||
aliases: [ | ||
"%" | ||
"%", | ||
"percent", | ||
"flow_percent", | ||
] | ||
@@ -13,0 +15,0 @@ }, |
@@ -103,3 +103,4 @@ var metric, imperial; | ||
aliases: [ | ||
"ft/h" | ||
"ft/h", | ||
"ft_per_hr", | ||
] | ||
@@ -106,0 +107,0 @@ } |
@@ -12,3 +12,3 @@ const metric = { | ||
"spm", | ||
"1/m" | ||
"1/m", | ||
] | ||
@@ -15,0 +15,0 @@ }, |
@@ -163,14 +163,2 @@ var metric, imperial; | ||
] | ||
}, | ||
mlmin: { | ||
name: { | ||
singular: 'Millilitre per 30 Minutes', | ||
plural: 'Millilitres per 30 Minutes', | ||
display: 'ml/30min' | ||
}, | ||
to_anchor: 1 / 1800000, | ||
aliases: [ | ||
'ml/30min', | ||
'mL/30 min' | ||
], | ||
} | ||
@@ -301,2 +289,3 @@ }; | ||
"bbls", | ||
"barrels" | ||
] | ||
@@ -303,0 +292,0 @@ } |
@@ -169,2 +169,14 @@ var metric | ||
], | ||
}, | ||
mlmin: { | ||
name: { | ||
singular: 'Millilitre per 30 Minutes', | ||
plural: 'Millilitres per 30 Minutes', | ||
display: 'ml/30min' | ||
}, | ||
to_anchor: 1 / 1800000, | ||
aliases: [ | ||
'ml/30min', | ||
'mL/30 min' | ||
], | ||
} | ||
@@ -336,3 +348,4 @@ } | ||
aliases: [ | ||
"gal/min" | ||
"gal/min", | ||
'gal_per_min', | ||
] | ||
@@ -339,0 +352,0 @@ } |
@@ -53,2 +53,4 @@ const unitBucketMapping = require('./definitions/unitBucketMapping'); | ||
let unitsByAlias; | ||
Converter = function(numerator, measure) { | ||
@@ -332,7 +334,15 @@ this.unitBucketMapping = unitBucketMapping; | ||
/** | ||
* Detailed list of all supported units | ||
* @param {string} [measure] | ||
*/ | ||
Converter.prototype.list = function(measure) { | ||
const describeWithAlias = function(resp) { | ||
return { | ||
abbr: resp.abbr, | ||
measure: resp.measure, | ||
system: resp.system, | ||
singular: resp.unit.name.singular, | ||
plural: resp.unit.name.plural, | ||
display: resp.unit.name.display, | ||
aliases: resp.unit.aliases, | ||
}; | ||
}; | ||
const unitList = function(measure, unitDecorator) { | ||
var list = []; | ||
@@ -349,3 +359,3 @@ | ||
each(units, function(unit, abbr) { | ||
list = list.concat(describe({ | ||
list = list.concat(unitDecorator({ | ||
abbr: abbr, | ||
@@ -361,4 +371,20 @@ measure: testMeasure, | ||
return list; | ||
} | ||
/** | ||
* Detailed list of all supported units | ||
* @param {string} [measure] | ||
*/ | ||
Converter.prototype.list = function(measure) { | ||
return unitList(measure, describe); | ||
}; | ||
/** | ||
* Detailed list of all supported units with aliases | ||
* @param {string} [measure] | ||
*/ | ||
Converter.prototype.listWithAlias = function(measure) { | ||
return unitList(measure, describeWithAlias); | ||
}; | ||
Converter.prototype.throwUnsupportedUnitError = function(what) { | ||
@@ -431,2 +457,27 @@ var validUnits = []; | ||
Converter.prototype.getUnitKeyByAlias = function(alias) { | ||
if (!unitsByAlias) { | ||
unitsByAlias = Object.values(measures).reduce((measureRes, systems) => { | ||
const systemAliases = Object.entries(systems).reduce((systemRes, [system, units]) => { | ||
if (system == '_anchors') return systemRes; | ||
const unitAliases = Object.entries(units).reduce((unitRes, [abbr, unit]) => { | ||
for (const alias of unit.aliases ?? []) { | ||
unitRes[alias] = abbr; | ||
} | ||
unitRes[abbr] = abbr; | ||
return unitRes; | ||
}, {}); | ||
return { ...systemRes, ...unitAliases }; | ||
}, {}); | ||
return { ...measureRes, ...systemAliases}; | ||
}, {}); | ||
} | ||
return unitsByAlias[alias]; | ||
} | ||
convert = function(value, measure = undefined) { | ||
@@ -433,0 +484,0 @@ return new Converter(value, measure); |
{ | ||
"name": "corva-convert-units", | ||
"version": "1.18.1", | ||
"version": "1.19.0", | ||
"description": "Convert between quantities in different units", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92650
4445