htmlemmurt 0.3.0 → 0.5.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
@@ -19,6 +19,8 @@ const { html, dependencies, errors } = compile('<cascett classe="a">Uè</cascett
19
19
 
20
20
  `compile` non lancia mai eccezioni: gli errori stanno in `errors`, con `message`, `file`, `line`, `column` e `suggestion`, in napoletano. Le opzioni sono `filename`, `root` (la cartella per i percorsi che cominciano con `/`), `read` (per leggere i file in un altro modo) e `inline` (incolla nella pagina i file di `<fratm da>`). I moduli `.fratm` li compila il pacchetto [`fratmscript`](https://www.npmjs.com/package/fratmscript).
21
21
 
22
+ `format(source)` restituisce la pagina come la scrive `emmurt fmt`, cambiando solo spazi e a capo, oppure `null` se la pagina ha errori (li dice `compile`).
23
+
22
24
  ## Con Vite
23
25
 
24
26
  ```js
package/index.d.ts CHANGED
@@ -48,6 +48,11 @@ export interface Vocabulary {
48
48
 
49
49
  /** Compiles htmlemmurt to HTML. Never throws on invalid source: check `errors`. */
50
50
  export function compile(source: string, options?: CompileOptions): CompileResult;
51
+ /**
52
+ * The page as `emmurt fmt` writes it: only spaces and line breaks change.
53
+ * Null when it has errors, which `compile` reports.
54
+ */
55
+ export function format(source: string): string | null;
51
56
  /** Every Neapolitan name and its HTML. */
52
57
  export function vocabulary(): Vocabulary;
53
58
  /** Version of the compiler. */
package/index.js CHANGED
@@ -7,7 +7,7 @@ import { createApi } from './lib/api.js';
7
7
  const wasm = createRequire(import.meta.url)('./wasm/node/emmurt_wasm.js');
8
8
  const api = createApi(wasm);
9
9
 
10
- export const { vocabulary, version, runtimeError } = api;
10
+ export const { format, vocabulary, version, runtimeError } = api;
11
11
  export { formatError } from './lib/api.js';
12
12
 
13
13
  /**
package/lib/api.js CHANGED
@@ -9,6 +9,11 @@ export function createApi(wasm) {
9
9
  return { html: response.html, dependencies: response.dependencies, errors: response.errors };
10
10
  }
11
11
 
12
+ // Undefined from the bindings when the page cannot be formatted
13
+ function format(source) {
14
+ return wasm.format(String(source)) ?? null;
15
+ }
16
+
12
17
  function vocabulary() {
13
18
  return JSON.parse(wasm.vocabulary());
14
19
  }
@@ -19,7 +24,7 @@ export function createApi(wasm) {
19
24
  return wasm.runtimeError(name, message);
20
25
  }
21
26
 
22
- return { compile, vocabulary, version: wasm.version, runtimeError };
27
+ return { compile, format, vocabulary, version: wasm.version, runtimeError };
23
28
  }
24
29
 
25
30
  /** `file:line:column: message`, then the hint on its own line. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "htmlemmurt",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "htmlemmurt compiler (WebAssembly), Vite plugin and browser runtime: HTML, ma comme si deve 🤌",
5
5
  "license": "MIT",
6
6
  "author": "Vito Esposito",
@@ -20,6 +20,25 @@ function compile(source, filename, read, inline) {
20
20
  }
21
21
  exports.compile = compile;
22
22
 
23
+ /**
24
+ * The formatted page, or undefined when it cannot be formatted: then
25
+ * `compile` says why.
26
+ * @param {string} source
27
+ * @returns {string | undefined}
28
+ */
29
+ function format(source) {
30
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
31
+ const len0 = WASM_VECTOR_LEN;
32
+ const ret = wasm.format(ptr0, len0);
33
+ let v2;
34
+ if (ret[0] !== 0) {
35
+ v2 = getStringFromWasm0(ret[0], ret[1]);
36
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
37
+ }
38
+ return v2;
39
+ }
40
+ exports.format = format;
41
+
23
42
  /**
24
43
  * A JavaScript runtime error in Neapolitan, as FratmScript says it.
25
44
  * @param {string} name
Binary file
@@ -19,6 +19,24 @@ export function compile(source, filename, read, inline) {
19
19
  return ret;
20
20
  }
21
21
 
22
+ /**
23
+ * The formatted page, or undefined when it cannot be formatted: then
24
+ * `compile` says why.
25
+ * @param {string} source
26
+ * @returns {string | undefined}
27
+ */
28
+ export function format(source) {
29
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
30
+ const len0 = WASM_VECTOR_LEN;
31
+ const ret = wasm.format(ptr0, len0);
32
+ let v2;
33
+ if (ret[0] !== 0) {
34
+ v2 = getStringFromWasm0(ret[0], ret[1]);
35
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
36
+ }
37
+ return v2;
38
+ }
39
+
22
40
  /**
23
41
  * A JavaScript runtime error in Neapolitan, as FratmScript says it.
24
42
  * @param {string} name
Binary file
package/web.d.ts CHANGED
@@ -5,6 +5,8 @@ import type { CompileOptions, CompileResult, Vocabulary, EmmurtError } from './i
5
5
  export function init(input?: string | URL | Request | Response | BufferSource | WebAssembly.Module): Promise<void>;
6
6
  /** Compiles htmlemmurt to HTML. Without `read`, includes cannot be resolved. */
7
7
  export function compile(source: string, options?: Omit<CompileOptions, 'root'>): CompileResult;
8
+ /** The page as `emmurt fmt` writes it, or null when it has errors: `compile` says which. */
9
+ export function format(source: string): string | null;
8
10
  export function vocabulary(): Vocabulary;
9
11
  export function version(): string;
10
12
  export function runtimeError(error: unknown): string;
package/web.js CHANGED
@@ -19,6 +19,7 @@ function loadedApi() {
19
19
  }
20
20
 
21
21
  export const compile = (source, options) => loadedApi().compile(source, options);
22
+ export const format = (source) => loadedApi().format(source);
22
23
  export const vocabulary = () => loadedApi().vocabulary();
23
24
  export const version = () => loadedApi().version();
24
25
  export const runtimeError = (error) => loadedApi().runtimeError(error);