@wasm-fmt/malva_fmt 0.1.17 → 0.2.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/README.md CHANGED
@@ -1,65 +1,71 @@
1
- # malva_fmt
1
+ [![Test](https://github.com/wasm-fmt/web_fmt/actions/workflows/test.yml/badge.svg)](https://github.com/wasm-fmt/web_fmt/actions/workflows/test.yml)
2
2
 
3
- CSS/SCSS/SASS/LESS formatter powered by WASM ported from [malva](https://github.com/g-plane/malva).
3
+ # Install
4
4
 
5
- ## Usage
5
+ [![npm](https://img.shields.io/npm/v/@wasm-fmt/malva_fmt)](https://www.npmjs.com/package/@wasm-fmt/malva_fmt)
6
6
 
7
- ### Node.js
8
-
9
- ```js
10
- import init from "malva_fmt";
7
+ ```bash
8
+ npm install @wasm-fmt/malva_fmt
9
+ ```
11
10
 
12
- const { format } = await init();
11
+ [![jsr.io](https://jsr.io/badges/@fmt/malva-fmt)](https://jsr.io/@fmt/malva-fmt)
13
12
 
14
- const result = format(
15
- ".foo {\n color: red;\n}",
16
- "style.css",
17
- {
18
- indentStyle: "space",
19
- indentWidth: 2,
20
- lineWidth: 80,
21
- lineEnding: "lf",
22
- }
23
- );
13
+ ```bash
14
+ npx jsr add @fmt/malva-fmt
24
15
  ```
25
16
 
26
- ### Vite
17
+ # Usage
18
+
19
+ ## Node.js / Deno / Bun / Bundler
27
20
 
28
- Add `"@wasm-fmt/malva-fmt"` to `optimizeDeps.exclude` in your vite config:
21
+ ```javascript
22
+ import { format } from "@wasm-fmt/malva_fmt";
29
23
 
30
- ```JSON
31
- {
32
- "optimizeDeps": {
33
- "exclude": ["@wasm-fmt/malva-fmt"]
34
- }
35
- }
24
+ const input = `.foo { color: red; }`;
25
+
26
+ const formatted = format(input, "style.css");
27
+ console.log(formatted);
36
28
  ```
37
29
 
38
- <details>
39
- <summary>
40
- If you cannot change the vite config, you can use another import entry
30
+ ## Web
31
+
32
+ For web environments, you need to initialize WASM module manually:
41
33
 
42
- </summary>
34
+ ```javascript
35
+ import init, { format } from "@wasm-fmt/malva_fmt/web";
43
36
 
44
- ```js
45
- import init from "@wasm-fmt/malva-fmt/vite";
37
+ await init();
46
38
 
47
- const { format } = await init();
39
+ const input = `.foo { color: red; }`;
48
40
 
49
- const result = format(
50
- ".foo {\n color: red;\n}",
51
- "style.css",
52
- {
53
- indentStyle: "space",
54
- indentWidth: 2,
55
- lineWidth: 80,
56
- lineEnding: "lf",
57
- }
58
- );
41
+ const formatted = format(input, "style.css");
42
+ console.log(formatted);
59
43
  ```
60
44
 
61
- </details>
45
+ ### Vite
62
46
 
63
- ## Configuration
47
+ ```JavaScript
48
+ import init, { format } from "@wasm-fmt/malva_fmt/vite";
49
+
50
+ await init();
51
+ // ...
52
+ ```
53
+
54
+ ## Entry Points
55
+
56
+ - `.` - Auto-detects environment (Node.js uses node, Webpack uses bundler, default is ESM)
57
+ - `./node` - Node.js environment (no init required)
58
+ - `./esm` - ESM environments like Deno (no init required)
59
+ - `./bundler` - Bundlers like Webpack (no init required)
60
+ - `./web` - Web browsers (requires manual init)
61
+ - `./vite` - Vite bundler (requires manual init)
62
+
63
+ # Configuration
64
64
 
65
65
  See [malva configuration docs](https://github.com/g-plane/malva/blob/main/docs/config.md) for all available options.
66
+
67
+ # Credits
68
+
69
+ Thanks to:
70
+
71
+ - The [malva](https://github.com/g-plane/malva) project
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Layout configuration options shared across all formatters.
3
+ */
4
+ export interface LayoutConfig {
5
+ /** Indentation style. Defaults to "space". */
6
+ indentStyle?: "tab" | "space";
7
+
8
+ /** Number of spaces per indentation level. Defaults to 2. */
9
+ indentWidth?: number;
10
+
11
+ /** Maximum line width before wrapping. Defaults to 80. */
12
+ lineWidth?: number;
13
+
14
+ /** Line ending style. Defaults to "lf". */
15
+ lineEnding?: "lf" | "crlf";
16
+ }
package/malva_fmt.d.ts CHANGED
@@ -1,54 +1,26 @@
1
+ /**
2
+ * WASM formatter for CSS/SCSS/SASS/LESS using malva.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { format } from "@wasm-fmt/malva_fmt";
7
+ *
8
+ * const input = ".class { color: red; }";
9
+ * const output = format(input, "style.css");
10
+ * ```
11
+ *
12
+ * @module
13
+ */
14
+
15
+ import type { Config } from "./options.d.ts";
16
+
1
17
  /* tslint:disable */
2
18
  /* eslint-disable */
3
19
 
4
- export interface Config extends LayoutConfig {
5
- /**
6
- * See {@link https://github.com/g-plane/malva/blob/main/docs/config.md}
7
- */
8
- [other: string]: any;
9
- }
10
-
11
-
12
- interface LayoutConfig {
13
- indentStyle?: "tab" | "space";
14
- indentWidth?: number;
15
- lineWidth?: number;
16
- lineEnding?: "lf" | "crlf";
17
- }
18
-
19
-
20
- export function format(src: string, filename: string, config?: Config | null): string;
21
-
22
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
23
-
24
- export interface InitOutput {
25
- readonly memory: WebAssembly.Memory;
26
- readonly format: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
27
- readonly __wbindgen_export: (a: number, b: number) => number;
28
- readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
29
- readonly __wbindgen_export3: (a: number) => void;
30
- readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
31
- readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
32
- }
33
-
34
- export type SyncInitInput = BufferSource | WebAssembly.Module;
35
-
36
20
  /**
37
- * Instantiates the given `module`, which can either be bytes or
38
- * a precompiled `WebAssembly.Module`.
39
- *
40
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
41
- *
42
- * @returns {InitOutput}
43
- */
44
- export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
45
-
46
- /**
47
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
48
- * for everything else, calls `WebAssembly.instantiate` directly.
49
- *
50
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
51
- *
52
- * @returns {Promise<InitOutput>}
53
- */
54
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
21
+ * Formats the given CSS/SCSS/Sass/Less code with the provided Configuration.
22
+ * @param src - The CSS/SCSS/Sass/Less code to format
23
+ * @param filename - The filename to determine the syntax (e.g., .css, .scss, .sass, .less)
24
+ * @param config - Optional formatter config
25
+ */
26
+ export function format(src: string, filename: string, config?: Config | null): string;