@wasm-fmt/graphql_fmt 0.0.0 → 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
- # graphql_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
- GraphQL formatter powered by WASM ported from [pretty_graphql](https://github.com/g-plane/pretty_graphql).
3
+ # Install
4
4
 
5
- ## Usage
5
+ [![npm](https://img.shields.io/npm/v/@wasm-fmt/graphql_fmt)](https://www.npmjs.com/package/@wasm-fmt/graphql_fmt)
6
6
 
7
- ### Node.js
8
-
9
- ```js
10
- import init from "graphql_fmt";
7
+ ```bash
8
+ npm install @wasm-fmt/graphql_fmt
9
+ ```
11
10
 
12
- const { format } = await init();
11
+ [![jsr.io](https://jsr.io/badges/@fmt/graphql-fmt)](https://jsr.io/@fmt/graphql-fmt)
13
12
 
14
- const result = format(
15
- "query { user { name } }",
16
- "query.graphql",
17
- {
18
- indentStyle: "space",
19
- indentWidth: 2,
20
- lineWidth: 80,
21
- lineEnding: "lf",
22
- }
23
- );
13
+ ```bash
14
+ npx jsr add @fmt/graphql-fmt
24
15
  ```
25
16
 
26
- ### Vite
17
+ # Usage
18
+
19
+ ## Node.js / Deno / Bun / Bundler
27
20
 
28
- Add `"@wasm-fmt/graphql-fmt"` to `optimizeDeps.exclude` in your vite config:
21
+ ```javascript
22
+ import { format } from "@wasm-fmt/graphql_fmt";
29
23
 
30
- ```JSON
31
- {
32
- "optimizeDeps": {
33
- "exclude": ["@wasm-fmt/graphql-fmt"]
34
- }
35
- }
24
+ const input = `query { user { name } }`;
25
+
26
+ const formatted = format(input);
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/graphql_fmt/web";
43
36
 
44
- ```js
45
- import init from "@wasm-fmt/graphql-fmt/vite";
37
+ await init();
46
38
 
47
- const { format } = await init();
39
+ const input = `query { user { name } }`;
48
40
 
49
- const result = format(
50
- "query { user { name } }",
51
- "query.graphql",
52
- {
53
- indentStyle: "space",
54
- indentWidth: 2,
55
- lineWidth: 80,
56
- lineEnding: "lf",
57
- }
58
- );
41
+ const formatted = format(input);
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/graphql_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 [pretty_graphql configuration docs](https://pretty-graphql.netlify.app/) for all available options.
66
+
67
+ # Credits
68
+
69
+ Thanks to:
70
+
71
+ - The [pretty_graphql](https://github.com/g-plane/pretty_graphql) project
package/graphql_fmt.d.ts CHANGED
@@ -1,54 +1,25 @@
1
+ /**
2
+ * WASM formatter for GraphQL using pretty_graphql.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { format } from "@wasm-fmt/graphql_fmt";
7
+ *
8
+ * const input = "{ hello }";
9
+ * const output = format(input);
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://pretty-graphql.netlify.app/}
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
- /**
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
20
  /**
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 GraphQL code with the provided Configuration.
22
+ * @param src - The GraphQL code to format
23
+ * @param config - Optional formatter config
24
+ */
25
+ export function format(src: string, config?: Config | null): string;