superjs-core 0.3.7 → 0.3.8
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 +173 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# superjs-core
|
|
2
|
+
|
|
3
|
+
> **Zero-dependency JavaScript toolkit — Standard Library + Dependency Scanner + 🇮🇩 Indonesia Validation**
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install superjs-core
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Satu package untuk semua kebutuhan JavaScript: utility functions, async helpers, crypto, path manipulation, typed errors, structured logging, **plus** dependency health scanner dan validasi data Indonesia (NIK, NPWP, Phone).
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Modules Overview
|
|
14
|
+
|
|
15
|
+
| Module | Fungsi Unggulan |
|
|
16
|
+
|--------|----------------|
|
|
17
|
+
| **core** | deepClone, deepMerge, debounce, throttle, memoize, retry, once |
|
|
18
|
+
| **math** | add/sub/mul/div (safe), median, stddev, percentile, correlation, formatCurrency |
|
|
19
|
+
| **date** | formatDate, parseDate, timeAgo, Duration, timezone helpers (WIB/WITA/WIT) |
|
|
20
|
+
| **collection** | sortBy, groupBy, shuffle, topoSort, slidingWindows, chunk |
|
|
21
|
+
| **string** | camelCase, uuid, nanoid, slugify, levenshtein, terbilang, formatRupiah, maskString |
|
|
22
|
+
| **async** | sleep, parallelMap, Queue, Semaphore, memoizeAsync, retryAsync |
|
|
23
|
+
| **io** | parseCsv, stringifyCsv, safeJsonParse, env, envInt, envBool |
|
|
24
|
+
| **type** | 20+ type guards (isString, isNil, assertDefined, getType) |
|
|
25
|
+
| **crypto** | hash, base64, generateToken, generateOTP, constantTimeEqual |
|
|
26
|
+
| **path** | join, resolve, basename, dirname, extname, normalize |
|
|
27
|
+
| **validation** | isNIK, isNPWP, isPhone("id"), isEmail, isURL |
|
|
28
|
+
| **error** | createError (typed + HTTP status), TypedError, MultiError |
|
|
29
|
+
| **logger** | Logger class, child loggers, console/JSON/file transports |
|
|
30
|
+
| **dep-exray** | scanProject, generateReport, analyzeUsage, CLI: `npx dep-exray .` |
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Contoh Cepat
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { deepClone, debounce } from "superjs-core"
|
|
38
|
+
import { formatDate, timeAgo } from "superjs-core/date"
|
|
39
|
+
import { groupBy, topoSort } from "superjs-core/collection"
|
|
40
|
+
import { sleep, parallelMap, Queue } from "superjs-core/async"
|
|
41
|
+
import { uuid, maskString, terbilang, formatRupiah } from "superjs-core/string"
|
|
42
|
+
import { generateToken } from "superjs-core/crypto"
|
|
43
|
+
import { isNIK, isNPWP, isPhone } from "superjs-core/validation"
|
|
44
|
+
import { createError, MultiError } from "superjs-core/error"
|
|
45
|
+
import { Logger } from "superjs-core/logger"
|
|
46
|
+
import { median, stddev, formatCurrency } from "superjs-core/math"
|
|
47
|
+
import { scanProject } from "superjs-core/dep-exray"
|
|
48
|
+
|
|
49
|
+
// Deep clone dengan circular reference
|
|
50
|
+
const cloned = deepClone({ a: 1, b: { c: new Date() } })
|
|
51
|
+
|
|
52
|
+
// Safe math (0.1 + 0.2 = 0.3)
|
|
53
|
+
console.log(add(0.1, 0.2)) // 0.3
|
|
54
|
+
|
|
55
|
+
// Date formatting
|
|
56
|
+
console.log(formatDate(new Date(), "DD/MM/YYYY")) // "28/06/2026"
|
|
57
|
+
console.log(timeAgo(new Date(Date.now() - 5000))) // "5 detik yang lalu"
|
|
58
|
+
|
|
59
|
+
// Priority queue
|
|
60
|
+
const queue = new Queue({ concurrency: 2 })
|
|
61
|
+
await queue.add(() => fetch("/api/data"))
|
|
62
|
+
|
|
63
|
+
// Validation Indonesia
|
|
64
|
+
isNIK("3201010203940001") // true
|
|
65
|
+
isNPWP("12.345.678.9-012.344") // true
|
|
66
|
+
isPhone("08123456789") // true
|
|
67
|
+
|
|
68
|
+
// Indonesian locale
|
|
69
|
+
terbilang(1500000) // "satu juta lima ratus ribu"
|
|
70
|
+
formatRupiah(1500000) // "Rp1.500.000"
|
|
71
|
+
maskString("08123456789") // "081*****789"
|
|
72
|
+
|
|
73
|
+
// Statistics
|
|
74
|
+
median([1, 2, 3, 4, 5]) // 3
|
|
75
|
+
percentile([1, 2, 3, 4, 5], 90) // 4.6
|
|
76
|
+
formatCurrency(1500000, { locale: "id-ID", currency: "IDR" }) // "Rp 1.500.000"
|
|
77
|
+
|
|
78
|
+
// Typed errors
|
|
79
|
+
throw createError("VALIDATION_ERROR", "Email required", { details: { field: "email" } })
|
|
80
|
+
|
|
81
|
+
// Logger
|
|
82
|
+
const log = new Logger({ level: "info", name: "app" })
|
|
83
|
+
log.info("Server started", { port: 3000 })
|
|
84
|
+
|
|
85
|
+
// Dependency scanning
|
|
86
|
+
const report = await scanProject({ path: "./my-project" })
|
|
87
|
+
console.log(report.totalEstimatedSize)
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## dep-exray — Dependency Health Scanner (built-in)
|
|
92
|
+
|
|
93
|
+
**Scan project untuk nemuin dependency bloated, gak kepake, atau punya CVE.**
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx dep-exray .
|
|
97
|
+
npx dep-exray /path/to/project --json --verbose
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Features
|
|
101
|
+
- Deteksi replacement: lodash → superjs-core, moment → superjs-core/date, uuid → native crypto.randomUUID()
|
|
102
|
+
- Estimasi ukuran dependency dalam MB/KB
|
|
103
|
+
- CVE detection dari known database
|
|
104
|
+
- JSON output untuk CI/CD integration
|
|
105
|
+
- Usage analyzer — deteksi apakah dependency beneran dipake
|
|
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 |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Project Structure
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
packages/core/
|
|
134
|
+
├── src/
|
|
135
|
+
│ ├── core/ # deepClone, debounce, retry, once
|
|
136
|
+
│ ├── math/ # add, median, stddev, formatCurrency
|
|
137
|
+
│ ├── date/ # formatDate, timeAgo, Duration, timezone
|
|
138
|
+
│ ├── collection/ # groupBy, topoSort, slidingWindows
|
|
139
|
+
│ ├── string/ # camelCase, terbilang, formatRupiah
|
|
140
|
+
│ ├── async/ # sleep, Queue, Semaphore, memoizeAsync
|
|
141
|
+
│ ├── io/ # parseCsv, safeJsonParse, env
|
|
142
|
+
│ ├── type/ # 20+ type guards
|
|
143
|
+
│ ├── crypto/ # hash, generateToken, base64
|
|
144
|
+
│ ├── path/ # join, resolve, basename
|
|
145
|
+
│ ├── validation/ # isNIK, isNPWP, isPhone, isEmail, isURL
|
|
146
|
+
│ ├── error/ # createError, TypedError, MultiError
|
|
147
|
+
│ ├── logger/ # Logger, transports
|
|
148
|
+
│ └── dep-exray/ # Dependency scanner
|
|
149
|
+
├── tests/ # 757 tests
|
|
150
|
+
├── dist/ # Built output
|
|
151
|
+
├── tsup.config.ts
|
|
152
|
+
├── vitest.config.ts
|
|
153
|
+
├── biome.json
|
|
154
|
+
└── package.json
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Roadmap
|
|
160
|
+
|
|
161
|
+
Lihat [ROADMAP.md](./ROADMAP.md) untuk detail lengkap.
|
|
162
|
+
|
|
163
|
+
### Priority
|
|
164
|
+
- **P0 ✅** validation, error, logger modules
|
|
165
|
+
- **P1 ✅** async (Queue, Semaphore), math (stats), string (terbilang), collection (topoSort), date (timeAgo)
|
|
166
|
+
- **P2** core (pipe/compose, Result type), signal module, crypto (AES-GCM)
|
|
167
|
+
- **P3** ml, color modules
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "superjs-core",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.8",
|
|
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",
|
|
7
7
|
"module": "./dist/index.js",
|