@bouko/ts 0.2.9 → 0.3.1
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/core/safety.d.ts +0 -0
- package/dist/core/safety.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.js +12 -0
- package/dist/utils/log.d.ts +4 -0
- package/dist/utils/log.js +5 -0
- package/dist/utils/time.d.ts +3 -0
- package/dist/utils/time.js +27 -0
- package/package.json +26 -2
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export * from "./utils/env";
|
|
|
8
8
|
export * from "./utils/formatters";
|
|
9
9
|
export * from "./utils/parsers";
|
|
10
10
|
export * from "./utils/converters";
|
|
11
|
+
export * from "./utils/log";
|
|
12
|
+
export * from "./utils/time";
|
|
11
13
|
export declare const safely: <T>(action: () => T) => T | undefined;
|
|
12
14
|
export declare const safelyThru: <T>(arr: T[], action: (item: T) => void) => void;
|
|
13
15
|
export declare const isJsonMap: (value: unknown) => value is JsonMap;
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,8 @@ export * from "./utils/env";
|
|
|
7
7
|
export * from "./utils/formatters";
|
|
8
8
|
export * from "./utils/parsers";
|
|
9
9
|
export * from "./utils/converters";
|
|
10
|
+
export * from "./utils/log";
|
|
11
|
+
export * from "./utils/time";
|
|
10
12
|
export const safely = (action) => {
|
|
11
13
|
try {
|
|
12
14
|
return action();
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for common data structures.
|
|
3
|
+
*
|
|
4
|
+
* - `StringMap`: Map of string keys to string values.
|
|
5
|
+
* - `JsonMap`: Object of primitives, arrays, or nested maps.
|
|
6
|
+
* - `JsonValue`: Union type representing a valid JSON value.
|
|
7
|
+
*
|
|
8
|
+
* They are intended to facilitate type-safe handling
|
|
9
|
+
* of generic objects (ex. forms)
|
|
10
|
+
**/
|
|
11
|
+
export type StringMap = Record<string, string>;
|
|
12
|
+
export type JsonMap = {
|
|
13
|
+
[key: string]: JsonValue | JsonValue[];
|
|
14
|
+
};
|
|
15
|
+
export type JsonValue = string | number | boolean | null | undefined | JsonMap;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for common data structures.
|
|
3
|
+
*
|
|
4
|
+
* - `StringMap`: Map of string keys to string values.
|
|
5
|
+
* - `JsonMap`: Object of primitives, arrays, or nested maps.
|
|
6
|
+
* - `JsonValue`: Union type representing a valid JSON value.
|
|
7
|
+
*
|
|
8
|
+
* They are intended to facilitate type-safe handling
|
|
9
|
+
* of generic objects (ex. forms)
|
|
10
|
+
**/
|
|
11
|
+
export {};
|
|
12
|
+
// clean
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function mmSS(timestamp) {
|
|
2
|
+
const totalSeconds = Math.floor(timestamp / 1000);
|
|
3
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
4
|
+
const seconds = totalSeconds % 60;
|
|
5
|
+
const padSeconds = (n) => n.toString().padStart(2, "0");
|
|
6
|
+
return `${minutes}:${padSeconds(seconds)}`;
|
|
7
|
+
}
|
|
8
|
+
export const secToMs = (sec) => {
|
|
9
|
+
const converted = sec * 1000;
|
|
10
|
+
return Math.floor(converted);
|
|
11
|
+
};
|
|
12
|
+
export function isoToMs(duration) {
|
|
13
|
+
const regex = /P(?:([\d.]+)Y)?(?:([\d.]+)M)?(?:([\d.]+)W)?(?:([\d.]+)D)?(?:T(?:([\d.]+)H)?(?:([\d.]+)M)?(?:([\d.]+)S)?)?/;
|
|
14
|
+
const matches = duration.match(regex);
|
|
15
|
+
if (!matches)
|
|
16
|
+
return 0;
|
|
17
|
+
const [, years, months, weeks, days, hours, minutes, seconds] = matches;
|
|
18
|
+
// Approximate conversions for years/months if needed
|
|
19
|
+
const ms = (parseFloat(years || "0") * 365 * 24 * 60 * 60 +
|
|
20
|
+
parseFloat(months || "0") * 30 * 24 * 60 * 60 +
|
|
21
|
+
parseFloat(weeks || "0") * 7 * 24 * 60 * 60 +
|
|
22
|
+
parseFloat(days || "0") * 24 * 60 * 60 +
|
|
23
|
+
parseFloat(hours || "0") * 60 * 60 +
|
|
24
|
+
parseFloat(minutes || "0") * 60 +
|
|
25
|
+
parseFloat(seconds || "0")) * 1000;
|
|
26
|
+
return ms;
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,30 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
|
|
3
3
|
"name": "@bouko/ts",
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
"version": "0.3.1",
|
|
6
|
+
|
|
5
7
|
"main": "./dist/index.js",
|
|
8
|
+
|
|
6
9
|
"types": "./dist/index.d.ts",
|
|
10
|
+
|
|
7
11
|
"license": "MIT",
|
|
12
|
+
|
|
8
13
|
"files": [
|
|
14
|
+
|
|
9
15
|
"dist"
|
|
16
|
+
|
|
10
17
|
],
|
|
18
|
+
|
|
11
19
|
"publishConfig": {
|
|
20
|
+
|
|
12
21
|
"access": "public"
|
|
22
|
+
|
|
13
23
|
},
|
|
24
|
+
|
|
14
25
|
"author": "",
|
|
26
|
+
|
|
15
27
|
"description": "",
|
|
28
|
+
|
|
16
29
|
"engines": {},
|
|
17
30
|
|
|
18
31
|
"scripts": {
|
|
32
|
+
|
|
19
33
|
"build": "tsc"
|
|
34
|
+
|
|
20
35
|
},
|
|
21
36
|
|
|
22
37
|
"dependencies": {
|
|
38
|
+
|
|
39
|
+
"chalk": "^5.6.0",
|
|
40
|
+
|
|
23
41
|
"zod": "^4.1.5"
|
|
42
|
+
|
|
24
43
|
},
|
|
25
44
|
|
|
26
45
|
"devDependencies": {
|
|
46
|
+
|
|
47
|
+
"@types/node": "^24.3.0",
|
|
48
|
+
|
|
27
49
|
"typescript": "^5.9.2"
|
|
50
|
+
|
|
28
51
|
}
|
|
29
52
|
|
|
30
|
-
}
|
|
53
|
+
}
|
|
54
|
+
|