superjs-core 0.4.0 → 0.4.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.
Files changed (2) hide show
  1. package/README.md +85 -97
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,179 +1,167 @@
1
1
  # superjs-core
2
2
 
3
- > **All-in-one JavaScript toolkit — Standard Library + Dependency Scanner + 🇮🇩 Indonesia Validation + Logger + Typed Errors**
3
+ > **JavaScript toolkit all-in-one buat developer Indonesia — Standard Library + Dependency Scanner + 🇮🇩 Validasi NIK/NPWP/Phone + Logger + Typed Errors**
4
4
 
5
5
  ```bash
6
6
  npm install superjs-core
7
7
  ```
8
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).
9
+ Satu package buat semua kebutuhan JavaScript lo: utility functions, async helpers, crypto, path manipulation, typed errors, structured logging, **plus** dependency health scanner dan validasi data Indonesia (NIK, NPWP, Phone).
10
+
11
+ **100% buat programmer Indonesia. Zero dependency runtime.**
10
12
 
11
13
  ---
12
14
 
13
- ## Features
15
+ ## Fitur Unggulan 🇮🇩
14
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
17
+ | Fitur | Fungsi |
18
+ |-------|--------|
19
+ | **Validasi NIK** | `isNIK('3201010203940001')` validasi 16 digit + tanggal lahir |
20
+ | **Validasi NPWP** | `isNPWP('12.345.678.9-012.344')`dengan checksum otomatis |
21
+ | **Validasi Nomor HP** | `isPhone('08123456789')` support semua prefix Indonesia |
22
+ | **Terbilang** | `terbilang(1500000)` "satu juta lima ratus ribu" |
23
+ | **Format Rupiah** | `formatRupiah(1500000)` → "Rp1.500.000" |
24
+ | **Format Waktu** | `timeAgo(new Date(...))` → "5 detik yang lalu" |
25
+ | **Timezone WIB/WITA/WIT** | `formatInTimezone(date, 'HH', TIMEZONE_WIB)` → "07" |
26
+ | **Dependency Scanner** | `npx dep-exray .` — scan project lo |
21
27
 
22
28
  ---
23
29
 
24
- ## Modules
30
+ ## 16 Modules
25
31
 
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 |
32
+ | Module | Fungsi Unggulan |
33
+ |--------|----------------|
34
+ | **core** | deepClone, deepMerge, debounce, deepEqual, pipe, throttle, memoize |
35
+ | **math** | add/sub/mul/div (safe float), median, stddev, percentile, formatCurrency |
36
+ | **date** | formatDate, timeAgo, Duration, timezone helpers (WIB/WITA/WIT) |
37
+ | **collection** | sortBy, groupBy, shuffle, topoSort, slidingWindows, deepGet, deepSet |
38
+ | **string** | camelCase, uuid, nanoid, slugify, **terbilang**, **formatRupiah**, maskString, formatBytes |
33
39
  | **async** | sleep, parallelMap, Queue, Semaphore, memoizeAsync, retryAsync |
34
- | **io** | parseCsv, stringifyCsv, safeJsonParse, env, envInt, envBool |
40
+ | **io** | parseCsv, stringifyCsv, safeJsonParse, env |
35
41
  | **type** | 20+ type guards (isString, isNil, assertDefined, getType) |
36
42
  | **crypto** | hash, base64, generateToken, generateOTP, constantTimeEqual |
37
43
  | **path** | join, resolve, basename, dirname, extname, normalize |
38
- | **validation** | isNIK, isNPWP, isPhone("id"), isEmail, isURL |
44
+ | **color** | hexToRgb, rgbToHex, lighten, darken, contrastRatio, meetsWCAG |
45
+ | **validation** | **isNIK**, **isNPWP**, **isPhone("id")**, isEmail, isURL |
39
46
  | **error** | createError (typed + HTTP status), TypedError, MultiError |
40
47
  | **logger** | Logger class, child loggers, console/JSON/file transports |
41
48
  | **dep-exray** | scanProject, generateReport, analyzeUsage, CLI: `npx dep-exray .` |
42
49
 
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
50
  ---
54
51
 
55
- ## Quick Examples
52
+ ## Contoh Kode
56
53
 
57
54
  ```typescript
58
- import { deepClone, debounce } from "superjs-core"
59
- import { formatDate, timeAgo } from "superjs-core/date"
60
- import { groupBy, topoSort } from "superjs-core/collection"
55
+ import { deepClone } from "superjs-core"
56
+ import { formatDate, timeAgo, TIMEZONE_WIB } from "superjs-core/date"
61
57
  import { Queue } from "superjs-core/async"
62
- import { uuid, maskString, terbilang, formatRupiah } from "superjs-core/string"
63
- import { generateToken } from "superjs-core/crypto"
58
+ import { uuid, maskString, terbilang, formatRupiah, formatBytes } from "superjs-core/string"
64
59
  import { isNIK, isNPWP, isPhone } from "superjs-core/validation"
65
60
  import { createError } from "superjs-core/error"
66
61
  import { Logger } from "superjs-core/logger"
67
- import { median, stddev, formatCurrency } from "superjs-core/math"
68
- import { scanProject } from "superjs-core/dep-exray"
62
+ import { hexToRgb, contrastRatio } from "superjs-core/color"
69
63
 
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
64
+ // Validasi data Indonesia
65
+ isNIK("3201010203940001") // true
66
+ isNPWP("12.345.678.9-012.344") // true
67
+ isPhone("08123456789") // true
76
68
 
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"
69
+ // Konversi angka ke kata
70
+ terbilang(1500000) // "satu juta lima ratus ribu"
71
+ formatRupiah(1500000) // "Rp1.500.000"
80
72
 
81
- // Priority task queue
82
- const queue = new Queue({ concurrency: 2 })
83
- await queue.add(() => fetch("/api/data"))
73
+ // Relative time
74
+ timeAgo(new Date(Date.now() - 5000)) // "5 detik yang lalu"
84
75
 
85
- // Indonesia validation
86
- isNIK("3201010203940001") // true
87
- isNPWP("12.345.678.9-012.344") // true
88
- isPhone("08123456789") // true
76
+ // Mask data sensitif (PDPA compliance)
77
+ maskString("08123456789") // "081*****789"
89
78
 
90
- // Indonesian locale
91
- terbilang(1500000) // "satu juta lima ratus ribu"
92
- formatRupiah(1500000) // "Rp1.500.000"
79
+ // Format file size
80
+ formatBytes(1048576) // "1 MB"
93
81
 
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"
82
+ // Color utilities
83
+ hexToRgb("#ff0000") // { r: 255, g: 0, b: 0 }
84
+ contrastRatio("#000000", "#ffffff") // 21
98
85
 
99
86
  // Typed errors
100
- throw createError("VALIDATION_ERROR", "Email required", { details: { field: "email" } })
87
+ throw createError("VALIDATION_ERROR", "Email wajib diisi")
101
88
 
102
89
  // Structured logger
103
90
  const log = new Logger({ level: "info", name: "app" })
104
91
  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
92
  ```
110
93
 
111
94
  ---
112
95
 
113
- ## dep-exray — Dependency Health Scanner (built-in)
96
+ ## dep-exray — Dependency Health Scanner
114
97
 
115
- **Scan your project to find bloated, unused, or vulnerable dependencies.**
98
+ **Scan project lo buat nemuin dependency yang gak kepake, bloated, atau punya CVE.**
116
99
 
117
100
  ```bash
118
101
  npx dep-exray .
119
102
  npx dep-exray /path/to/project --json --verbose
120
103
  ```
121
104
 
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
105
+ ### Fitur
106
+ - Deteksi replacement: lodash → superjs-core, moment → superjs-core/date, uuid → native crypto.randomUUID()
107
+ - Estimasi ukuran dependency
108
+ - CVE detection
109
+ - JSON output untuk CI/CD
110
+ - Usage analyzer
111
+
112
+ ---
113
+
114
+ ## Quick Start
115
+
116
+ ```bash
117
+ git clone https://github.com/superdevids/superjs.git
118
+ cd superjs/packages/core
119
+ npm install
120
+ npx tsup # Build
121
+ npx vitest run # Test (810 tests)
122
+ npx dep-exray . # Scan project sendiri
123
+ ```
124
+
125
+ ---
126
+
127
+ ## Statistik Test
128
+
129
+ | File Tes | Jumlah |
130
+ |----------|--------|
131
+ | 18 file | **810** passing ✅ |
128
132
 
129
133
  ---
130
134
 
131
- ## Project Structure
135
+ ## Struktur Project
132
136
 
133
137
  ```
134
138
  packages/core/
135
139
  ├── src/
136
- │ ├── core/ # deepClone, debounce, retry, once
140
+ │ ├── core/ # deepClone, debounce, deepEqual, pipe
137
141
  │ ├── math/ # add, median, stddev, formatCurrency
138
- │ ├── date/ # formatDate, timeAgo, Duration, timezone
139
- │ ├── collection/ # groupBy, topoSort, slidingWindows
142
+ │ ├── date/ # formatDate, timeAgo, Duration, WIB/WITA/WIT
143
+ │ ├── collection/ # groupBy, topoSort, deepGet, deepSet
140
144
  │ ├── string/ # camelCase, terbilang, formatRupiah
141
145
  │ ├── async/ # sleep, Queue, Semaphore, memoizeAsync
142
146
  │ ├── io/ # parseCsv, safeJsonParse, env
143
147
  │ ├── type/ # 20+ type guards
144
148
  │ ├── crypto/ # hash, generateToken, base64
145
149
  │ ├── path/ # join, resolve, basename
150
+ │ ├── color/ # hexToRgb, lighten, darken, contrastRatio
146
151
  │ ├── validation/ # isNIK, isNPWP, isPhone, isEmail, isURL
147
152
  │ ├── error/ # createError, TypedError, MultiError
148
153
  │ ├── logger/ # Logger, transports
149
154
  │ └── dep-exray/ # Dependency scanner
150
- ├── tests/ # 757 tests
151
- ├── dist/ # Built output
152
- ├── tsup.config.ts
153
- ├── vitest.config.ts
154
- ├── biome.json
155
+ ├── tests/ # 810 tests
156
+ ├── dist/ # Hasil build
155
157
  └── package.json
156
158
  ```
157
159
 
158
160
  ---
159
161
 
160
- ## Test Stats
161
-
162
- | Test Files | Tests |
163
- |-----------|-------|
164
- | 17 | **757** passing |
165
-
166
- ---
167
-
168
162
  ## Roadmap
169
163
 
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
164
+ Lihat [ROADMAP.md](./ROADMAP.md) untuk detail lengkap.
177
165
 
178
166
  ---
179
167
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "superjs-core",
3
- "version": "0.4.0",
4
- "description": "All-in-one JS toolkit: standard library (deepClone, debounce, deepEqual, pipe, color utilities, typed errors, logger, crypto, path, dependency scanner, Indonesia validation). 100+ functions, zero runtime deps, tree-shakeable.",
3
+ "version": "0.4.1",
4
+ "description": "JavaScript toolkit all-in-one buat developer Indonesia: validasi NIK/NPWP/Phone, terbilang, formatRupiah, timeAgo (WIB/WITA/WIT), deepClone, logger, dep scanner. 100+ fungsi, zero dep runtime.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",