@elliots/typical 0.1.8 → 0.1.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 +95 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  Typical adds runtime validation to typescript, making TypeScript type-safe at runtime *with no changes to your code*.
4
4
 
5
- It can be used as a TSC plugin, or ESM loader for Node.js.
6
-
7
- (Could add unplugin/vite plugin, bun plugin etc. if needed.)
5
+ It can be used as a TSC plugin, ESM loader for Node.js, or with bundlers like Vite, Webpack, and Rollup via unplugin.
8
6
 
9
7
  ## Why?
10
8
 
@@ -25,6 +23,7 @@ Why not.
25
23
  - ✅ TSC plugin
26
24
  - ✅ ESM loader for runtime transformation with `node --import @elliots/typical/esm` (or `node --loader @elliots/typical/esm-loader` for older Node versions)
27
25
  - ✅ tsx wrapper (ttsx) for easy use like `npx ttsx script.ts`
26
+ - ✅ Unplugin for Vite, Webpack, Rollup, esbuild, and more
28
27
 
29
28
  ## Installation
30
29
 
@@ -40,12 +39,30 @@ If not provided, these default settings will be used.
40
39
 
41
40
  ```json
42
41
  {
43
- "include": ["src/**/*.ts", "src/**/*.tsx"],
44
- "exclude": ["node_modules/**", "**/*.d.ts", "dist/**"],
45
- "optimizeReused": true
42
+ "include": ["**/*.ts", "**/*.tsx"],
43
+ "exclude": ["node_modules/**", "**/*.d.ts", "dist/**", "build/**"],
44
+ "reusableValidators": true,
45
+ "validateFunctions": true,
46
+ "validateCasts": false,
47
+ "hoistRegex": true,
48
+ "ignoreDOMTypes": true,
49
+ "ignoreTypes": []
46
50
  }
47
51
  ```
48
52
 
53
+ ### Configuration Options
54
+
55
+ | Option | Default | Description |
56
+ |--------|---------|-------------|
57
+ | `include` | `["**/*.ts", "**/*.tsx"]` | Glob patterns for files to transform |
58
+ | `exclude` | `["node_modules/**", "**/*.d.ts", "dist/**", "build/**"]` | Glob patterns for files to skip |
59
+ | `reusableValidators` | `true` | Create shared validators for identical types (smaller output, allows reuse) |
60
+ | `validateFunctions` | `true` | Validate function parameters and return types at runtime |
61
+ | `validateCasts` | `false` | Validate type assertions (`as Type`) at runtime |
62
+ | `hoistRegex` | `true` | Hoist regex patterns to top-level constants (improves performance) |
63
+ | `ignoreDOMTypes` | `true` | Skip validation for DOM types (Document, Element, etc.) |
64
+ | `ignoreTypes` | `[]` | Type patterns to skip validation for (supports wildcards, e.g., `["React.*"]`) |
65
+
49
66
  ## Usage
50
67
 
51
68
  See ./samples/esm and ./samples/tsc and ./samples/ttsx
@@ -64,6 +81,78 @@ npm add -g @elliots/typical
64
81
  ttsx your-script.ts
65
82
  ```
66
83
 
84
+ ## Vite / Webpack / Rollup (unplugin)
85
+
86
+ Install the unplugin:
87
+
88
+ ```bash
89
+ npm add @elliots/unplugin-typical
90
+ ```
91
+
92
+ ### Vite
93
+
94
+ ```typescript
95
+ // vite.config.ts
96
+ import Typical from '@elliots/unplugin-typical/vite'
97
+
98
+ export default defineConfig({
99
+ plugins: [
100
+ Typical(),
101
+ ],
102
+ })
103
+ ```
104
+
105
+ ### Webpack
106
+
107
+ ```typescript
108
+ // webpack.config.js
109
+ const Typical = require('@elliots/unplugin-typical/webpack').default
110
+
111
+ module.exports = {
112
+ plugins: [
113
+ Typical(),
114
+ ],
115
+ }
116
+ ```
117
+
118
+ ### Rollup
119
+
120
+ ```typescript
121
+ // rollup.config.js
122
+ import Typical from '@elliots/unplugin-typical/rollup'
123
+
124
+ export default {
125
+ plugins: [
126
+ Typical(),
127
+ ],
128
+ }
129
+ ```
130
+
131
+ ### esbuild
132
+
133
+ ```typescript
134
+ import { build } from 'esbuild'
135
+ import Typical from '@elliots/unplugin-typical/esbuild'
136
+
137
+ build({
138
+ plugins: [Typical()],
139
+ })
140
+ ```
141
+
142
+ ### Plugin Configuration
143
+
144
+ Pass options directly to the plugin:
145
+
146
+ ```typescript
147
+ Typical({
148
+ validateFunctions: true,
149
+ validateCasts: false,
150
+ // ... other options
151
+ })
152
+ ```
153
+
154
+ Or use a `typical.json` file in your project root (shared with other entry points like TSC plugin and ESM loader).
155
+
67
156
  ## Example
68
157
 
69
158
  This code will run without errors when compiled normally, but will throw an error when using Typical.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliots/typical",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Runtime safe TypeScript transformer using typia",
5
5
  "main": "dist/src/index.js",
6
6
  "type": "module",