@wise-old-man/utils 2.0.0-beta.6 → 2.0.0-beta.8

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 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(metricString: string): metricString is Metric;
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): string | null;
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(metricString) {
1907
- return metricString in MetricProps;
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
- switch (abbreviation.toLowerCase()) {
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 abbreviation;
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).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
2277
+ return (Math.round(num * 100) / 100).toLocaleString();
2274
2278
  }
2275
2279
  if ((num < 10000 && num > -10000) || !withLetters) {
2276
- return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
2280
+ return num.toLocaleString();
2277
2281
  }
2278
2282
  // < 10 million
2279
2283
  if (num < 10000000 && num > -10000000) {
2280
- return `${Math.floor(num / 1000)}k`;
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 `${Math.round((num / 1000000 + Number.EPSILON) * 100) / 100}m`;
2285
- }
2286
- return `${Math.round((num / 1000000000 + Number.EPSILON) * 100) / 100}b`;
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)
@@ -2469,12 +2482,15 @@ class CompetitionsClient extends BaseAPIClient {
2469
2482
 
2470
2483
  class WOMClient {
2471
2484
  constructor(options) {
2485
+ const headers = {
2486
+ 'x-user-agent': (options === null || options === void 0 ? void 0 : options.userAgent) || config.defaultUserAgent
2487
+ };
2488
+ if (options === null || options === void 0 ? void 0 : options.apiKey) {
2489
+ headers['x-api-key'] = options.apiKey;
2490
+ }
2472
2491
  const axiosInstance = axios__default["default"].create({
2473
2492
  baseURL: (options === null || options === void 0 ? void 0 : options.baseAPIUrl) || config.baseAPIUrl,
2474
- headers: {
2475
- 'x-api-key': (options === null || options === void 0 ? void 0 : options.apiKey) || null,
2476
- 'x-user-agent': (options === null || options === void 0 ? void 0 : options.userAgent) || config.defaultUserAgent
2477
- }
2493
+ headers
2478
2494
  });
2479
2495
  this.deltas = new DeltasClient(axiosInstance);
2480
2496
  this.groups = new GroupsClient(axiosInstance);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise-old-man/utils",
3
- "version": "2.0.0-beta.6",
3
+ "version": "2.0.0-beta.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",