superjs-core 0.4.0 → 0.4.2

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 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/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export { generateReport } from './dep-exray/reporter/index.js';
13
13
  export { analyzeUsage } from './dep-exray/analyzer/index.js';
14
14
  export { DependencyInfo, ReplacementSuggestion, ScanResult, ScannerConfig, SecurityIssue } from './dep-exray/types.js';
15
15
  export { KNOWN_CVES, KNOWN_MAPPINGS } from './dep-exray/known-mappings.js';
16
- export { isEmail, isNIK, isNPWP, isPhone, isURL } from './validation/index.js';
16
+ export { NIKInfo, isEmail, isKodepos, isNIK, isNPWP, isNoRekening, isPhone, isPlatNomor, isURL, parseNIK } from './validation/index.js';
17
17
  export { ErrorCode, MultiError, TypedError, collectErrors, createError, isTypedError } from './error/index.js';
18
18
  export { L as LogLevel, a as Logger, T as Transport, c as consoleTransport, b as createBufferedTransport, d as createConsoleTransport, e as createFileTransport, f as createJsonTransport, l as logger } from './index-BgG21uJC.js';
19
19
  export { contrastRatio, darken, hexToRgb, lighten, meetsWCAG, rgbToHex } from './color/index.js';
package/dist/index.js CHANGED
@@ -1980,6 +1980,194 @@ function isURL(value) {
1980
1980
  }
1981
1981
  }
1982
1982
 
1983
+ // src/validation/parseNIK.ts
1984
+ function parseNIK(value) {
1985
+ const digits = value.replace(/\D/g, "");
1986
+ const info = {
1987
+ nik: value,
1988
+ valid: false,
1989
+ gender: null,
1990
+ birthDate: null,
1991
+ province: null,
1992
+ provinceCode: null,
1993
+ city: null,
1994
+ cityCode: null,
1995
+ district: null,
1996
+ districtCode: null,
1997
+ uniqueCode: null
1998
+ };
1999
+ if (digits.length !== 16) return info;
2000
+ const provinceCode = digits.slice(0, 2);
2001
+ const cityCode = digits.slice(2, 4);
2002
+ const districtCode = digits.slice(4, 6);
2003
+ const rawDay = Number.parseInt(digits.slice(6, 8), 10);
2004
+ const month = Number.parseInt(digits.slice(8, 10), 10);
2005
+ const year = Number.parseInt(digits.slice(10, 12), 10);
2006
+ const uniqueCode = digits.slice(12, 16);
2007
+ if (rawDay < 1 || rawDay > 71 || month < 1 || month > 12) return info;
2008
+ const gender = rawDay >= 41 ? "PEREMPUAN" : "LAKI-LAKI";
2009
+ let day = rawDay;
2010
+ if (day >= 41) day -= 40;
2011
+ const fullYear = year < 70 ? 2e3 + year : 1900 + year;
2012
+ const birthDate = new Date(fullYear, month - 1, day);
2013
+ if (birthDate.getFullYear() !== fullYear || birthDate.getMonth() !== month - 1 || birthDate.getDate() !== day) {
2014
+ return info;
2015
+ }
2016
+ return {
2017
+ nik: value,
2018
+ valid: true,
2019
+ gender,
2020
+ birthDate,
2021
+ province: PROVINCE_CODES[provinceCode] ?? null,
2022
+ provinceCode,
2023
+ city: null,
2024
+ cityCode,
2025
+ district: null,
2026
+ districtCode,
2027
+ uniqueCode
2028
+ };
2029
+ }
2030
+ var PROVINCE_CODES = {
2031
+ "11": "ACEH",
2032
+ "12": "SUMATERA UTARA",
2033
+ "13": "SUMATERA BARAT",
2034
+ "14": "RIAU",
2035
+ "15": "JAMBI",
2036
+ "16": "SUMATERA SELATAN",
2037
+ "17": "BENGKULU",
2038
+ "18": "LAMPUNG",
2039
+ "19": "KEPULAUAN BANGKA BELITUNG",
2040
+ "21": "KEPULAUAN RIAU",
2041
+ "31": "DKI JAKARTA",
2042
+ "32": "JAWA BARAT",
2043
+ "33": "JAWA TENGAH",
2044
+ "34": "DI YOGYAKARTA",
2045
+ "35": "JAWA TIMUR",
2046
+ "36": "BANTEN",
2047
+ "51": "BALI",
2048
+ "52": "NUSA TENGGARA BARAT",
2049
+ "53": "NUSA TENGGARA TIMUR",
2050
+ "61": "KALIMANTAN BARAT",
2051
+ "62": "KALIMANTAN TENGAH",
2052
+ "63": "KALIMANTAN SELATAN",
2053
+ "64": "KALIMANTAN TIMUR",
2054
+ "65": "KALIMANTAN UTARA",
2055
+ "71": "SULAWESI UTARA",
2056
+ "72": "SULAWESI TENGAH",
2057
+ "73": "SULAWESI SELATAN",
2058
+ "74": "SULAWESI TENGGARA",
2059
+ "75": "GORONTALO",
2060
+ "76": "SULAWESI BARAT",
2061
+ "81": "MALUKU",
2062
+ "82": "MALUKU UTARA",
2063
+ "91": "PAPUA",
2064
+ "92": "PAPUA BARAT",
2065
+ "93": "PAPUA SELATAN",
2066
+ "94": "PAPUA TENGAH",
2067
+ "95": "PAPUA PEGUNUNGAN"
2068
+ };
2069
+
2070
+ // src/validation/isPlatNomor.ts
2071
+ function isPlatNomor(value) {
2072
+ const trimmed = value.trim().toUpperCase();
2073
+ const regex = /^([A-Z]{1,2})\s*(\d{1,4})\s*([A-Z]{0,3})$/;
2074
+ const match = trimmed.match(regex);
2075
+ if (!match) return false;
2076
+ const kodeDepan = match[1];
2077
+ const angka = parseInt(match[2], 10);
2078
+ const kodeBelakang = match[3] || "";
2079
+ if (!KODE_DAERAH.includes(kodeDepan)) return false;
2080
+ if (angka < 1 || angka > 9999) return false;
2081
+ if (kodeBelakang.length > 3) return false;
2082
+ return true;
2083
+ }
2084
+ var KODE_DAERAH = [
2085
+ "A",
2086
+ "AA",
2087
+ "AB",
2088
+ "AD",
2089
+ "AE",
2090
+ "AG",
2091
+ "B",
2092
+ "BA",
2093
+ "BB",
2094
+ "BD",
2095
+ "BE",
2096
+ "BG",
2097
+ "BH",
2098
+ "BK",
2099
+ "BL",
2100
+ "BM",
2101
+ "BN",
2102
+ "BP",
2103
+ "BR",
2104
+ "BT",
2105
+ "BU",
2106
+ "BV",
2107
+ "BW",
2108
+ "D",
2109
+ "DA",
2110
+ "DB",
2111
+ "DC",
2112
+ "DD",
2113
+ "DE",
2114
+ "DF",
2115
+ "DG",
2116
+ "DH",
2117
+ "DK",
2118
+ "DL",
2119
+ "DM",
2120
+ "DN",
2121
+ "DP",
2122
+ "DR",
2123
+ "DT",
2124
+ "DU",
2125
+ "DW",
2126
+ "E",
2127
+ "EA",
2128
+ "EB",
2129
+ "ED",
2130
+ "EE",
2131
+ "F",
2132
+ "G",
2133
+ "H",
2134
+ "K",
2135
+ "KB",
2136
+ "KH",
2137
+ "KI",
2138
+ "KU",
2139
+ "KT",
2140
+ "L",
2141
+ "M",
2142
+ "N",
2143
+ "NB",
2144
+ "NG",
2145
+ "NK",
2146
+ "NM",
2147
+ "P",
2148
+ "PA",
2149
+ "PB",
2150
+ "R",
2151
+ "S",
2152
+ "ST",
2153
+ "T",
2154
+ "W",
2155
+ "Z"
2156
+ ];
2157
+
2158
+ // src/validation/isKodepos.ts
2159
+ function isKodepos(value) {
2160
+ if (value.length !== 5) return false;
2161
+ return /^\d{5}$/.test(value);
2162
+ }
2163
+
2164
+ // src/validation/isNoRekening.ts
2165
+ function isNoRekening(value) {
2166
+ const digits = value.replace(/\D/g, "");
2167
+ if (digits.length < 8 || digits.length > 16) return false;
2168
+ return true;
2169
+ }
2170
+
1983
2171
  // src/error/createError.ts
1984
2172
  var defaultStatus = {
1985
2173
  "BAD_REQUEST": 400,
@@ -2425,15 +2613,18 @@ export {
2425
2613
  isEmail,
2426
2614
  isEmpty,
2427
2615
  isFunction,
2616
+ isKodepos,
2428
2617
  isLeapYear,
2429
2618
  isMap,
2430
2619
  isNIK,
2431
2620
  isNPWP,
2432
2621
  isNil,
2622
+ isNoRekening,
2433
2623
  isNull,
2434
2624
  isNumber,
2435
2625
  isObject,
2436
2626
  isPhone,
2627
+ isPlatNomor,
2437
2628
  isPromise,
2438
2629
  isRegExp,
2439
2630
  isSet,
@@ -2464,6 +2655,7 @@ export {
2464
2655
  parse,
2465
2656
  parseCsv,
2466
2657
  parseDate,
2658
+ parseNIK,
2467
2659
  pascalCase,
2468
2660
  pick,
2469
2661
  pipeline,