@bouko/ts 0.2.3 → 0.2.5
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/types/math.d.ts +12 -0
- package/dist/types/math.js +10 -0
- package/dist/utils/formatters.d.ts +1 -0
- package/dist/utils/formatters.js +7 -0
- package/package.json +1 -1
- package/dist/core/env.d.ts +0 -11
- package/dist/core/env.js +0 -24
- package/dist/core/parse.d.ts +0 -2
- package/dist/core/parse.js +0 -14
- package/dist/core/safety.d.ts +0 -0
- package/dist/core/safety.js +0 -1
- package/dist/core/types.d.ts +0 -2
- package/dist/core/types.js +0 -5
- package/dist/types/env.d.ts +0 -1
- package/dist/types/env.js +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -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
|
+
};
|
package/dist/utils/formatters.js
CHANGED
|
@@ -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
package/dist/core/env.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { EnvValue } from "../types/env";
|
|
2
|
-
export declare function getEnv<T extends EnvValue = string>(key: string, fallback?: T): T;
|
|
3
|
-
/**
|
|
4
|
-
* Problems:
|
|
5
|
-
*
|
|
6
|
-
* - Perfect `EnvValue`
|
|
7
|
-
* - Perfect `isNum`
|
|
8
|
-
* - Perfect `isBool`
|
|
9
|
-
* - Perfect `parseNum`
|
|
10
|
-
* - Perfect `parseBool`
|
|
11
|
-
**/
|
package/dist/core/env.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { isNum, isBool } from "./types";
|
|
2
|
-
import { parseNum, parseBool } from "./parse";
|
|
3
|
-
export function getEnv(key, fallback) {
|
|
4
|
-
const value = process.env[key]?.trim();
|
|
5
|
-
if (!value || value === "") {
|
|
6
|
-
if (fallback !== undefined)
|
|
7
|
-
return fallback;
|
|
8
|
-
throw new Error(`Missing ENV: '${key}'`);
|
|
9
|
-
}
|
|
10
|
-
if (isNum(value))
|
|
11
|
-
return parseNum(value);
|
|
12
|
-
if (isBool(value))
|
|
13
|
-
return parseBool(value);
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Problems:
|
|
18
|
-
*
|
|
19
|
-
* - Perfect `EnvValue`
|
|
20
|
-
* - Perfect `isNum`
|
|
21
|
-
* - Perfect `isBool`
|
|
22
|
-
* - Perfect `parseNum`
|
|
23
|
-
* - Perfect `parseBool`
|
|
24
|
-
**/
|
package/dist/core/parse.d.ts
DELETED
package/dist/core/parse.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const parseNum = (input) => {
|
|
2
|
-
const num = Number(input.trim());
|
|
3
|
-
if (!isNaN(num))
|
|
4
|
-
return num;
|
|
5
|
-
};
|
|
6
|
-
export const parseBool = (input) => {
|
|
7
|
-
const lower = input.trim().toLowerCase();
|
|
8
|
-
if (lower === "true")
|
|
9
|
-
return true;
|
|
10
|
-
if (lower === "false")
|
|
11
|
-
return false;
|
|
12
|
-
else
|
|
13
|
-
throw new Error(`Invalid boolean: ${input}`);
|
|
14
|
-
};
|
package/dist/core/safety.d.ts
DELETED
|
File without changes
|
package/dist/core/safety.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/core/types.d.ts
DELETED
package/dist/core/types.js
DELETED
package/dist/types/env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type EnvValue = string | number | boolean;
|
package/dist/types/env.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|