superjs-core 0.3.8 → 0.3.9
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 +58 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
# superjs-core
|
|
2
2
|
|
|
3
|
-
> **
|
|
3
|
+
> **All-in-one JavaScript toolkit — Standard Library + Dependency Scanner + 🇮🇩 Indonesia Validation + Logger + Typed Errors**
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install superjs-core
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
One package for all your JavaScript needs: utility functions, async helpers, crypto, path manipulation, typed errors, structured logging, **plus** dependency health scanner and Indonesia-specific data validation (NIK, NPWP, Phone).
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Features
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
- ✅ **90+ functions** — 16 modules covering everything from `deepClone` to `terbilang`
|
|
16
|
+
- ✅ **Tree-shakeable** — import only what you need via subpath exports
|
|
17
|
+
- ✅ **TypeScript strict** — full type safety, zero `any`
|
|
18
|
+
- ✅ **Zero runtime dependencies** — commander + picocolors are CLI-only
|
|
19
|
+
- ✅ **ESM-first** — target ES2022, optimized for Node 18+ and modern browsers
|
|
20
|
+
- ✅ **Biome linted** — consistent code style enforced
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Modules
|
|
25
|
+
|
|
26
|
+
| Module | Key Functions |
|
|
27
|
+
|--------|---------------|
|
|
17
28
|
| **core** | deepClone, deepMerge, debounce, throttle, memoize, retry, once |
|
|
18
|
-
| **math** | add/sub/mul/div (safe), median, stddev, percentile, correlation, formatCurrency |
|
|
29
|
+
| **math** | add/sub/mul/div (safe float), median, stddev, percentile, correlation, formatCurrency |
|
|
19
30
|
| **date** | formatDate, parseDate, timeAgo, Duration, timezone helpers (WIB/WITA/WIT) |
|
|
20
31
|
| **collection** | sortBy, groupBy, shuffle, topoSort, slidingWindows, chunk |
|
|
21
|
-
| **string** | camelCase, uuid, nanoid, slugify, levenshtein,
|
|
32
|
+
| **string** | camelCase, uuid, nanoid, slugify, levenshtein, fuzzyMatch, maskString |
|
|
22
33
|
| **async** | sleep, parallelMap, Queue, Semaphore, memoizeAsync, retryAsync |
|
|
23
34
|
| **io** | parseCsv, stringifyCsv, safeJsonParse, env, envInt, envBool |
|
|
24
35
|
| **type** | 20+ type guards (isString, isNil, assertDefined, getType) |
|
|
@@ -29,38 +40,49 @@ Satu package untuk semua kebutuhan JavaScript: utility functions, async helpers,
|
|
|
29
40
|
| **logger** | Logger class, child loggers, console/JSON/file transports |
|
|
30
41
|
| **dep-exray** | scanProject, generateReport, analyzeUsage, CLI: `npx dep-exray .` |
|
|
31
42
|
|
|
43
|
+
### 🇮🇩 Indonesian Locale
|
|
44
|
+
|
|
45
|
+
| Function | Description |
|
|
46
|
+
|----------|-------------|
|
|
47
|
+
| `terbilang(value)` | Convert numbers to Indonesian words ("satu juta lima ratus ribu") |
|
|
48
|
+
| `formatRupiah(value)` | Format as Rupiah ("Rp1.500.000") |
|
|
49
|
+
| `isNIK(value)` | Validate Indonesian NIK (16-digit ID number) |
|
|
50
|
+
| `isNPWP(value)` | Validate Indonesian NPWP (tax ID with checksum) |
|
|
51
|
+
| `isPhone(value)` | Validate Indonesian phone numbers |
|
|
52
|
+
|
|
32
53
|
---
|
|
33
54
|
|
|
34
|
-
##
|
|
55
|
+
## Quick Examples
|
|
35
56
|
|
|
36
57
|
```typescript
|
|
37
58
|
import { deepClone, debounce } from "superjs-core"
|
|
38
59
|
import { formatDate, timeAgo } from "superjs-core/date"
|
|
39
60
|
import { groupBy, topoSort } from "superjs-core/collection"
|
|
40
|
-
import {
|
|
61
|
+
import { Queue } from "superjs-core/async"
|
|
41
62
|
import { uuid, maskString, terbilang, formatRupiah } from "superjs-core/string"
|
|
42
63
|
import { generateToken } from "superjs-core/crypto"
|
|
43
64
|
import { isNIK, isNPWP, isPhone } from "superjs-core/validation"
|
|
44
|
-
import { createError
|
|
65
|
+
import { createError } from "superjs-core/error"
|
|
45
66
|
import { Logger } from "superjs-core/logger"
|
|
46
67
|
import { median, stddev, formatCurrency } from "superjs-core/math"
|
|
47
68
|
import { scanProject } from "superjs-core/dep-exray"
|
|
48
69
|
|
|
49
|
-
// Deep clone
|
|
70
|
+
// Deep clone with circular reference support
|
|
50
71
|
const cloned = deepClone({ a: 1, b: { c: new Date() } })
|
|
51
72
|
|
|
52
|
-
// Safe math (0.1 + 0.2 = 0.3)
|
|
73
|
+
// Safe math (0.1 + 0.2 = 0.3 ✅)
|
|
74
|
+
import { add } from "superjs-core/math"
|
|
53
75
|
console.log(add(0.1, 0.2)) // 0.3
|
|
54
76
|
|
|
55
|
-
// Date formatting
|
|
77
|
+
// Date formatting without moment
|
|
56
78
|
console.log(formatDate(new Date(), "DD/MM/YYYY")) // "28/06/2026"
|
|
57
|
-
console.log(timeAgo(new Date(Date.now() - 5000))) // "5
|
|
79
|
+
console.log(timeAgo(new Date(Date.now() - 5000))) // "5 seconds ago"
|
|
58
80
|
|
|
59
|
-
// Priority queue
|
|
81
|
+
// Priority task queue
|
|
60
82
|
const queue = new Queue({ concurrency: 2 })
|
|
61
83
|
await queue.add(() => fetch("/api/data"))
|
|
62
84
|
|
|
63
|
-
//
|
|
85
|
+
// Indonesia validation
|
|
64
86
|
isNIK("3201010203940001") // true
|
|
65
87
|
isNPWP("12.345.678.9-012.344") // true
|
|
66
88
|
isPhone("08123456789") // true
|
|
@@ -68,29 +90,29 @@ isPhone("08123456789") // true
|
|
|
68
90
|
// Indonesian locale
|
|
69
91
|
terbilang(1500000) // "satu juta lima ratus ribu"
|
|
70
92
|
formatRupiah(1500000) // "Rp1.500.000"
|
|
71
|
-
maskString("08123456789") // "081*****789"
|
|
72
93
|
|
|
73
94
|
// Statistics
|
|
74
95
|
median([1, 2, 3, 4, 5]) // 3
|
|
75
96
|
percentile([1, 2, 3, 4, 5], 90) // 4.6
|
|
76
|
-
formatCurrency(1500000, { locale: "
|
|
97
|
+
formatCurrency(1500000, { locale: "en-US", currency: "USD" }) // "$1,500,000"
|
|
77
98
|
|
|
78
99
|
// Typed errors
|
|
79
100
|
throw createError("VALIDATION_ERROR", "Email required", { details: { field: "email" } })
|
|
80
101
|
|
|
81
|
-
//
|
|
102
|
+
// Structured logger
|
|
82
103
|
const log = new Logger({ level: "info", name: "app" })
|
|
83
104
|
log.info("Server started", { port: 3000 })
|
|
84
105
|
|
|
85
106
|
// Dependency scanning
|
|
86
107
|
const report = await scanProject({ path: "./my-project" })
|
|
87
|
-
console.log(report.totalEstimatedSize)
|
|
108
|
+
console.log(report.totalEstimatedSize) // "2.3 MB"
|
|
109
|
+
```
|
|
88
110
|
|
|
89
111
|
---
|
|
90
112
|
|
|
91
113
|
## dep-exray — Dependency Health Scanner (built-in)
|
|
92
114
|
|
|
93
|
-
**Scan project
|
|
115
|
+
**Scan your project to find bloated, unused, or vulnerable dependencies.**
|
|
94
116
|
|
|
95
117
|
```bash
|
|
96
118
|
npx dep-exray .
|
|
@@ -98,32 +120,11 @@ npx dep-exray /path/to/project --json --verbose
|
|
|
98
120
|
```
|
|
99
121
|
|
|
100
122
|
### Features
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
- CVE detection
|
|
104
|
-
- JSON output
|
|
105
|
-
- Usage analyzer —
|
|
106
|
-
|
|
107
|
-
---
|
|
108
|
-
|
|
109
|
-
## Quick Start
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
git clone <repo-url> superjs
|
|
113
|
-
cd superjs/packages/core
|
|
114
|
-
npm install
|
|
115
|
-
npx tsup # Build
|
|
116
|
-
npx vitest run # Test (757 tests)
|
|
117
|
-
npx dep-exray . # Scan project
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
## Test Stats
|
|
123
|
-
|
|
124
|
-
| File | Tests |
|
|
125
|
-
|------|-------|
|
|
126
|
-
| 17 test files | **757** passing |
|
|
123
|
+
- Detect replacements: lodash → superjs-core, moment → superjs-core/date, uuid → native crypto.randomUUID()
|
|
124
|
+
- Estimate dependency size in MB/KB
|
|
125
|
+
- CVE detection from known vulnerability database
|
|
126
|
+
- JSON output for CI/CD integration
|
|
127
|
+
- Usage analyzer — detects whether dependencies are actually imported
|
|
127
128
|
|
|
128
129
|
---
|
|
129
130
|
|
|
@@ -156,9 +157,17 @@ packages/core/
|
|
|
156
157
|
|
|
157
158
|
---
|
|
158
159
|
|
|
160
|
+
## Test Stats
|
|
161
|
+
|
|
162
|
+
| Test Files | Tests |
|
|
163
|
+
|-----------|-------|
|
|
164
|
+
| 17 | **757** passing |
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
159
168
|
## Roadmap
|
|
160
169
|
|
|
161
|
-
|
|
170
|
+
See [ROADMAP.md](./ROADMAP.md) for full details.
|
|
162
171
|
|
|
163
172
|
### Priority
|
|
164
173
|
- **P0 ✅** validation, error, logger modules
|
|
@@ -170,4 +179,4 @@ Lihat [ROADMAP.md](./ROADMAP.md) untuk detail lengkap.
|
|
|
170
179
|
|
|
171
180
|
## License
|
|
172
181
|
|
|
173
|
-
MIT
|
|
182
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "superjs-core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "All-in-one JavaScript toolkit: standard library + Indonesia validation (NIK, NPWP, Phone) + dependency scanner + structured logger + typed errors. 90+ functions, zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|