@wise-old-man/utils 2.0.0-beta.6 → 2.0.0-beta.7
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/index.d.ts +3 -3
- package/dist/index.js +24 -11
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1666,7 +1666,7 @@ declare const F2P_BOSSES: Boss[];
|
|
|
1666
1666
|
declare const MEMBER_SKILLS: Skill[];
|
|
1667
1667
|
declare const COMBAT_SKILLS: Skill[];
|
|
1668
1668
|
declare function findMetric(metricName: string): Metric | null;
|
|
1669
|
-
declare function isMetric(
|
|
1669
|
+
declare function isMetric(metric: Metric | string): metric is Metric;
|
|
1670
1670
|
declare function isSkill(metric: Metric | string): metric is Skill;
|
|
1671
1671
|
declare function isActivity(metric: Metric | string): metric is Activity;
|
|
1672
1672
|
declare function isBoss(metric: Metric | string): metric is Boss;
|
|
@@ -1677,7 +1677,7 @@ declare function getMetricMeasure(metric: Metric): MetricMeasure;
|
|
|
1677
1677
|
declare function getMetricName(metric: Metric): string;
|
|
1678
1678
|
declare function getMinimumBossKc(metric: Metric): number;
|
|
1679
1679
|
declare function getParentEfficiencyMetric(metric: Metric): "ehp" | "ehb";
|
|
1680
|
-
declare function parseMetricAbbreviation(abbreviation: string):
|
|
1680
|
+
declare function parseMetricAbbreviation(abbreviation: string): Metric | null;
|
|
1681
1681
|
|
|
1682
1682
|
declare type PeriodPropsMap = MapOf<Period, {
|
|
1683
1683
|
name: string;
|
|
@@ -1705,7 +1705,7 @@ declare function isPlayerBuild(buildString: string): buildString is PlayerBuild;
|
|
|
1705
1705
|
declare function findPlayerType(typeName: string): PlayerType | null;
|
|
1706
1706
|
declare function findPlayerBuild(buildName: string): PlayerBuild | null;
|
|
1707
1707
|
|
|
1708
|
-
declare function formatNumber(num: number, withLetters?: boolean): string | -1;
|
|
1708
|
+
declare function formatNumber(num: number, withLetters?: boolean, decimalPrecision?: number): string | -1;
|
|
1709
1709
|
declare function padNumber(value: number): string;
|
|
1710
1710
|
declare function round(num: number, cases: number): number;
|
|
1711
1711
|
|
package/dist/index.js
CHANGED
|
@@ -1903,8 +1903,8 @@ function findMetric(metricName) {
|
|
|
1903
1903
|
}
|
|
1904
1904
|
return null;
|
|
1905
1905
|
}
|
|
1906
|
-
function isMetric(
|
|
1907
|
-
return
|
|
1906
|
+
function isMetric(metric) {
|
|
1907
|
+
return metric in MetricProps;
|
|
1908
1908
|
}
|
|
1909
1909
|
function isSkill(metric) {
|
|
1910
1910
|
return metric in SkillProps;
|
|
@@ -1944,7 +1944,11 @@ function parseMetricAbbreviation(abbreviation) {
|
|
|
1944
1944
|
if (!abbreviation || abbreviation.length === 0) {
|
|
1945
1945
|
return null;
|
|
1946
1946
|
}
|
|
1947
|
-
|
|
1947
|
+
const fixedAbbreviation = abbreviation.toLowerCase();
|
|
1948
|
+
if (isMetric(fixedAbbreviation)) {
|
|
1949
|
+
return fixedAbbreviation;
|
|
1950
|
+
}
|
|
1951
|
+
switch (fixedAbbreviation) {
|
|
1948
1952
|
// Bosses
|
|
1949
1953
|
case 'sire':
|
|
1950
1954
|
return Metric.ABYSSAL_SIRE;
|
|
@@ -2176,7 +2180,7 @@ function parseMetricAbbreviation(abbreviation) {
|
|
|
2176
2180
|
case 'const':
|
|
2177
2181
|
return Metric.CONSTRUCTION;
|
|
2178
2182
|
default:
|
|
2179
|
-
return
|
|
2183
|
+
return null;
|
|
2180
2184
|
}
|
|
2181
2185
|
}
|
|
2182
2186
|
|
|
@@ -2265,25 +2269,34 @@ function findPlayerBuild(buildName) {
|
|
|
2265
2269
|
return null;
|
|
2266
2270
|
}
|
|
2267
2271
|
|
|
2268
|
-
function formatNumber(num, withLetters = false) {
|
|
2272
|
+
function formatNumber(num, withLetters = false, decimalPrecision = 2) {
|
|
2269
2273
|
if (num === undefined || num === null)
|
|
2270
2274
|
return -1;
|
|
2271
2275
|
// If number is float
|
|
2272
2276
|
if (num % 1 !== 0) {
|
|
2273
|
-
return (Math.round(num * 100) / 100).
|
|
2277
|
+
return (Math.round(num * 100) / 100).toLocaleString();
|
|
2274
2278
|
}
|
|
2275
2279
|
if ((num < 10000 && num > -10000) || !withLetters) {
|
|
2276
|
-
return num.
|
|
2280
|
+
return num.toLocaleString();
|
|
2277
2281
|
}
|
|
2278
2282
|
// < 10 million
|
|
2279
2283
|
if (num < 10000000 && num > -10000000) {
|
|
2280
|
-
return
|
|
2284
|
+
// If has no decimals, return as whole number instead (10.00k => 10k)
|
|
2285
|
+
if ((num / 1000) % 1 === 0)
|
|
2286
|
+
return `${num / 1000}k`;
|
|
2287
|
+
return `${(num / 1000).toFixed(decimalPrecision)}k`;
|
|
2281
2288
|
}
|
|
2282
2289
|
// < 1 billion
|
|
2283
2290
|
if (num < 1000000000 && num > -1000000000) {
|
|
2284
|
-
return
|
|
2285
|
-
|
|
2286
|
-
|
|
2291
|
+
// If has no decimals, return as whole number instead (10.00m => 10m)
|
|
2292
|
+
if ((num / 1000000) % 1 === 0)
|
|
2293
|
+
return `${num / 1000000}m`;
|
|
2294
|
+
return `${(num / 1000000).toFixed(decimalPrecision)}m`;
|
|
2295
|
+
}
|
|
2296
|
+
// If has no decimals, return as whole number instead (10.00b => 10b)
|
|
2297
|
+
if ((num / 1000000000) % 1 === 0)
|
|
2298
|
+
return `${num / 1000000000}b`;
|
|
2299
|
+
return `${(num / 1000000000).toFixed(decimalPrecision)}b`;
|
|
2287
2300
|
}
|
|
2288
2301
|
function padNumber(value) {
|
|
2289
2302
|
if (!value)
|