@khgtrn/lib 1.0.0 → 1.0.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/README.md +8 -8
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Library for Typescript/Javascript
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@khgtrn/lib)
|
|
4
|
+
[](https://www.npmjs.com/package/@khgtrn/lib)
|
|
5
|
+
[](https://github.com/khgtrn/ts-lib/blob/main/LICENSE)
|
|
6
6
|
|
|
7
7
|
Shared TypeScript utility library: Java-style enums, common helper functions, number-to-words conversion (Vietnamese/English), and floating-point-safe rounding.
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ Built as both ESM (`dist/esm`) and CJS (`dist/cjs`), with full type declarations
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
pnpm add @khgtrn/
|
|
14
|
+
pnpm add @khgtrn/lib
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
Requires Node.js >= 19 at runtime (needed for `crypto.getRandomValues` as a global — see `engines` in [package.json](package.json)). The shipped `.d.ts` files are compatible down to **TypeScript 2.7**, and the compiled JS itself avoids syntax (`?.`, `??`) that older bundlers can't parse — no separate install/config needed to consume this package from a legacy toolchain (e.g. Angular 6).
|
|
@@ -21,7 +21,7 @@ Requires Node.js >= 19 at runtime (needed for `crypto.getRandomValues` as a glob
|
|
|
21
21
|
`BaseEnum` is a base class for simulating Java enums: each constant is a singleton instance, and subclasses only need to `extends` and declare `static readonly` fields — no constructor to write.
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
|
-
import { BaseEnum } from '@khgtrn/
|
|
24
|
+
import { BaseEnum } from '@khgtrn/lib';
|
|
25
25
|
|
|
26
26
|
class Role extends BaseEnum<number> {
|
|
27
27
|
static readonly Admin = new Role(1, 'Administrator');
|
|
@@ -76,7 +76,7 @@ See the JSDoc in [src/func.ts](src/func.ts) for full parameter/return details.
|
|
|
76
76
|
## numberToWords — spelling out numbers
|
|
77
77
|
|
|
78
78
|
```ts
|
|
79
|
-
import { numberToWords } from '@khgtrn/
|
|
79
|
+
import { numberToWords } from '@khgtrn/lib';
|
|
80
80
|
|
|
81
81
|
numberToWords(1005); // "một nghìn không trăm linh năm" (Vietnamese by default)
|
|
82
82
|
numberToWords(1005, 'en'); // "one thousand five"
|
|
@@ -92,7 +92,7 @@ numberToWords(-123, 'en'); // "negative one hundred twenty-three"
|
|
|
92
92
|
## round — floating-point-safe rounding
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
|
-
import { round } from '@khgtrn/
|
|
95
|
+
import { round } from '@khgtrn/lib';
|
|
96
96
|
|
|
97
97
|
round(491.66999999999996); // 491.67 (default precision = 10)
|
|
98
98
|
round(1.23456, 2); // 1.23
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khgtrn/lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Library for Typescript",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
"typescript",
|
|
23
23
|
"ts",
|
|
24
24
|
"lib",
|
|
25
|
-
"library"
|
|
26
|
-
"klib"
|
|
25
|
+
"library"
|
|
27
26
|
],
|
|
28
27
|
"author": "khgtrn",
|
|
29
28
|
"license": "MIT",
|