@crustkit/minify 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 crustkit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # @crustkit/minify
2
+
3
+ JS and CSS minification. Zero config, great defaults, typed to the bone.
4
+
5
+ Built on [oxc](https://oxc.rs) (JS) and [Lightning CSS](https://lightningcss.dev) (CSS). Rust under the hood, npm on the surface.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @crustkit/minify
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { minifyJs, minifyCss, minify } from '@crustkit/minify'
17
+
18
+ // JS -- zero config
19
+ const { code } = minifyJs('var x = 1 + 2; console.log(x)')
20
+ // => 'console.log(3);'
21
+
22
+ // CSS -- zero config
23
+ const { code } = minifyCss('.foo { color: red; margin: 0px; }')
24
+ // => '.foo{color:red;margin:0}'
25
+
26
+ // Auto-detect from filename
27
+ const result = minify(code, { filename: 'app.js' })
28
+ const result = minify(code, { filename: 'style.css' })
29
+ ```
30
+
31
+ ### Source maps
32
+
33
+ When you pass `sourceMap: true`, the return type narrows. TypeScript knows `map` is a `string`, not `string | null`.
34
+
35
+ ```ts
36
+ const { code, map } = minifyJs(src, { sourceMap: true, filename: 'app.js' })
37
+ // ^-- map: string (guaranteed)
38
+ ```
39
+
40
+ ### JS options
41
+
42
+ ```ts
43
+ minifyJs(code, {
44
+ mangle: true, // shorten variable names (default: true)
45
+ compress: true, // dead code elimination (default: true)
46
+ sourceMap: false, // generate source map (default: false)
47
+ filename: 'app.js', // for source maps and error messages
48
+ module: true, // treat as ES module
49
+ })
50
+ ```
51
+
52
+ ### CSS options
53
+
54
+ CSS functions only accept CSS options. Passing `mangle` or `compress` is a type error.
55
+
56
+ ```ts
57
+ minifyCss(code, {
58
+ sourceMap: false,
59
+ filename: 'style.css',
60
+ })
61
+
62
+ minifyCss(code, { mangle: true })
63
+ // ^^^^^^ -- type error
64
+ ```
65
+
66
+ ### Terser drop-in
67
+
68
+ Change one import. Everything else stays the same.
69
+
70
+ ```ts
71
+ // before
72
+ import { minify } from 'terser'
73
+
74
+ // after
75
+ import { terser as minify } from '@crustkit/minify'
76
+
77
+ const result = await minify(code, {
78
+ compress: { drop_console: true },
79
+ mangle: true,
80
+ })
81
+ ```
82
+
83
+ Returns a Promise for API compatibility with terser. The work is synchronous in Rust.
84
+
85
+ ## What it does
86
+
87
+ - **JS**: Parses with oxc, compresses (constant folding, dead code elimination, inlining), mangles variable names, generates source maps. Handles ES modules, CommonJS, JSX, TypeScript.
88
+ - **CSS**: Parses with Lightning CSS, minifies whitespace, shortens values (`0px` to `0`), handles vendor prefixing, nesting, and modern CSS syntax.
89
+
90
+ ## License
91
+
92
+ MIT
@@ -0,0 +1,157 @@
1
+ interface JsOptions {
2
+ /** Shorten variable names. @default true */
3
+ mangle?: boolean;
4
+ /** Dead code elimination & constant folding. @default true */
5
+ compress?: boolean;
6
+ /** Generate a source map. @default false */
7
+ sourceMap?: boolean;
8
+ /** Filename — used for source maps and error messages. */
9
+ filename?: string;
10
+ /**
11
+ * Treat as ES module.
12
+ * @default auto-detected from filename extension (.mjs = module)
13
+ */
14
+ module?: boolean;
15
+ }
16
+ interface CssOptions {
17
+ /** Generate a source map. @default false */
18
+ sourceMap?: boolean;
19
+ /** Filename — used for source maps and error messages. */
20
+ filename?: string;
21
+ }
22
+ interface MinifyResult {
23
+ /** The minified code. */
24
+ code: string;
25
+ /** Source map JSON string. Only present when `sourceMap: true`. */
26
+ map: string | null;
27
+ }
28
+ interface MinifyResultWithMap {
29
+ code: string;
30
+ /** Source map JSON string. Guaranteed present. */
31
+ map: string;
32
+ }
33
+ interface MinifyResultWithoutMap {
34
+ code: string;
35
+ map: null;
36
+ }
37
+ /**
38
+ * Minify JavaScript or TypeScript.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { minifyJs } from '@crustkit/minify'
43
+ *
44
+ * // Zero config
45
+ * const { code } = minifyJs('var x = 1 + 2; console.log(x)')
46
+ *
47
+ * // With source map — `map` is guaranteed string
48
+ * const { code, map } = minifyJs(src, { sourceMap: true, filename: 'app.js' })
49
+ *
50
+ * // Disable mangling
51
+ * const { code } = minifyJs(src, { mangle: false })
52
+ * ```
53
+ */
54
+ declare function minifyJs(code: string, options: JsOptions & {
55
+ sourceMap: true;
56
+ }): MinifyResultWithMap;
57
+ declare function minifyJs(code: string, options?: JsOptions): MinifyResult;
58
+ /**
59
+ * Minify CSS. Handles vendor prefixing, nesting, and modern syntax automatically.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { minifyCss } from '@crustkit/minify'
64
+ *
65
+ * const { code } = minifyCss('.foo { color: red; margin: 0px; }')
66
+ * // '.foo{color:red;margin:0}'
67
+ *
68
+ * const { code, map } = minifyCss(src, { sourceMap: true })
69
+ * ```
70
+ */
71
+ declare function minifyCss(code: string, options: CssOptions & {
72
+ sourceMap: true;
73
+ }): MinifyResultWithMap;
74
+ declare function minifyCss(code: string, options?: CssOptions): MinifyResult;
75
+ type MinifyOptions = (JsOptions & {
76
+ language?: 'js';
77
+ }) | (CssOptions & {
78
+ language: 'css';
79
+ });
80
+ /**
81
+ * Minify code. Auto-detects language from `filename`, or set `language` explicitly.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import { minify } from '@crustkit/minify'
86
+ *
87
+ * // Auto-detect from filename
88
+ * minify('var x = 1', { filename: 'app.js' })
89
+ * minify('.foo { color: red }', { filename: 'style.css' })
90
+ *
91
+ * // Explicit language
92
+ * minify(code, { language: 'js' })
93
+ * minify(code, { language: 'css' })
94
+ *
95
+ * // Default: JS
96
+ * minify('var x = 1 + 2; console.log(x)')
97
+ * ```
98
+ */
99
+ declare function minify(code: string, options?: MinifyOptions): MinifyResult;
100
+ interface TerserCompressOptions {
101
+ /** Number of compression passes. @default 1 */
102
+ passes?: number;
103
+ /** Remove `debugger` statements. @default true */
104
+ drop_debugger?: boolean;
105
+ /** Remove `console.*` calls. @default false */
106
+ drop_console?: boolean;
107
+ /** Remove unreachable code. @default true */
108
+ dead_code?: boolean;
109
+ /** Join consecutive var/let/const statements. @default true */
110
+ join_vars?: boolean;
111
+ /** Allow other compress options terser accepts. */
112
+ [key: string]: unknown;
113
+ }
114
+ interface TerserMangleOptions {
115
+ /** Mangle top-level names. @default false */
116
+ toplevel?: boolean;
117
+ /** Names to keep unmangled. */
118
+ reserved?: string[];
119
+ /** Allow other mangle options terser accepts. */
120
+ [key: string]: unknown;
121
+ }
122
+ interface TerserSourceMapOptions {
123
+ /** Source map URL to embed in the output. */
124
+ url?: string;
125
+ /** Original filename for source map. */
126
+ filename?: string;
127
+ }
128
+ interface TerserOptions {
129
+ compress?: boolean | TerserCompressOptions;
130
+ mangle?: boolean | TerserMangleOptions;
131
+ sourceMap?: boolean | TerserSourceMapOptions;
132
+ module?: boolean;
133
+ toplevel?: boolean;
134
+ }
135
+ interface TerserResult {
136
+ code: string;
137
+ map?: string;
138
+ }
139
+ /**
140
+ * Terser-compatible drop-in replacement.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * // Before:
145
+ * import { minify } from 'terser'
146
+ *
147
+ * // After — just change the import:
148
+ * import { terser as minify } from '@crustkit/minify'
149
+ *
150
+ * const result = await minify(code, { compress: true, mangle: true })
151
+ * ```
152
+ *
153
+ * Returns a Promise for API compatibility. The work is synchronous in Rust.
154
+ */
155
+ declare function terser(code: string | Record<string, string>, options?: TerserOptions): Promise<TerserResult>;
156
+
157
+ export { type CssOptions, type JsOptions, type MinifyOptions, type MinifyResult, type MinifyResultWithMap, type MinifyResultWithoutMap, type TerserCompressOptions, type TerserMangleOptions, type TerserOptions, type TerserResult, type TerserSourceMapOptions, minify, minifyCss, minifyJs, terser };
@@ -0,0 +1,157 @@
1
+ interface JsOptions {
2
+ /** Shorten variable names. @default true */
3
+ mangle?: boolean;
4
+ /** Dead code elimination & constant folding. @default true */
5
+ compress?: boolean;
6
+ /** Generate a source map. @default false */
7
+ sourceMap?: boolean;
8
+ /** Filename — used for source maps and error messages. */
9
+ filename?: string;
10
+ /**
11
+ * Treat as ES module.
12
+ * @default auto-detected from filename extension (.mjs = module)
13
+ */
14
+ module?: boolean;
15
+ }
16
+ interface CssOptions {
17
+ /** Generate a source map. @default false */
18
+ sourceMap?: boolean;
19
+ /** Filename — used for source maps and error messages. */
20
+ filename?: string;
21
+ }
22
+ interface MinifyResult {
23
+ /** The minified code. */
24
+ code: string;
25
+ /** Source map JSON string. Only present when `sourceMap: true`. */
26
+ map: string | null;
27
+ }
28
+ interface MinifyResultWithMap {
29
+ code: string;
30
+ /** Source map JSON string. Guaranteed present. */
31
+ map: string;
32
+ }
33
+ interface MinifyResultWithoutMap {
34
+ code: string;
35
+ map: null;
36
+ }
37
+ /**
38
+ * Minify JavaScript or TypeScript.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { minifyJs } from '@crustkit/minify'
43
+ *
44
+ * // Zero config
45
+ * const { code } = minifyJs('var x = 1 + 2; console.log(x)')
46
+ *
47
+ * // With source map — `map` is guaranteed string
48
+ * const { code, map } = minifyJs(src, { sourceMap: true, filename: 'app.js' })
49
+ *
50
+ * // Disable mangling
51
+ * const { code } = minifyJs(src, { mangle: false })
52
+ * ```
53
+ */
54
+ declare function minifyJs(code: string, options: JsOptions & {
55
+ sourceMap: true;
56
+ }): MinifyResultWithMap;
57
+ declare function minifyJs(code: string, options?: JsOptions): MinifyResult;
58
+ /**
59
+ * Minify CSS. Handles vendor prefixing, nesting, and modern syntax automatically.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { minifyCss } from '@crustkit/minify'
64
+ *
65
+ * const { code } = minifyCss('.foo { color: red; margin: 0px; }')
66
+ * // '.foo{color:red;margin:0}'
67
+ *
68
+ * const { code, map } = minifyCss(src, { sourceMap: true })
69
+ * ```
70
+ */
71
+ declare function minifyCss(code: string, options: CssOptions & {
72
+ sourceMap: true;
73
+ }): MinifyResultWithMap;
74
+ declare function minifyCss(code: string, options?: CssOptions): MinifyResult;
75
+ type MinifyOptions = (JsOptions & {
76
+ language?: 'js';
77
+ }) | (CssOptions & {
78
+ language: 'css';
79
+ });
80
+ /**
81
+ * Minify code. Auto-detects language from `filename`, or set `language` explicitly.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import { minify } from '@crustkit/minify'
86
+ *
87
+ * // Auto-detect from filename
88
+ * minify('var x = 1', { filename: 'app.js' })
89
+ * minify('.foo { color: red }', { filename: 'style.css' })
90
+ *
91
+ * // Explicit language
92
+ * minify(code, { language: 'js' })
93
+ * minify(code, { language: 'css' })
94
+ *
95
+ * // Default: JS
96
+ * minify('var x = 1 + 2; console.log(x)')
97
+ * ```
98
+ */
99
+ declare function minify(code: string, options?: MinifyOptions): MinifyResult;
100
+ interface TerserCompressOptions {
101
+ /** Number of compression passes. @default 1 */
102
+ passes?: number;
103
+ /** Remove `debugger` statements. @default true */
104
+ drop_debugger?: boolean;
105
+ /** Remove `console.*` calls. @default false */
106
+ drop_console?: boolean;
107
+ /** Remove unreachable code. @default true */
108
+ dead_code?: boolean;
109
+ /** Join consecutive var/let/const statements. @default true */
110
+ join_vars?: boolean;
111
+ /** Allow other compress options terser accepts. */
112
+ [key: string]: unknown;
113
+ }
114
+ interface TerserMangleOptions {
115
+ /** Mangle top-level names. @default false */
116
+ toplevel?: boolean;
117
+ /** Names to keep unmangled. */
118
+ reserved?: string[];
119
+ /** Allow other mangle options terser accepts. */
120
+ [key: string]: unknown;
121
+ }
122
+ interface TerserSourceMapOptions {
123
+ /** Source map URL to embed in the output. */
124
+ url?: string;
125
+ /** Original filename for source map. */
126
+ filename?: string;
127
+ }
128
+ interface TerserOptions {
129
+ compress?: boolean | TerserCompressOptions;
130
+ mangle?: boolean | TerserMangleOptions;
131
+ sourceMap?: boolean | TerserSourceMapOptions;
132
+ module?: boolean;
133
+ toplevel?: boolean;
134
+ }
135
+ interface TerserResult {
136
+ code: string;
137
+ map?: string;
138
+ }
139
+ /**
140
+ * Terser-compatible drop-in replacement.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * // Before:
145
+ * import { minify } from 'terser'
146
+ *
147
+ * // After — just change the import:
148
+ * import { terser as minify } from '@crustkit/minify'
149
+ *
150
+ * const result = await minify(code, { compress: true, mangle: true })
151
+ * ```
152
+ *
153
+ * Returns a Promise for API compatibility. The work is synchronous in Rust.
154
+ */
155
+ declare function terser(code: string | Record<string, string>, options?: TerserOptions): Promise<TerserResult>;
156
+
157
+ export { type CssOptions, type JsOptions, type MinifyOptions, type MinifyResult, type MinifyResultWithMap, type MinifyResultWithoutMap, type TerserCompressOptions, type TerserMangleOptions, type TerserOptions, type TerserResult, type TerserSourceMapOptions, minify, minifyCss, minifyJs, terser };