5 changed files with 320 additions and 4 deletions
@ -0,0 +1,183 @@ |
|||
///
|
|||
/// Copyright © 2016-2025 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { TbMeasure, TbMeasureUnits } from '@shared/models/unit.models'; |
|||
|
|||
export type LengthUnits = LengthMetricUnits | LengthImperialUnits; |
|||
|
|||
export type LengthMetricUnits = 'nm' | 'μm' | 'mm' | 'cm' | 'dm' | 'm' | 'km' | 'angstrom'; |
|||
export type LengthImperialUnits = |
|||
| 'in' |
|||
| 'yd' |
|||
| 'ft-us' |
|||
| 'ft' |
|||
| 'fathom' |
|||
| 'mi' |
|||
| 'nmi' |
|||
| 'thou' |
|||
| 'barleycorn' |
|||
| 'hand' |
|||
| 'ch' |
|||
| 'fur' |
|||
| 'league' |
|||
| 'link' |
|||
| 'rod' |
|||
| 'cable' |
|||
| 'AU'; |
|||
|
|||
const METRIC: TbMeasureUnits<LengthMetricUnits> = { |
|||
ratio: 3.28084, |
|||
units: { |
|||
nm: { |
|||
name: 'unit.nanometer', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'nanoscale', 'atomic scale', 'molecular scale', 'nanometer', 'nanometers', 'nm'], |
|||
to_anchor: 1e-9, |
|||
}, |
|||
μm: { |
|||
name: 'unit.micrometer', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'microns', 'micrometer', 'micrometers', 'µm'], |
|||
to_anchor: 1e-6, |
|||
}, |
|||
mm: { |
|||
name: 'unit.millimeter', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'millimeter', 'millimeters', 'rainfall', 'precipitation', 'displacement', 'position', 'movement', 'transition', 'mm'], |
|||
to_anchor: 1e-3, |
|||
}, |
|||
cm: { |
|||
name: 'unit.centimeter', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'centimeter', 'centimeters', 'rainfall', 'precipitation', 'displacement', 'position', 'movement', 'transition', 'cm'], |
|||
to_anchor: 1e-2, |
|||
}, |
|||
dm: { |
|||
name: 'unit.decimeter', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'decimeter', 'decimeters', 'dm'], |
|||
to_anchor: 1e-1, |
|||
}, |
|||
m: { |
|||
name: 'unit.meter', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'meter', 'meters', 'm'], |
|||
to_anchor: 1, |
|||
}, |
|||
km: { |
|||
name: 'unit.kilometer', |
|||
tags: ['distance', 'height', 'length', 'width', 'gap', 'depth', 'kilometer', 'kilometers', 'km'], |
|||
to_anchor: 1e3, |
|||
}, |
|||
angstrom: { |
|||
name: 'unit.angstrom', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'atomic scale', 'atomic distance', 'nanoscale', 'angstrom', 'angstroms', 'Å'], |
|||
to_anchor: 1e-10, |
|||
}, |
|||
}, |
|||
}; |
|||
|
|||
const IMPERIAL: TbMeasureUnits<LengthImperialUnits> = { |
|||
ratio: 1 / 3.28084, |
|||
units: { |
|||
in: { |
|||
name: 'unit.inch', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'inch', 'inches', 'in'], |
|||
to_anchor: 1 / 12, |
|||
}, |
|||
yd: { |
|||
name: 'unit.yard', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'yard', 'yards', 'yd'], |
|||
to_anchor: 3, |
|||
}, |
|||
'ft-us': { |
|||
name: 'unit.foot-us', |
|||
tags: ['length', 'us survey foot', 'us survey feet', 'ft-us', 'surveying'], |
|||
to_anchor: 1.000002, |
|||
}, |
|||
ft: { |
|||
name: 'unit.foot', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'foot', 'feet', 'ft'], |
|||
to_anchor: 1, |
|||
}, |
|||
fathom: { |
|||
name: 'unit.fathom', |
|||
tags: ['depth', 'nautical measurement', 'fathom'], |
|||
to_anchor: 6, |
|||
}, |
|||
mi: { |
|||
name: 'unit.mile', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'mile', 'miles', 'mi'], |
|||
to_anchor: 5280, |
|||
}, |
|||
nmi: { |
|||
name: 'unit.nautical-mile', |
|||
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'nautical mile', 'nmi'], |
|||
to_anchor: 6076.12, |
|||
}, |
|||
thou: { |
|||
name: 'unit.thou', |
|||
tags: ['length', 'measurement', 'thou'], |
|||
to_anchor: 0.001 / 12, |
|||
}, |
|||
barleycorn: { |
|||
name: 'unit.barleycorn', |
|||
tags: ['length', 'shoe size', 'barleycorn'], |
|||
to_anchor: 1 / 36, |
|||
}, |
|||
hand: { |
|||
name: 'unit.hand', |
|||
tags: ['length', 'horse measurement', 'hand'], |
|||
to_anchor: 4 / 12, |
|||
}, |
|||
ch: { |
|||
name: 'unit.chain', |
|||
tags: ['length', 'land surveying', 'ch'], |
|||
to_anchor: 66, |
|||
}, |
|||
fur: { |
|||
name: 'unit.furlong', |
|||
tags: ['length', 'land surveying', 'fur'], |
|||
to_anchor: 660, |
|||
}, |
|||
league: { |
|||
name: 'unit.league', |
|||
tags: ['length', 'historical measurement', 'league'], |
|||
to_anchor: 3 * 5280, |
|||
}, |
|||
link: { |
|||
name: 'unit.link', |
|||
tags: ['length', 'land surveying', 'link'], |
|||
to_anchor: 0.66, |
|||
}, |
|||
rod: { |
|||
name: 'unit.rod', |
|||
tags: ['length', 'land surveying', 'rod'], |
|||
to_anchor: 16.5, |
|||
}, |
|||
cable: { |
|||
name: 'unit.cable', |
|||
tags: ['distance', 'nautical measurement', 'cable'], |
|||
to_anchor: 600, |
|||
}, |
|||
AU: { |
|||
name: 'unit.astronomical-unit', |
|||
tags: ['distance', 'celestial bodies', 'solar system', 'AU'], |
|||
to_anchor: 149597870700 * 3.28084, |
|||
}, |
|||
}, |
|||
}; |
|||
|
|||
const measure: TbMeasure<LengthUnits> = { |
|||
METRIC, |
|||
IMPERIAL |
|||
}; |
|||
|
|||
export default measure; |
|||
@ -0,0 +1,121 @@ |
|||
///
|
|||
/// Copyright © 2016-2025 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { TbMeasure, TbMeasureUnits } from '@shared/models/unit.models'; |
|||
|
|||
export type MassUnits = MassMetricUnits | MassImperialUnits; |
|||
|
|||
export type MassMetricUnits = 'ng' | 'mcg' | 'mg' | 'g' | 'kg' | 't' | 'Da'; |
|||
export type MassImperialUnits = 'oz' | 'lb' | 'st' | 'short tons' | 'gr' | 'dr' | 'qr' | 'cwt' | 'slug'; |
|||
|
|||
const METRIC: TbMeasureUnits<MassMetricUnits> = { |
|||
ratio: 1 / 453.59237, |
|||
units: { |
|||
ng: { |
|||
name: 'unit.nanogram', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'nanogram', 'nanograms', 'ng'], |
|||
to_anchor: 1e-9, |
|||
}, |
|||
mcg: { |
|||
name: 'unit.microgram', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'μg', 'microgram'], |
|||
to_anchor: 1e-6, |
|||
}, |
|||
mg: { |
|||
name: 'unit.milligram', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'milligram', 'miligrams', 'mg'], |
|||
to_anchor: 1e-3, |
|||
}, |
|||
g: { |
|||
name: 'unit.gram', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'gram', 'grams', 'g'], |
|||
to_anchor: 1, |
|||
}, |
|||
kg: { |
|||
name: 'unit.kilogram', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'kilogram', 'kilograms', 'kg'], |
|||
to_anchor: 1000, // 1 kg = 1000 g
|
|||
}, |
|||
t: { |
|||
name: 'unit.tonne', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'tonne', 'tons', 't'], |
|||
to_anchor: 1000000, |
|||
}, |
|||
Da: { |
|||
name: 'unit.dalton', |
|||
tags: ['atomic mass unit', 'AMU', 'unified atomic mass unit', 'dalton', 'Da'], |
|||
to_anchor: 1.66053906660e-24, |
|||
}, |
|||
}, |
|||
}; |
|||
|
|||
const IMPERIAL: TbMeasureUnits<MassImperialUnits> = { |
|||
ratio: 453.59237, |
|||
units: { |
|||
oz: { |
|||
name: 'unit.ounce', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'ounce', 'ounces', 'oz'], |
|||
to_anchor: 1 / 16, |
|||
}, |
|||
lb: { |
|||
name: 'unit.pound', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'pound', 'pounds', 'lb'], |
|||
to_anchor: 1, |
|||
}, |
|||
st: { |
|||
name: 'unit.stone', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'stone', 'stones', 'st'], |
|||
to_anchor: 14, |
|||
}, |
|||
'short tons': { |
|||
name: 'unit.short-tons', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'short ton', 'short tons'], |
|||
to_anchor: 2000, |
|||
}, |
|||
gr: { |
|||
name: 'unit.grain', |
|||
tags: ['mass', 'measurement', 'grain', 'gr'], |
|||
to_anchor: 1 / 7000, |
|||
}, |
|||
dr: { |
|||
name: 'unit.drachm', |
|||
tags: ['mass', 'measurement', 'drachm', 'dr'], |
|||
to_anchor: 1 / 256, |
|||
}, |
|||
qr: { |
|||
name: 'unit.quarter', |
|||
tags: ['mass', 'measurement', 'quarter', 'qr'], |
|||
to_anchor: 28, |
|||
}, |
|||
cwt: { |
|||
name: 'unit.hundredweight-countt', |
|||
tags: ['mass', 'weight', 'heaviness', 'load', 'hundredweight count', 'cwt'], |
|||
to_anchor: 100, |
|||
}, |
|||
slug: { |
|||
name: 'unit.slug', |
|||
tags: ['mass', 'measurement', 'slug'], |
|||
to_anchor: 32.174, |
|||
}, |
|||
}, |
|||
}; |
|||
|
|||
const measure: TbMeasure<MassUnits> = { |
|||
METRIC, |
|||
IMPERIAL |
|||
}; |
|||
|
|||
export default measure; |
|||
Loading…
Reference in new issue