@bouko/ts 0.2.2 → 0.2.4

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
@@ -1,7 +1,9 @@
1
1
  import type { JsonMap, JsonValue } from "./types/generic";
2
2
  export * from "./types/generic";
3
3
  export * from "./types/work";
4
+ export * from "./types/math";
4
5
  export * from "./utils/checkers";
6
+ export * from "./utils/env";
5
7
  export * from "./utils/formatters";
6
8
  export * from "./utils/parsers";
7
9
  export declare const safely: <T>(action: () => T) => T | undefined;
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from "./types/generic";
2
2
  export * from "./types/work";
3
+ export * from "./types/math";
3
4
  export * from "./utils/checkers";
5
+ export * from "./utils/env";
4
6
  export * from "./utils/formatters";
5
7
  export * from "./utils/parsers";
6
8
  export const safely = (action) => {
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Type definitions for math/numbers.
3
+ *
4
+ * - `Range`: Object with `min` and `max` properties.
5
+ *
6
+ * They are intended to facilitate math utilities
7
+ * such as clamping, normalization, etc.
8
+ **/
9
+ export declare type Range = {
10
+ min: number;
11
+ max: number;
12
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Type definitions for math/numbers.
3
+ *
4
+ * - `Range`: Object with `min` and `max` properties.
5
+ *
6
+ * They are intended to facilitate math utilities
7
+ * such as clamping, normalization, etc.
8
+ **/
9
+ export {};
@@ -1 +1,2 @@
1
1
  export declare const shortenStr: (str: string) => string;
2
+ export declare const shortenNum: (x: number) => string;
@@ -3,3 +3,10 @@ export const shortenStr = (str) => {
3
3
  return str;
4
4
  return `${str.slice(0, 3)}...${str.slice(-3)}`;
5
5
  };
6
+ export const shortenNum = (x) => {
7
+ if (x < 1000)
8
+ return x.toString();
9
+ if (x < 1_000_000)
10
+ return `${Math.floor(x / 1000)}k`;
11
+ return `${Math.floor(x / 1_000_000)}m`;
12
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/ts",
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",