superjs-core 0.3.7 → 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.
Files changed (2) hide show
  1. package/README.md +182 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # superjs-core
2
+
3
+ > **All-in-one JavaScript toolkit — Standard Library + Dependency Scanner + 🇮🇩 Indonesia Validation + Logger + Typed Errors**
4
+
5
+ ```bash
6
+ npm install superjs-core
7
+ ```
8
+
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
+
11
+ ---
12
+
13
+ ## Features
14
+
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
+ |--------|---------------|
28
+ | **core** | deepClone, deepMerge, debounce, throttle, memoize, retry, once |
29
+ | **math** | add/sub/mul/div (safe float), median, stddev, percentile, correlation, formatCurrency |
30
+ | **date** | formatDate, parseDate, timeAgo, Duration, timezone helpers (WIB/WITA/WIT) |
31
+ | **collection** | sortBy, groupBy, shuffle, topoSort, slidingWindows, chunk |
32
+ | **string** | camelCase, uuid, nanoid, slugify, levenshtein, fuzzyMatch, maskString |
33
+ | **async** | sleep, parallelMap, Queue, Semaphore, memoizeAsync, retryAsync |
34
+ | **io** | parseCsv, stringifyCsv, safeJsonParse, env, envInt, envBool |
35
+ | **type** | 20+ type guards (isString, isNil, assertDefined, getType) |
36
+ | **crypto** | hash, base64, generateToken, generateOTP, constantTimeEqual |
37
+ | **path** | join, resolve, basename, dirname, extname, normalize |
38
+ | **validation** | isNIK, isNPWP, isPhone("id"), isEmail, isURL |
39
+ | **error** | createError (typed + HTTP status), TypedError, MultiError |
40
+ | **logger** | Logger class, child loggers, console/JSON/file transports |
41
+ | **dep-exray** | scanProject, generateReport, analyzeUsage, CLI: `npx dep-exray .` |
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
+
53
+ ---
54
+
55
+ ## Quick Examples
56
+
57
+ ```typescript
58
+ import { deepClone, debounce } from "superjs-core"
59
+ import { formatDate, timeAgo } from "superjs-core/date"
60
+ import { groupBy, topoSort } from "superjs-core/collection"
61
+ import { Queue } from "superjs-core/async"
62
+ import { uuid, maskString, terbilang, formatRupiah } from "superjs-core/string"
63
+ import { generateToken } from "superjs-core/crypto"
64
+ import { isNIK, isNPWP, isPhone } from "superjs-core/validation"
65
+ import { createError } from "superjs-core/error"
66
+ import { Logger } from "superjs-core/logger"
67
+ import { median, stddev, formatCurrency } from "superjs-core/math"
68
+ import { scanProject } from "superjs-core/dep-exray"
69
+
70
+ // Deep clone with circular reference support
71
+ const cloned = deepClone({ a: 1, b: { c: new Date() } })
72
+
73
+ // Safe math (0.1 + 0.2 = 0.3 ✅)
74
+ import { add } from "superjs-core/math"
75
+ console.log(add(0.1, 0.2)) // 0.3
76
+
77
+ // Date formatting without moment
78
+ console.log(formatDate(new Date(), "DD/MM/YYYY")) // "28/06/2026"
79
+ console.log(timeAgo(new Date(Date.now() - 5000))) // "5 seconds ago"
80
+
81
+ // Priority task queue
82
+ const queue = new Queue({ concurrency: 2 })
83
+ await queue.add(() => fetch("/api/data"))
84
+
85
+ // Indonesia validation
86
+ isNIK("3201010203940001") // true
87
+ isNPWP("12.345.678.9-012.344") // true
88
+ isPhone("08123456789") // true
89
+
90
+ // Indonesian locale
91
+ terbilang(1500000) // "satu juta lima ratus ribu"
92
+ formatRupiah(1500000) // "Rp1.500.000"
93
+
94
+ // Statistics
95
+ median([1, 2, 3, 4, 5]) // 3
96
+ percentile([1, 2, 3, 4, 5], 90) // 4.6
97
+ formatCurrency(1500000, { locale: "en-US", currency: "USD" }) // "$1,500,000"
98
+
99
+ // Typed errors
100
+ throw createError("VALIDATION_ERROR", "Email required", { details: { field: "email" } })
101
+
102
+ // Structured logger
103
+ const log = new Logger({ level: "info", name: "app" })
104
+ log.info("Server started", { port: 3000 })
105
+
106
+ // Dependency scanning
107
+ const report = await scanProject({ path: "./my-project" })
108
+ console.log(report.totalEstimatedSize) // "2.3 MB"
109
+ ```
110
+
111
+ ---
112
+
113
+ ## dep-exray — Dependency Health Scanner (built-in)
114
+
115
+ **Scan your project to find bloated, unused, or vulnerable dependencies.**
116
+
117
+ ```bash
118
+ npx dep-exray .
119
+ npx dep-exray /path/to/project --json --verbose
120
+ ```
121
+
122
+ ### Features
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
128
+
129
+ ---
130
+
131
+ ## Project Structure
132
+
133
+ ```
134
+ packages/core/
135
+ ├── src/
136
+ │ ├── core/ # deepClone, debounce, retry, once
137
+ │ ├── math/ # add, median, stddev, formatCurrency
138
+ │ ├── date/ # formatDate, timeAgo, Duration, timezone
139
+ │ ├── collection/ # groupBy, topoSort, slidingWindows
140
+ │ ├── string/ # camelCase, terbilang, formatRupiah
141
+ │ ├── async/ # sleep, Queue, Semaphore, memoizeAsync
142
+ │ ├── io/ # parseCsv, safeJsonParse, env
143
+ │ ├── type/ # 20+ type guards
144
+ │ ├── crypto/ # hash, generateToken, base64
145
+ │ ├── path/ # join, resolve, basename
146
+ │ ├── validation/ # isNIK, isNPWP, isPhone, isEmail, isURL
147
+ │ ├── error/ # createError, TypedError, MultiError
148
+ │ ├── logger/ # Logger, transports
149
+ │ └── dep-exray/ # Dependency scanner
150
+ ├── tests/ # 757 tests
151
+ ├── dist/ # Built output
152
+ ├── tsup.config.ts
153
+ ├── vitest.config.ts
154
+ ├── biome.json
155
+ └── package.json
156
+ ```
157
+
158
+ ---
159
+
160
+ ## Test Stats
161
+
162
+ | Test Files | Tests |
163
+ |-----------|-------|
164
+ | 17 | **757** passing |
165
+
166
+ ---
167
+
168
+ ## Roadmap
169
+
170
+ See [ROADMAP.md](./ROADMAP.md) for full details.
171
+
172
+ ### Priority
173
+ - **P0 ✅** validation, error, logger modules
174
+ - **P1 ✅** async (Queue, Semaphore), math (stats), string (terbilang), collection (topoSort), date (timeAgo)
175
+ - **P2** core (pipe/compose, Result type), signal module, crypto (AES-GCM)
176
+ - **P3** ml, color modules
177
+
178
+ ---
179
+
180
+ ## License
181
+
182
+ MIT
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "superjs-core",
3
- "version": "0.3.7",
4
- "description": "Zero-dependency JavaScript standard library + dependency health scanner — core, math, date, collection, string, async, io, type, crypto, path & dep-exray",
3
+ "version": "0.3.9",
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",