nhb-toolbox 4.23.10 → 4.23.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants.js +8 -6
- package/dist/cjs/converter/area.js +21 -31
- package/dist/cjs/converter/base.js +20 -1
- package/dist/cjs/converter/data.js +15 -25
- package/dist/cjs/converter/length.js +18 -28
- package/dist/cjs/converter/mass.js +18 -28
- package/dist/cjs/converter/temp.js +6 -16
- package/dist/cjs/converter/time.js +16 -26
- package/dist/cjs/converter/volume.js +33 -43
- package/dist/dts/constants.d.ts +1 -0
- package/dist/dts/converter/base.d.ts +40 -12
- package/dist/dts/converter/constants.d.ts +1 -1
- package/dist/dts/converter/temp.d.ts +1 -1
- package/dist/dts/converter/types.d.ts +2 -0
- package/dist/dts/converter/volume.d.ts +1 -1
- package/dist/esm/constants.js +1 -0
- package/dist/esm/converter/area.js +21 -31
- package/dist/esm/converter/base.js +20 -1
- package/dist/esm/converter/data.js +15 -25
- package/dist/esm/converter/length.js +18 -28
- package/dist/esm/converter/mass.js +18 -28
- package/dist/esm/converter/temp.js +6 -16
- package/dist/esm/converter/time.js +16 -26
- package/dist/esm/converter/volume.js +33 -43
- package/package.json +1 -1
package/dist/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STATUS_CODES = exports.HTTP_STATUS_CODES = exports.HTTP_STATUS = exports.HTTP_CODES = exports.COUNTRIES = exports.LOWERCASED_WORDS = exports.LOCALE_CODES = exports.FRANKFURTER_CURRENCIES = exports.CURRENCY_LOCALES = exports.CURRENCY_CODES = exports.CSS_COLORS = exports.NUMBER_COLOR_PALETTE = exports.ALPHABET_COLOR_PALETTE = exports.WESTERN_SEASONS = exports.US_ACADEMIC_SEASONS = exports.SEASON_PRESETS = exports.PHILIPPINES_SEASONS = exports.JAPAN_SEASONS = exports.INDIA_VEDIC_SEASONS = exports.INDIA_TAMIL_SEASONS = exports.INDIA_IMD_SEASONS = exports.ETHIOPIA_SEASONS = exports.BANGLADESH_SEASONS = exports.AUSTRALIA_SEASONS = exports.WESTERN_ZODIAC_SIGNS = exports.WEEK_DAYS = exports.VEDIC_ZODIAC_SIGNS = exports.TIME_ZONES = exports.TIME_ZONE_LABELS = exports.MONTHS = void 0;
|
|
3
|
+
exports.STATUS_CODES = exports.HTTP_STATUS_CODES = exports.HTTP_STATUS = exports.HTTP_CODES = exports.COUNTRIES = exports.UNITS = exports.LOWERCASED_WORDS = exports.LOCALE_CODES = exports.FRANKFURTER_CURRENCIES = exports.CURRENCY_LOCALES = exports.CURRENCY_CODES = exports.CSS_COLORS = exports.NUMBER_COLOR_PALETTE = exports.ALPHABET_COLOR_PALETTE = exports.WESTERN_SEASONS = exports.US_ACADEMIC_SEASONS = exports.SEASON_PRESETS = exports.PHILIPPINES_SEASONS = exports.JAPAN_SEASONS = exports.INDIA_VEDIC_SEASONS = exports.INDIA_TAMIL_SEASONS = exports.INDIA_IMD_SEASONS = exports.ETHIOPIA_SEASONS = exports.BANGLADESH_SEASONS = exports.AUSTRALIA_SEASONS = exports.WESTERN_ZODIAC_SIGNS = exports.WEEK_DAYS = exports.VEDIC_ZODIAC_SIGNS = exports.TIME_ZONES = exports.TIME_ZONE_LABELS = exports.MONTHS = void 0;
|
|
4
4
|
var constants_1 = require("./date/constants");
|
|
5
5
|
Object.defineProperty(exports, "MONTHS", { enumerable: true, get: function () { return constants_1.MONTHS; } });
|
|
6
6
|
Object.defineProperty(exports, "TIME_ZONE_LABELS", { enumerable: true, get: function () { return constants_1.TIME_ZONE_LABELS; } });
|
|
@@ -32,10 +32,12 @@ Object.defineProperty(exports, "FRANKFURTER_CURRENCIES", { enumerable: true, get
|
|
|
32
32
|
Object.defineProperty(exports, "LOCALE_CODES", { enumerable: true, get: function () { return constants_3.LOCALE_CODES; } });
|
|
33
33
|
var constants_4 = require("./string/constants");
|
|
34
34
|
Object.defineProperty(exports, "LOWERCASED_WORDS", { enumerable: true, get: function () { return constants_4.LOWERCASE; } });
|
|
35
|
+
var constants_5 = require("./converter/constants");
|
|
36
|
+
Object.defineProperty(exports, "UNITS", { enumerable: true, get: function () { return constants_5.UNITS; } });
|
|
35
37
|
var countries_1 = require("./object/countries");
|
|
36
38
|
Object.defineProperty(exports, "COUNTRIES", { enumerable: true, get: function () { return countries_1.COUNTRIES; } });
|
|
37
|
-
var
|
|
38
|
-
Object.defineProperty(exports, "HTTP_CODES", { enumerable: true, get: function () { return
|
|
39
|
-
Object.defineProperty(exports, "HTTP_STATUS", { enumerable: true, get: function () { return
|
|
40
|
-
Object.defineProperty(exports, "HTTP_STATUS_CODES", { enumerable: true, get: function () { return
|
|
41
|
-
Object.defineProperty(exports, "STATUS_CODES", { enumerable: true, get: function () { return
|
|
39
|
+
var constants_6 = require("./http-status/constants");
|
|
40
|
+
Object.defineProperty(exports, "HTTP_CODES", { enumerable: true, get: function () { return constants_6.HTTP_STATUS_CODES; } });
|
|
41
|
+
Object.defineProperty(exports, "HTTP_STATUS", { enumerable: true, get: function () { return constants_6.HTTP_STATUS_CODES; } });
|
|
42
|
+
Object.defineProperty(exports, "HTTP_STATUS_CODES", { enumerable: true, get: function () { return constants_6.HTTP_STATUS_CODES; } });
|
|
43
|
+
Object.defineProperty(exports, "STATUS_CODES", { enumerable: true, get: function () { return constants_6.HTTP_STATUS_CODES; } });
|
|
@@ -15,11 +15,11 @@ class $Area extends base_1.$BaseConverter {
|
|
|
15
15
|
'square-metre': 1,
|
|
16
16
|
'square-kilometre': 1e6,
|
|
17
17
|
'square-inch': 0.00064516,
|
|
18
|
-
'square-foot': 0.
|
|
19
|
-
'square-yard': 0.
|
|
20
|
-
'square-mile':
|
|
18
|
+
'square-foot': 0.09290304,
|
|
19
|
+
'square-yard': 0.83612736,
|
|
20
|
+
'square-mile': 2_589_988.110336,
|
|
21
21
|
hectare: 1e4,
|
|
22
|
-
acre:
|
|
22
|
+
acre: 4_046.8564224,
|
|
23
23
|
};
|
|
24
24
|
constructor(value, unit) {
|
|
25
25
|
super(value, unit);
|
|
@@ -41,33 +41,23 @@ class $Area extends base_1.$BaseConverter {
|
|
|
41
41
|
}
|
|
42
42
|
formatTo(target, options) {
|
|
43
43
|
const value = this.to(target);
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
hectare: 'ha',
|
|
62
|
-
acre: 'ac',
|
|
63
|
-
};
|
|
64
|
-
return `${rounded}${shortLabels[target]}`;
|
|
65
|
-
}
|
|
66
|
-
case 'scientific':
|
|
67
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
68
|
-
default:
|
|
69
|
-
return this.$withPluralUnit(rounded, target);
|
|
70
|
-
}
|
|
44
|
+
const shortLabels = {
|
|
45
|
+
'square-millimeter': 'mm²',
|
|
46
|
+
'square-centimeter': 'cm²',
|
|
47
|
+
'square-meter': 'm²',
|
|
48
|
+
'square-kilometer': 'km²',
|
|
49
|
+
'square-millimetre': 'mm²',
|
|
50
|
+
'square-centimetre': 'cm²',
|
|
51
|
+
'square-metre': 'm²',
|
|
52
|
+
'square-kilometre': 'km²',
|
|
53
|
+
'square-inch': 'in²',
|
|
54
|
+
'square-foot': 'ft²',
|
|
55
|
+
'square-yard': 'yd²',
|
|
56
|
+
'square-mile': 'mi²',
|
|
57
|
+
hectare: 'ha',
|
|
58
|
+
acre: 'ac',
|
|
59
|
+
};
|
|
60
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
71
61
|
}
|
|
72
62
|
}
|
|
73
63
|
exports.$Area = $Area;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.$BaseConverter = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
4
5
|
class $BaseConverter {
|
|
5
6
|
value;
|
|
6
7
|
unit;
|
|
@@ -20,6 +21,18 @@ class $BaseConverter {
|
|
|
20
21
|
const factor = 10 ** decimals;
|
|
21
22
|
return Math.round(value * factor) / factor;
|
|
22
23
|
}
|
|
24
|
+
$formatTo(value, target, shortLabels, options) {
|
|
25
|
+
const { style = 'plural', decimals = 2 } = options ?? {};
|
|
26
|
+
const rounded = this.$round(value, decimals);
|
|
27
|
+
switch (style) {
|
|
28
|
+
case 'compact':
|
|
29
|
+
return `${rounded}${shortLabels[target]}`;
|
|
30
|
+
case 'scientific':
|
|
31
|
+
return `${value.toExponential(decimals)} ${target}`;
|
|
32
|
+
default:
|
|
33
|
+
return this.$withPluralUnit(rounded, target);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
23
36
|
valueOf() {
|
|
24
37
|
return this.value;
|
|
25
38
|
}
|
|
@@ -67,7 +80,13 @@ class $BaseConverter {
|
|
|
67
80
|
return this.value === Number(n);
|
|
68
81
|
}
|
|
69
82
|
format(decimals = 2) {
|
|
70
|
-
return
|
|
83
|
+
return this.$withPluralUnit(this.$round(this.value, decimals));
|
|
84
|
+
}
|
|
85
|
+
supportedUnits(category) {
|
|
86
|
+
if (category && category in constants_1.UNITS) {
|
|
87
|
+
return [...constants_1.UNITS[category]];
|
|
88
|
+
}
|
|
89
|
+
return Object.values(constants_1.UNITS).flat();
|
|
71
90
|
}
|
|
72
91
|
}
|
|
73
92
|
exports.$BaseConverter = $BaseConverter;
|
|
@@ -39,31 +39,21 @@ class $Data extends base_1.$BaseConverter {
|
|
|
39
39
|
}
|
|
40
40
|
formatTo(target, options) {
|
|
41
41
|
const value = this.to(target);
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
petabit: 'Pb',
|
|
58
|
-
petabyte: 'PB',
|
|
59
|
-
};
|
|
60
|
-
return `${rounded}${shortLabels[target]}`;
|
|
61
|
-
}
|
|
62
|
-
case 'scientific':
|
|
63
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
64
|
-
default:
|
|
65
|
-
return this.$withPluralUnit(rounded, target);
|
|
66
|
-
}
|
|
42
|
+
const shortLabels = {
|
|
43
|
+
bit: 'b',
|
|
44
|
+
byte: 'B',
|
|
45
|
+
kilobit: 'Kb',
|
|
46
|
+
kilobyte: 'KB',
|
|
47
|
+
megabit: 'Mb',
|
|
48
|
+
megabyte: 'MB',
|
|
49
|
+
gigabit: 'Gb',
|
|
50
|
+
gigabyte: 'GB',
|
|
51
|
+
terabit: 'Tb',
|
|
52
|
+
terabyte: 'TB',
|
|
53
|
+
petabit: 'Pb',
|
|
54
|
+
petabyte: 'PB',
|
|
55
|
+
};
|
|
56
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
67
57
|
}
|
|
68
58
|
}
|
|
69
59
|
exports.$Data = $Data;
|
|
@@ -19,7 +19,7 @@ class $Length extends base_1.$BaseConverter {
|
|
|
19
19
|
yard: 0.9144,
|
|
20
20
|
mile: 1609.344,
|
|
21
21
|
'nautical-mile': 1852,
|
|
22
|
-
'light-year': 9.
|
|
22
|
+
'light-year': 9.4607_3047_25808e15,
|
|
23
23
|
};
|
|
24
24
|
constructor(value, unit) {
|
|
25
25
|
super(value, unit);
|
|
@@ -41,33 +41,23 @@ class $Length extends base_1.$BaseConverter {
|
|
|
41
41
|
}
|
|
42
42
|
formatTo(target, options) {
|
|
43
43
|
const value = this.to(target);
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
'nautical-mile': 'nmi',
|
|
62
|
-
'light-year': 'ly',
|
|
63
|
-
};
|
|
64
|
-
return `${rounded}${shortLabels[target]}`;
|
|
65
|
-
}
|
|
66
|
-
case 'scientific':
|
|
67
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
68
|
-
default:
|
|
69
|
-
return this.$withPluralUnit(rounded, target);
|
|
70
|
-
}
|
|
44
|
+
const shortLabels = {
|
|
45
|
+
millimeter: 'mm',
|
|
46
|
+
centimeter: 'cm',
|
|
47
|
+
meter: 'm',
|
|
48
|
+
kilometer: 'km',
|
|
49
|
+
millimetre: 'mm',
|
|
50
|
+
centimetre: 'cm',
|
|
51
|
+
metre: 'm',
|
|
52
|
+
kilometre: 'km',
|
|
53
|
+
inch: 'in',
|
|
54
|
+
foot: 'ft',
|
|
55
|
+
yard: 'yd',
|
|
56
|
+
mile: 'mi',
|
|
57
|
+
'nautical-mile': 'nmi',
|
|
58
|
+
'light-year': 'ly',
|
|
59
|
+
};
|
|
60
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
71
61
|
}
|
|
72
62
|
}
|
|
73
63
|
exports.$Length = $Length;
|
|
@@ -11,11 +11,11 @@ class $Mass extends base_1.$BaseConverter {
|
|
|
11
11
|
gram: 0.001,
|
|
12
12
|
kilogram: 1,
|
|
13
13
|
tonne: 1000,
|
|
14
|
-
ounce: 0.
|
|
15
|
-
pound: 0.
|
|
16
|
-
stone: 6.
|
|
17
|
-
'short-ton': 907.
|
|
18
|
-
'long-ton': 1016.
|
|
14
|
+
ounce: 0.028349523125,
|
|
15
|
+
pound: 0.45359237,
|
|
16
|
+
stone: 6.35029318,
|
|
17
|
+
'short-ton': 907.18474,
|
|
18
|
+
'long-ton': 1016.0469088,
|
|
19
19
|
};
|
|
20
20
|
constructor(value, unit) {
|
|
21
21
|
super(value, unit);
|
|
@@ -37,29 +37,19 @@ class $Mass extends base_1.$BaseConverter {
|
|
|
37
37
|
}
|
|
38
38
|
formatTo(target, options) {
|
|
39
39
|
const value = this.to(target);
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
'short-ton': 't (US)',
|
|
54
|
-
'long-ton': 't (UK)',
|
|
55
|
-
};
|
|
56
|
-
return `${rounded}${shortLabels[target]}`;
|
|
57
|
-
}
|
|
58
|
-
case 'scientific':
|
|
59
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
60
|
-
default:
|
|
61
|
-
return this.$withPluralUnit(rounded, target);
|
|
62
|
-
}
|
|
40
|
+
const shortLabels = {
|
|
41
|
+
microgram: 'µg',
|
|
42
|
+
milligram: 'mg',
|
|
43
|
+
gram: 'g',
|
|
44
|
+
kilogram: 'kg',
|
|
45
|
+
tonne: 't',
|
|
46
|
+
ounce: 'oz',
|
|
47
|
+
pound: 'lb',
|
|
48
|
+
stone: 'st',
|
|
49
|
+
'short-ton': 't (US)',
|
|
50
|
+
'long-ton': 't (UK)',
|
|
51
|
+
};
|
|
52
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
63
53
|
}
|
|
64
54
|
}
|
|
65
55
|
exports.$Mass = $Mass;
|
|
@@ -40,22 +40,12 @@ class $Temperature extends base_1.$BaseConverter {
|
|
|
40
40
|
}
|
|
41
41
|
formatTo(target, options) {
|
|
42
42
|
const value = this.to(target);
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
fahrenheit: '°F',
|
|
50
|
-
kelvin: 'K',
|
|
51
|
-
};
|
|
52
|
-
return `${rounded}${shortLabels[target]}`;
|
|
53
|
-
}
|
|
54
|
-
case 'scientific':
|
|
55
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
56
|
-
default:
|
|
57
|
-
return this.$withPluralUnit(rounded, target);
|
|
58
|
-
}
|
|
43
|
+
const shortLabels = {
|
|
44
|
+
celsius: '°C',
|
|
45
|
+
fahrenheit: '°F',
|
|
46
|
+
kelvin: 'K',
|
|
47
|
+
};
|
|
48
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
59
49
|
}
|
|
60
50
|
}
|
|
61
51
|
exports.$Temperature = $Temperature;
|
|
@@ -40,32 +40,22 @@ class $Time extends base_1.$BaseConverter {
|
|
|
40
40
|
}
|
|
41
41
|
formatTo(target, options) {
|
|
42
42
|
const value = this.to(target);
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
century: 'cen',
|
|
60
|
-
millennium: 'mil',
|
|
61
|
-
};
|
|
62
|
-
return `${rounded}${shortLabels[target]}`;
|
|
63
|
-
}
|
|
64
|
-
case 'scientific':
|
|
65
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
66
|
-
default:
|
|
67
|
-
return this.$withPluralUnit(rounded, target);
|
|
68
|
-
}
|
|
43
|
+
const shortLabels = {
|
|
44
|
+
nanosecond: 'ns',
|
|
45
|
+
microsecond: 'µs',
|
|
46
|
+
millisecond: 'ms',
|
|
47
|
+
second: 's',
|
|
48
|
+
minute: 'min',
|
|
49
|
+
hour: 'h',
|
|
50
|
+
day: 'd',
|
|
51
|
+
week: 'wk',
|
|
52
|
+
month: 'mo',
|
|
53
|
+
year: 'yr',
|
|
54
|
+
decade: 'dec',
|
|
55
|
+
century: 'cen',
|
|
56
|
+
millennium: 'mil',
|
|
57
|
+
};
|
|
58
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
69
59
|
}
|
|
70
60
|
}
|
|
71
61
|
exports.$Time = $Time;
|
|
@@ -14,19 +14,19 @@ class $Volume extends base_1.$BaseConverter {
|
|
|
14
14
|
'cubic-centimetre': 1e-6,
|
|
15
15
|
'cubic-metre': 1,
|
|
16
16
|
'cubic-kilometre': 1e9,
|
|
17
|
-
'cubic-inch':
|
|
18
|
-
'cubic-foot': 0.
|
|
19
|
-
'cubic-yard': 0.
|
|
17
|
+
'cubic-inch': 0.000016387064,
|
|
18
|
+
'cubic-foot': 0.028316846592,
|
|
19
|
+
'cubic-yard': 0.764554857984,
|
|
20
20
|
liter: 0.001,
|
|
21
21
|
litre: 0.001,
|
|
22
22
|
milliliter: 1e-6,
|
|
23
23
|
millilitre: 1e-6,
|
|
24
|
-
gallon: 0.
|
|
25
|
-
quart: 0.
|
|
26
|
-
pint: 0.
|
|
27
|
-
cup: 0.
|
|
28
|
-
tablespoon:
|
|
29
|
-
teaspoon:
|
|
24
|
+
gallon: 0.003785411784,
|
|
25
|
+
quart: 0.000946352946,
|
|
26
|
+
pint: 0.000473176473,
|
|
27
|
+
cup: 0.0002365882365,
|
|
28
|
+
tablespoon: 0.00001478676478125,
|
|
29
|
+
teaspoon: 0.00000492892159375,
|
|
30
30
|
};
|
|
31
31
|
constructor(value, unit) {
|
|
32
32
|
super(value, unit);
|
|
@@ -48,40 +48,30 @@ class $Volume extends base_1.$BaseConverter {
|
|
|
48
48
|
}
|
|
49
49
|
formatTo(target, options) {
|
|
50
50
|
const value = this.to(target);
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
tablespoon: 'tbsp',
|
|
76
|
-
teaspoon: 'tsp',
|
|
77
|
-
};
|
|
78
|
-
return `${rounded}${shortLabels[target]}`;
|
|
79
|
-
}
|
|
80
|
-
case 'scientific':
|
|
81
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
82
|
-
default:
|
|
83
|
-
return this.$withPluralUnit(rounded, target);
|
|
84
|
-
}
|
|
51
|
+
const shortLabels = {
|
|
52
|
+
'cubic-millimeter': 'mm³',
|
|
53
|
+
'cubic-centimeter': 'cm³',
|
|
54
|
+
'cubic-meter': 'm³',
|
|
55
|
+
'cubic-kilometer': 'km³',
|
|
56
|
+
'cubic-millimetre': 'mm³',
|
|
57
|
+
'cubic-centimetre': 'cm³',
|
|
58
|
+
'cubic-metre': 'm³',
|
|
59
|
+
'cubic-kilometre': 'km³',
|
|
60
|
+
'cubic-inch': 'in³',
|
|
61
|
+
'cubic-foot': 'ft³',
|
|
62
|
+
'cubic-yard': 'yd³',
|
|
63
|
+
liter: 'L',
|
|
64
|
+
litre: 'L',
|
|
65
|
+
milliliter: 'mL',
|
|
66
|
+
millilitre: 'mL',
|
|
67
|
+
gallon: 'gal',
|
|
68
|
+
quart: 'qt',
|
|
69
|
+
pint: 'pt',
|
|
70
|
+
cup: 'c',
|
|
71
|
+
tablespoon: 'tbsp',
|
|
72
|
+
teaspoon: 'tsp',
|
|
73
|
+
};
|
|
74
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
85
75
|
}
|
|
86
76
|
}
|
|
87
77
|
exports.$Volume = $Volume;
|
package/dist/dts/constants.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export { ALPHABET_COLOR_PALETTE, NUMBER_COLOR_PALETTE } from './colors/constants
|
|
|
4
4
|
export { CSS_COLORS } from './colors/css-colors';
|
|
5
5
|
export { CURRENCY_CODES, CURRENCY_LOCALES, SUPPORTED_CURRENCIES as FRANKFURTER_CURRENCIES, LOCALE_CODES, } from './number/constants';
|
|
6
6
|
export { LOWERCASE as LOWERCASED_WORDS } from './string/constants';
|
|
7
|
+
export { UNITS } from './converter/constants';
|
|
7
8
|
export { COUNTRIES } from './object/countries';
|
|
8
9
|
export { HTTP_STATUS_CODES as HTTP_CODES, HTTP_STATUS_CODES as HTTP_STATUS, HTTP_STATUS_CODES, HTTP_STATUS_CODES as STATUS_CODES, } from './http-status/constants';
|
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
import type { Numeric } from '../types/index';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Tuple } from '../utils/types';
|
|
3
|
+
import type { $Unit, Category, CategoryUnits, ConverterFormatOptions } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* @description Base class providing common mathematical and formatting utilities
|
|
5
6
|
* for all unit converters (time, length, data, temperature, etc.).
|
|
6
7
|
*/
|
|
7
|
-
export declare class $BaseConverter<
|
|
8
|
+
export declare class $BaseConverter<Unit extends $Unit> {
|
|
8
9
|
protected readonly value: number;
|
|
9
|
-
protected readonly unit:
|
|
10
|
+
protected readonly unit: Unit;
|
|
10
11
|
/**
|
|
11
12
|
* Convert value to other units
|
|
12
13
|
* @param value Number or numeric string value to convert.
|
|
13
14
|
* @param unit Optional base unit for the provided value.
|
|
14
15
|
*/
|
|
15
|
-
constructor(value: Numeric, unit?:
|
|
16
|
-
/**
|
|
16
|
+
constructor(value: Numeric, unit?: Unit);
|
|
17
|
+
/** @protected Returns a grammatically correct unit string, prefixed with the number value. */
|
|
17
18
|
protected $withPluralUnit(value?: number, unit?: $Unit): string;
|
|
18
|
-
/**
|
|
19
|
+
/** @protected Rounds a numeric value to given decimal places. */
|
|
19
20
|
protected $round(value: number, decimals?: number): number;
|
|
21
|
+
/**
|
|
22
|
+
* @protected Shared formatter for all converters.
|
|
23
|
+
* @param value Converted value (already computed via `.to(target)`).
|
|
24
|
+
* @param target Target unit name.
|
|
25
|
+
* @param shortLabels Record of compact unit labels.
|
|
26
|
+
* @param options Formatting options.
|
|
27
|
+
* @returns Formatted string according to style (compact, plural, scientific).
|
|
28
|
+
*/
|
|
29
|
+
protected $formatTo(value: number, target: Unit, shortLabels: Record<Unit, string>, options: ConverterFormatOptions | undefined): string;
|
|
20
30
|
/**
|
|
21
31
|
* @instance Returns the numeric value.
|
|
22
32
|
* @returns The raw numeric value without unit.
|
|
@@ -31,10 +41,15 @@ export declare class $BaseConverter<U extends $Unit> {
|
|
|
31
41
|
* @instance Returns the unit name.
|
|
32
42
|
* @returns The current unit.
|
|
33
43
|
*/
|
|
34
|
-
getUnit():
|
|
44
|
+
getUnit(): Unit;
|
|
35
45
|
/**
|
|
36
46
|
* @instance Returns the original value with formatted pluralized unit.
|
|
37
|
-
* @returns A string like "3 hours" or "1 minute".
|
|
47
|
+
* @returns A string like `"3 hours"` or `"1 minute"` or `"3"` if no unit is provided.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* - This method is automatically called when the instance is used in a string context.
|
|
51
|
+
* - For complex and versatile pluralization, please refer to {@link https://toolbox.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
|
|
52
|
+
|
|
38
53
|
*/
|
|
39
54
|
toString(): string;
|
|
40
55
|
/**
|
|
@@ -43,7 +58,7 @@ export declare class $BaseConverter<U extends $Unit> {
|
|
|
43
58
|
*/
|
|
44
59
|
toObject(): {
|
|
45
60
|
value: number;
|
|
46
|
-
unit:
|
|
61
|
+
unit: Unit;
|
|
47
62
|
};
|
|
48
63
|
/**
|
|
49
64
|
* @instance Converts to JSON representation.
|
|
@@ -87,9 +102,22 @@ export declare class $BaseConverter<U extends $Unit> {
|
|
|
87
102
|
/** * @instance Returns whether this value equals another numeric value. */
|
|
88
103
|
eq(n: Numeric): boolean;
|
|
89
104
|
/**
|
|
90
|
-
* @instance Returns a human-friendly formatted string with fixed decimals.
|
|
91
|
-
* @param decimals Number of decimal places.
|
|
92
|
-
* @returns Formatted string.
|
|
105
|
+
* @instance Returns a human-friendly formatted string with fixed decimals (if the value is fraction).
|
|
106
|
+
* @param decimals Number of decimal places for fractional value.
|
|
107
|
+
* @returns Formatted string with proper unit pluralization.
|
|
108
|
+
*
|
|
109
|
+
* @remarks For complex and versatile pluralization, please refer to {@link https://toolbox.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
|
|
93
110
|
*/
|
|
94
111
|
format(decimals?: number): string;
|
|
112
|
+
/**
|
|
113
|
+
* @instance Returns all supported units.
|
|
114
|
+
* @returns Array of supported unit strings.
|
|
115
|
+
*/
|
|
116
|
+
supportedUnits(): Array<$Unit>;
|
|
117
|
+
/**
|
|
118
|
+
* @instance Returns all supported units for a specific category.
|
|
119
|
+
* @param category Category to filter units by.
|
|
120
|
+
* @returns Tuple of supported units for the specified category.
|
|
121
|
+
*/
|
|
122
|
+
supportedUnits<Cat extends Category>(category: Cat): Tuple<CategoryUnits<Cat>>;
|
|
95
123
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Record of Units */
|
|
1
|
+
/** Record of Units (Categorized) */
|
|
2
2
|
export declare const UNITS: Readonly<{
|
|
3
3
|
readonly time: readonly ["nanosecond", "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "year", "decade", "century", "millennium"];
|
|
4
4
|
readonly length: readonly ["millimeter", "centimeter", "meter", "kilometer", "millimetre", "centimetre", "metre", "kilometre", "inch", "foot", "yard", "mile", "nautical-mile", "light-year"];
|
|
@@ -28,7 +28,7 @@ export declare class $Temperature extends $BaseConverter<$TempUnit> {
|
|
|
28
28
|
* @instance Formats the converted value and unit.
|
|
29
29
|
* @param target Target unit to format to.
|
|
30
30
|
* @param options Formatting options.
|
|
31
|
-
* @returns Formatted string like "
|
|
31
|
+
* @returns Formatted string like "95°F", "5.25 kelvins", or "5e+3 celsius".
|
|
32
32
|
*/
|
|
33
33
|
formatTo(target: $TempUnit, options?: ConverterFormatOptions): string;
|
|
34
34
|
}
|
|
@@ -22,6 +22,8 @@ export type $Unit = LooseLiteral<UnitMap[Category]>;
|
|
|
22
22
|
export type InferCategory<U extends $Unit> = {
|
|
23
23
|
[K in Category]: U extends UnitMap[K] ? K : never;
|
|
24
24
|
}[Category];
|
|
25
|
+
/** Infer Units belong to a specific Category */
|
|
26
|
+
export type CategoryUnits<Cat extends Category> = UnitMap[Cat];
|
|
25
27
|
/** * Type for the returned converter instance based on the provided unit `U`. */
|
|
26
28
|
export type Converted<U extends $Unit> = InferCategory<U> extends never ? $BaseConverter<U> : InferCategory<U> extends 'area' ? $Area : InferCategory<U> extends 'time' ? $Time : InferCategory<U> extends 'length' ? $Length : InferCategory<U> extends 'mass' ? $Mass : InferCategory<U> extends 'data' ? $Data : InferCategory<U> extends 'temp' ? $Temperature : InferCategory<U> extends 'volume' ? $Volume : $BaseConverter<U>;
|
|
27
29
|
/** * Options for formatting converted values. */
|
|
@@ -28,7 +28,7 @@ export declare class $Volume extends $BaseConverter<$VolumeUnit> {
|
|
|
28
28
|
* @instance Formats the converted value and unit.
|
|
29
29
|
* @param target Target unit to format to.
|
|
30
30
|
* @param options Formatting options.
|
|
31
|
-
* @returns Formatted string like "
|
|
31
|
+
* @returns Formatted string like "5m³", "5.25 cubic-meters", or "5e+3 meter".
|
|
32
32
|
*/
|
|
33
33
|
formatTo(target: $VolumeUnit, options?: ConverterFormatOptions): string;
|
|
34
34
|
}
|
package/dist/esm/constants.js
CHANGED
|
@@ -4,5 +4,6 @@ export { ALPHABET_COLOR_PALETTE, NUMBER_COLOR_PALETTE } from './colors/constants
|
|
|
4
4
|
export { CSS_COLORS } from './colors/css-colors.js';
|
|
5
5
|
export { CURRENCY_CODES, CURRENCY_LOCALES, SUPPORTED_CURRENCIES as FRANKFURTER_CURRENCIES, LOCALE_CODES, } from './number/constants.js';
|
|
6
6
|
export { LOWERCASE as LOWERCASED_WORDS } from './string/constants.js';
|
|
7
|
+
export { UNITS } from './converter/constants.js';
|
|
7
8
|
export { COUNTRIES } from './object/countries.js';
|
|
8
9
|
export { HTTP_STATUS_CODES as HTTP_CODES, HTTP_STATUS_CODES as HTTP_STATUS, HTTP_STATUS_CODES, HTTP_STATUS_CODES as STATUS_CODES, } from './http-status/constants.js';
|
|
@@ -12,11 +12,11 @@ export class $Area extends $BaseConverter {
|
|
|
12
12
|
'square-metre': 1,
|
|
13
13
|
'square-kilometre': 1e6,
|
|
14
14
|
'square-inch': 0.00064516,
|
|
15
|
-
'square-foot': 0.
|
|
16
|
-
'square-yard': 0.
|
|
17
|
-
'square-mile':
|
|
15
|
+
'square-foot': 0.09290304,
|
|
16
|
+
'square-yard': 0.83612736,
|
|
17
|
+
'square-mile': 2_589_988.110336,
|
|
18
18
|
hectare: 1e4,
|
|
19
|
-
acre:
|
|
19
|
+
acre: 4_046.8564224,
|
|
20
20
|
};
|
|
21
21
|
constructor(value, unit) {
|
|
22
22
|
super(value, unit);
|
|
@@ -38,33 +38,23 @@ export class $Area extends $BaseConverter {
|
|
|
38
38
|
}
|
|
39
39
|
formatTo(target, options) {
|
|
40
40
|
const value = this.to(target);
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
hectare: 'ha',
|
|
59
|
-
acre: 'ac',
|
|
60
|
-
};
|
|
61
|
-
return `${rounded}${shortLabels[target]}`;
|
|
62
|
-
}
|
|
63
|
-
case 'scientific':
|
|
64
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
65
|
-
default:
|
|
66
|
-
return this.$withPluralUnit(rounded, target);
|
|
67
|
-
}
|
|
41
|
+
const shortLabels = {
|
|
42
|
+
'square-millimeter': 'mm²',
|
|
43
|
+
'square-centimeter': 'cm²',
|
|
44
|
+
'square-meter': 'm²',
|
|
45
|
+
'square-kilometer': 'km²',
|
|
46
|
+
'square-millimetre': 'mm²',
|
|
47
|
+
'square-centimetre': 'cm²',
|
|
48
|
+
'square-metre': 'm²',
|
|
49
|
+
'square-kilometre': 'km²',
|
|
50
|
+
'square-inch': 'in²',
|
|
51
|
+
'square-foot': 'ft²',
|
|
52
|
+
'square-yard': 'yd²',
|
|
53
|
+
'square-mile': 'mi²',
|
|
54
|
+
hectare: 'ha',
|
|
55
|
+
acre: 'ac',
|
|
56
|
+
};
|
|
57
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
68
58
|
}
|
|
69
59
|
}
|
|
70
60
|
_a = $Area;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UNITS } from './constants.js';
|
|
1
2
|
export class $BaseConverter {
|
|
2
3
|
value;
|
|
3
4
|
unit;
|
|
@@ -17,6 +18,18 @@ export class $BaseConverter {
|
|
|
17
18
|
const factor = 10 ** decimals;
|
|
18
19
|
return Math.round(value * factor) / factor;
|
|
19
20
|
}
|
|
21
|
+
$formatTo(value, target, shortLabels, options) {
|
|
22
|
+
const { style = 'plural', decimals = 2 } = options ?? {};
|
|
23
|
+
const rounded = this.$round(value, decimals);
|
|
24
|
+
switch (style) {
|
|
25
|
+
case 'compact':
|
|
26
|
+
return `${rounded}${shortLabels[target]}`;
|
|
27
|
+
case 'scientific':
|
|
28
|
+
return `${value.toExponential(decimals)} ${target}`;
|
|
29
|
+
default:
|
|
30
|
+
return this.$withPluralUnit(rounded, target);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
20
33
|
valueOf() {
|
|
21
34
|
return this.value;
|
|
22
35
|
}
|
|
@@ -64,6 +77,12 @@ export class $BaseConverter {
|
|
|
64
77
|
return this.value === Number(n);
|
|
65
78
|
}
|
|
66
79
|
format(decimals = 2) {
|
|
67
|
-
return
|
|
80
|
+
return this.$withPluralUnit(this.$round(this.value, decimals));
|
|
81
|
+
}
|
|
82
|
+
supportedUnits(category) {
|
|
83
|
+
if (category && category in UNITS) {
|
|
84
|
+
return [...UNITS[category]];
|
|
85
|
+
}
|
|
86
|
+
return Object.values(UNITS).flat();
|
|
68
87
|
}
|
|
69
88
|
}
|
|
@@ -36,31 +36,21 @@ export class $Data extends $BaseConverter {
|
|
|
36
36
|
}
|
|
37
37
|
formatTo(target, options) {
|
|
38
38
|
const value = this.to(target);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
petabit: 'Pb',
|
|
55
|
-
petabyte: 'PB',
|
|
56
|
-
};
|
|
57
|
-
return `${rounded}${shortLabels[target]}`;
|
|
58
|
-
}
|
|
59
|
-
case 'scientific':
|
|
60
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
61
|
-
default:
|
|
62
|
-
return this.$withPluralUnit(rounded, target);
|
|
63
|
-
}
|
|
39
|
+
const shortLabels = {
|
|
40
|
+
bit: 'b',
|
|
41
|
+
byte: 'B',
|
|
42
|
+
kilobit: 'Kb',
|
|
43
|
+
kilobyte: 'KB',
|
|
44
|
+
megabit: 'Mb',
|
|
45
|
+
megabyte: 'MB',
|
|
46
|
+
gigabit: 'Gb',
|
|
47
|
+
gigabyte: 'GB',
|
|
48
|
+
terabit: 'Tb',
|
|
49
|
+
terabyte: 'TB',
|
|
50
|
+
petabit: 'Pb',
|
|
51
|
+
petabyte: 'PB',
|
|
52
|
+
};
|
|
53
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
64
54
|
}
|
|
65
55
|
}
|
|
66
56
|
_a = $Data;
|
|
@@ -16,7 +16,7 @@ export class $Length extends $BaseConverter {
|
|
|
16
16
|
yard: 0.9144,
|
|
17
17
|
mile: 1609.344,
|
|
18
18
|
'nautical-mile': 1852,
|
|
19
|
-
'light-year': 9.
|
|
19
|
+
'light-year': 9.4607_3047_25808e15,
|
|
20
20
|
};
|
|
21
21
|
constructor(value, unit) {
|
|
22
22
|
super(value, unit);
|
|
@@ -38,33 +38,23 @@ export class $Length extends $BaseConverter {
|
|
|
38
38
|
}
|
|
39
39
|
formatTo(target, options) {
|
|
40
40
|
const value = this.to(target);
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
'nautical-mile': 'nmi',
|
|
59
|
-
'light-year': 'ly',
|
|
60
|
-
};
|
|
61
|
-
return `${rounded}${shortLabels[target]}`;
|
|
62
|
-
}
|
|
63
|
-
case 'scientific':
|
|
64
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
65
|
-
default:
|
|
66
|
-
return this.$withPluralUnit(rounded, target);
|
|
67
|
-
}
|
|
41
|
+
const shortLabels = {
|
|
42
|
+
millimeter: 'mm',
|
|
43
|
+
centimeter: 'cm',
|
|
44
|
+
meter: 'm',
|
|
45
|
+
kilometer: 'km',
|
|
46
|
+
millimetre: 'mm',
|
|
47
|
+
centimetre: 'cm',
|
|
48
|
+
metre: 'm',
|
|
49
|
+
kilometre: 'km',
|
|
50
|
+
inch: 'in',
|
|
51
|
+
foot: 'ft',
|
|
52
|
+
yard: 'yd',
|
|
53
|
+
mile: 'mi',
|
|
54
|
+
'nautical-mile': 'nmi',
|
|
55
|
+
'light-year': 'ly',
|
|
56
|
+
};
|
|
57
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
68
58
|
}
|
|
69
59
|
}
|
|
70
60
|
_a = $Length;
|
|
@@ -8,11 +8,11 @@ export class $Mass extends $BaseConverter {
|
|
|
8
8
|
gram: 0.001,
|
|
9
9
|
kilogram: 1,
|
|
10
10
|
tonne: 1000,
|
|
11
|
-
ounce: 0.
|
|
12
|
-
pound: 0.
|
|
13
|
-
stone: 6.
|
|
14
|
-
'short-ton': 907.
|
|
15
|
-
'long-ton': 1016.
|
|
11
|
+
ounce: 0.028349523125,
|
|
12
|
+
pound: 0.45359237,
|
|
13
|
+
stone: 6.35029318,
|
|
14
|
+
'short-ton': 907.18474,
|
|
15
|
+
'long-ton': 1016.0469088,
|
|
16
16
|
};
|
|
17
17
|
constructor(value, unit) {
|
|
18
18
|
super(value, unit);
|
|
@@ -34,29 +34,19 @@ export class $Mass extends $BaseConverter {
|
|
|
34
34
|
}
|
|
35
35
|
formatTo(target, options) {
|
|
36
36
|
const value = this.to(target);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
'short-ton': 't (US)',
|
|
51
|
-
'long-ton': 't (UK)',
|
|
52
|
-
};
|
|
53
|
-
return `${rounded}${shortLabels[target]}`;
|
|
54
|
-
}
|
|
55
|
-
case 'scientific':
|
|
56
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
57
|
-
default:
|
|
58
|
-
return this.$withPluralUnit(rounded, target);
|
|
59
|
-
}
|
|
37
|
+
const shortLabels = {
|
|
38
|
+
microgram: 'µg',
|
|
39
|
+
milligram: 'mg',
|
|
40
|
+
gram: 'g',
|
|
41
|
+
kilogram: 'kg',
|
|
42
|
+
tonne: 't',
|
|
43
|
+
ounce: 'oz',
|
|
44
|
+
pound: 'lb',
|
|
45
|
+
stone: 'st',
|
|
46
|
+
'short-ton': 't (US)',
|
|
47
|
+
'long-ton': 't (UK)',
|
|
48
|
+
};
|
|
49
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
60
50
|
}
|
|
61
51
|
}
|
|
62
52
|
_a = $Mass;
|
|
@@ -37,21 +37,11 @@ export class $Temperature extends $BaseConverter {
|
|
|
37
37
|
}
|
|
38
38
|
formatTo(target, options) {
|
|
39
39
|
const value = this.to(target);
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
fahrenheit: '°F',
|
|
47
|
-
kelvin: 'K',
|
|
48
|
-
};
|
|
49
|
-
return `${rounded}${shortLabels[target]}`;
|
|
50
|
-
}
|
|
51
|
-
case 'scientific':
|
|
52
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
53
|
-
default:
|
|
54
|
-
return this.$withPluralUnit(rounded, target);
|
|
55
|
-
}
|
|
40
|
+
const shortLabels = {
|
|
41
|
+
celsius: '°C',
|
|
42
|
+
fahrenheit: '°F',
|
|
43
|
+
kelvin: 'K',
|
|
44
|
+
};
|
|
45
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
56
46
|
}
|
|
57
47
|
}
|
|
@@ -37,32 +37,22 @@ export class $Time extends $BaseConverter {
|
|
|
37
37
|
}
|
|
38
38
|
formatTo(target, options) {
|
|
39
39
|
const value = this.to(target);
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
century: 'cen',
|
|
57
|
-
millennium: 'mil',
|
|
58
|
-
};
|
|
59
|
-
return `${rounded}${shortLabels[target]}`;
|
|
60
|
-
}
|
|
61
|
-
case 'scientific':
|
|
62
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
63
|
-
default:
|
|
64
|
-
return this.$withPluralUnit(rounded, target);
|
|
65
|
-
}
|
|
40
|
+
const shortLabels = {
|
|
41
|
+
nanosecond: 'ns',
|
|
42
|
+
microsecond: 'µs',
|
|
43
|
+
millisecond: 'ms',
|
|
44
|
+
second: 's',
|
|
45
|
+
minute: 'min',
|
|
46
|
+
hour: 'h',
|
|
47
|
+
day: 'd',
|
|
48
|
+
week: 'wk',
|
|
49
|
+
month: 'mo',
|
|
50
|
+
year: 'yr',
|
|
51
|
+
decade: 'dec',
|
|
52
|
+
century: 'cen',
|
|
53
|
+
millennium: 'mil',
|
|
54
|
+
};
|
|
55
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
66
56
|
}
|
|
67
57
|
}
|
|
68
58
|
_a = $Time;
|
|
@@ -11,19 +11,19 @@ export class $Volume extends $BaseConverter {
|
|
|
11
11
|
'cubic-centimetre': 1e-6,
|
|
12
12
|
'cubic-metre': 1,
|
|
13
13
|
'cubic-kilometre': 1e9,
|
|
14
|
-
'cubic-inch':
|
|
15
|
-
'cubic-foot': 0.
|
|
16
|
-
'cubic-yard': 0.
|
|
14
|
+
'cubic-inch': 0.000016387064,
|
|
15
|
+
'cubic-foot': 0.028316846592,
|
|
16
|
+
'cubic-yard': 0.764554857984,
|
|
17
17
|
liter: 0.001,
|
|
18
18
|
litre: 0.001,
|
|
19
19
|
milliliter: 1e-6,
|
|
20
20
|
millilitre: 1e-6,
|
|
21
|
-
gallon: 0.
|
|
22
|
-
quart: 0.
|
|
23
|
-
pint: 0.
|
|
24
|
-
cup: 0.
|
|
25
|
-
tablespoon:
|
|
26
|
-
teaspoon:
|
|
21
|
+
gallon: 0.003785411784,
|
|
22
|
+
quart: 0.000946352946,
|
|
23
|
+
pint: 0.000473176473,
|
|
24
|
+
cup: 0.0002365882365,
|
|
25
|
+
tablespoon: 0.00001478676478125,
|
|
26
|
+
teaspoon: 0.00000492892159375,
|
|
27
27
|
};
|
|
28
28
|
constructor(value, unit) {
|
|
29
29
|
super(value, unit);
|
|
@@ -45,40 +45,30 @@ export class $Volume extends $BaseConverter {
|
|
|
45
45
|
}
|
|
46
46
|
formatTo(target, options) {
|
|
47
47
|
const value = this.to(target);
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
tablespoon: 'tbsp',
|
|
73
|
-
teaspoon: 'tsp',
|
|
74
|
-
};
|
|
75
|
-
return `${rounded}${shortLabels[target]}`;
|
|
76
|
-
}
|
|
77
|
-
case 'scientific':
|
|
78
|
-
return `${value.toExponential(decimals)} ${target}`;
|
|
79
|
-
default:
|
|
80
|
-
return this.$withPluralUnit(rounded, target);
|
|
81
|
-
}
|
|
48
|
+
const shortLabels = {
|
|
49
|
+
'cubic-millimeter': 'mm³',
|
|
50
|
+
'cubic-centimeter': 'cm³',
|
|
51
|
+
'cubic-meter': 'm³',
|
|
52
|
+
'cubic-kilometer': 'km³',
|
|
53
|
+
'cubic-millimetre': 'mm³',
|
|
54
|
+
'cubic-centimetre': 'cm³',
|
|
55
|
+
'cubic-metre': 'm³',
|
|
56
|
+
'cubic-kilometre': 'km³',
|
|
57
|
+
'cubic-inch': 'in³',
|
|
58
|
+
'cubic-foot': 'ft³',
|
|
59
|
+
'cubic-yard': 'yd³',
|
|
60
|
+
liter: 'L',
|
|
61
|
+
litre: 'L',
|
|
62
|
+
milliliter: 'mL',
|
|
63
|
+
millilitre: 'mL',
|
|
64
|
+
gallon: 'gal',
|
|
65
|
+
quart: 'qt',
|
|
66
|
+
pint: 'pt',
|
|
67
|
+
cup: 'c',
|
|
68
|
+
tablespoon: 'tbsp',
|
|
69
|
+
teaspoon: 'tsp',
|
|
70
|
+
};
|
|
71
|
+
return this.$formatTo(value, target, shortLabels, options);
|
|
82
72
|
}
|
|
83
73
|
}
|
|
84
74
|
_a = $Volume;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhb-toolbox",
|
|
3
|
-
"version": "4.23.
|
|
3
|
+
"version": "4.23.11",
|
|
4
4
|
"description": "A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|