zig-pug 0.3.0 → 0.3.2

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 (47) hide show
  1. package/README.md +27 -0
  2. package/binding.gyp +16 -10
  3. package/index.mjs +192 -0
  4. package/package.json +12 -3
  5. package/prebuilts/darwin-arm64/libzig-pug.a +0 -0
  6. package/prebuilts/darwin-x64/libzig-pug.a +0 -0
  7. package/prebuilts/linux-arm64/libzig-pug.a +0 -0
  8. package/prebuilts/linux-x64/libzig-pug.a +0 -0
  9. package/prebuilts/win32-x64/zig-pug.lib +0 -0
  10. package/vendor/mujs/COPYING +0 -16
  11. package/vendor/mujs/README +0 -50
  12. package/vendor/mujs/astnames.h +0 -92
  13. package/vendor/mujs/jsarray.c +0 -832
  14. package/vendor/mujs/jsboolean.c +0 -38
  15. package/vendor/mujs/jsbuiltin.c +0 -249
  16. package/vendor/mujs/jscompile.c +0 -1428
  17. package/vendor/mujs/jsdate.c +0 -861
  18. package/vendor/mujs/jsdtoa.c +0 -749
  19. package/vendor/mujs/jserror.c +0 -139
  20. package/vendor/mujs/jsfunction.c +0 -231
  21. package/vendor/mujs/jsgc.c +0 -284
  22. package/vendor/mujs/jsi.h +0 -870
  23. package/vendor/mujs/jsintern.c +0 -137
  24. package/vendor/mujs/jslex.c +0 -878
  25. package/vendor/mujs/jsmath.c +0 -194
  26. package/vendor/mujs/jsnumber.c +0 -198
  27. package/vendor/mujs/jsobject.c +0 -560
  28. package/vendor/mujs/json.c +0 -422
  29. package/vendor/mujs/jsparse.c +0 -1065
  30. package/vendor/mujs/jsproperty.c +0 -341
  31. package/vendor/mujs/jsregexp.c +0 -232
  32. package/vendor/mujs/jsrepr.c +0 -285
  33. package/vendor/mujs/jsrun.c +0 -2096
  34. package/vendor/mujs/jsstate.c +0 -334
  35. package/vendor/mujs/jsstring.c +0 -852
  36. package/vendor/mujs/jsvalue.c +0 -708
  37. package/vendor/mujs/libmujs.a +0 -0
  38. package/vendor/mujs/main.c +0 -396
  39. package/vendor/mujs/mujs.h +0 -253
  40. package/vendor/mujs/one.c +0 -25
  41. package/vendor/mujs/opnames.h +0 -85
  42. package/vendor/mujs/pp.c +0 -980
  43. package/vendor/mujs/regexp.c +0 -1277
  44. package/vendor/mujs/regexp.h +0 -46
  45. package/vendor/mujs/utf.c +0 -305
  46. package/vendor/mujs/utf.h +0 -52
  47. package/vendor/mujs/utfdata.h +0 -2209
package/README.md CHANGED
@@ -13,6 +13,7 @@ High-performance Pug template engine powered by Zig and mujs.
13
13
  - ✅ **Documentation comments** - `//!` for file metadata (ignored by parser)
14
14
  - ✅ **Conditionals** - if/else/unless
15
15
  - ✅ **Mixins** - Reusable components
16
+ - ✅ **Dual package** - CommonJS (`require`) and ES Modules (`import`)
16
17
  - ✅ **Bun.js compatible** - 2-5x faster than Node.js
17
18
  - ⚡ **Native performance** - Written in Zig, compiled to native code
18
19
  - 🔋 **Zero dependencies** - Only Zig and embedded mujs
@@ -35,6 +36,7 @@ The addon will compile automatically during installation.
35
36
 
36
37
  ### Simple API
37
38
 
39
+ **CommonJS (Node.js):**
38
40
  ```javascript
39
41
  const zigpug = require('zig-pug');
40
42
 
@@ -43,8 +45,18 @@ console.log(html);
43
45
  // <p>Hello World!</p>
44
46
  ```
45
47
 
48
+ **ES Modules (Node.js, Bun):**
49
+ ```javascript
50
+ import { compile } from 'zig-pug';
51
+
52
+ const html = compile('p Hello #{name}!', { name: 'World' });
53
+ console.log(html);
54
+ // <p>Hello World!</p>
55
+ ```
56
+
46
57
  ### Object-Oriented API
47
58
 
59
+ **CommonJS (Node.js):**
48
60
  ```javascript
49
61
  const { PugCompiler } = require('zig-pug');
50
62
 
@@ -59,6 +71,21 @@ console.log(html);
59
71
  // <h1>My Page</h1>
60
72
  ```
61
73
 
74
+ **ES Modules (Node.js, Bun):**
75
+ ```javascript
76
+ import { PugCompiler } from 'zig-pug';
77
+
78
+ const compiler = new PugCompiler();
79
+ compiler
80
+ .set('title', 'My Page')
81
+ .set('version', 1.5)
82
+ .setBool('isDev', false);
83
+
84
+ const html = compiler.compile('h1 #{title}');
85
+ console.log(html);
86
+ // <h1>My Page</h1>
87
+ ```
88
+
62
89
  ### Express Integration
63
90
 
64
91
  ```javascript
package/binding.gyp CHANGED
@@ -3,19 +3,25 @@
3
3
  {
4
4
  "target_name": "zigpug",
5
5
  "sources": [
6
- "binding.c",
7
- "vendor/mujs/one.c"
6
+ "binding.c"
8
7
  ],
9
8
  "include_dirs": [
10
- "include",
11
- "vendor/mujs"
9
+ "include"
12
10
  ],
13
- "libraries": [
14
- "-lm"
15
- ],
16
- "cflags": [
17
- "-std=c99",
18
- "-DHAVE_STRLCPY=0"
11
+ "conditions": [
12
+ ["OS=='win'", {
13
+ "libraries": [
14
+ "<(module_root_dir)/prebuilts/win32-<(target_arch)/zig-pug.lib"
15
+ ]
16
+ }, {
17
+ "libraries": [
18
+ "-lm",
19
+ "<(module_root_dir)/prebuilts/<(OS)-<(target_arch)/libzig-pug.a"
20
+ ],
21
+ "cflags": [
22
+ "-std=c99"
23
+ ]
24
+ }]
19
25
  ],
20
26
  "defines": [
21
27
  "NAPI_VERSION=8"
package/index.mjs ADDED
@@ -0,0 +1,192 @@
1
+ /**
2
+ * zig-pug - Pug template engine for Node.js (ES Module version)
3
+ * Powered by Zig and mujs
4
+ */
5
+
6
+ import { createRequire } from 'module';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname } from 'path';
9
+ import { readFileSync } from 'fs';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = dirname(__filename);
13
+ const require = createRequire(import.meta.url);
14
+
15
+ const binding = require('./build/Release/zigpug.node');
16
+
17
+ /**
18
+ * PugCompiler class - High-level API for compiling Pug templates
19
+ */
20
+ export class PugCompiler {
21
+ constructor() {
22
+ this.context = binding.createContext();
23
+ if (!this.context) {
24
+ throw new Error('Failed to create zig-pug context');
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Set a string variable in the template context
30
+ * @param {string} key - Variable name
31
+ * @param {string} value - String value
32
+ * @returns {PugCompiler} - Returns this for chaining
33
+ */
34
+ setString(key, value) {
35
+ if (typeof key !== 'string') {
36
+ throw new TypeError('Key must be a string');
37
+ }
38
+ if (typeof value !== 'string') {
39
+ throw new TypeError('Value must be a string');
40
+ }
41
+
42
+ const success = binding.setString(this.context, key, value);
43
+ if (!success) {
44
+ throw new Error(`Failed to set string variable: ${key}`);
45
+ }
46
+ return this;
47
+ }
48
+
49
+ /**
50
+ * Set a number variable in the template context
51
+ * @param {string} key - Variable name
52
+ * @param {number} value - Number value
53
+ * @returns {PugCompiler} - Returns this for chaining
54
+ */
55
+ setNumber(key, value) {
56
+ if (typeof key !== 'string') {
57
+ throw new TypeError('Key must be a string');
58
+ }
59
+ if (typeof value !== 'number') {
60
+ throw new TypeError('Value must be a number');
61
+ }
62
+
63
+ const success = binding.setNumber(this.context, key, Math.floor(value));
64
+ if (!success) {
65
+ throw new Error(`Failed to set number variable: ${key}`);
66
+ }
67
+ return this;
68
+ }
69
+
70
+ /**
71
+ * Set a boolean variable in the template context
72
+ * @param {string} key - Variable name
73
+ * @param {boolean} value - Boolean value
74
+ * @returns {PugCompiler} - Returns this for chaining
75
+ */
76
+ setBool(key, value) {
77
+ if (typeof key !== 'string') {
78
+ throw new TypeError('Key must be a string');
79
+ }
80
+ if (typeof value !== 'boolean') {
81
+ throw new TypeError('Value must be a boolean');
82
+ }
83
+
84
+ const success = binding.setBool(this.context, key, value);
85
+ if (!success) {
86
+ throw new Error(`Failed to set boolean variable: ${key}`);
87
+ }
88
+ return this;
89
+ }
90
+
91
+ /**
92
+ * Set a variable (automatically detects type)
93
+ * @param {string} key - Variable name
94
+ * @param {string|number|boolean} value - Value of any supported type
95
+ * @returns {PugCompiler} - Returns this for chaining
96
+ */
97
+ set(key, value) {
98
+ if (typeof value === 'string') {
99
+ return this.setString(key, value);
100
+ } else if (typeof value === 'number') {
101
+ return this.setNumber(key, value);
102
+ } else if (typeof value === 'boolean') {
103
+ return this.setBool(key, value);
104
+ } else {
105
+ throw new TypeError(`Unsupported value type for key "${key}": ${typeof value}`);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Set multiple variables from an object
111
+ * @param {Object} variables - Object with key-value pairs
112
+ * @returns {PugCompiler} - Returns this for chaining
113
+ */
114
+ setVariables(variables) {
115
+ if (typeof variables !== 'object' || variables === null) {
116
+ throw new TypeError('Variables must be an object');
117
+ }
118
+
119
+ for (const [key, value] of Object.entries(variables)) {
120
+ this.set(key, value);
121
+ }
122
+
123
+ return this;
124
+ }
125
+
126
+ /**
127
+ * Compile a Pug template to HTML
128
+ * @param {string} template - Pug template string
129
+ * @returns {string} - Compiled HTML
130
+ */
131
+ compile(template) {
132
+ if (typeof template !== 'string') {
133
+ throw new TypeError('Template must be a string');
134
+ }
135
+
136
+ const html = binding.compile(this.context, template);
137
+ if (!html) {
138
+ throw new Error('Failed to compile template');
139
+ }
140
+
141
+ return html;
142
+ }
143
+
144
+ /**
145
+ * Compile a template with variables in one call
146
+ * @param {string} template - Pug template string
147
+ * @param {Object} variables - Variables to set before compiling
148
+ * @returns {string} - Compiled HTML
149
+ */
150
+ render(template, variables = {}) {
151
+ this.setVariables(variables);
152
+ return this.compile(template);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Convenience function to compile a template with variables
158
+ * @param {string} template - Pug template string
159
+ * @param {Object} variables - Variables for the template
160
+ * @returns {string} - Compiled HTML
161
+ */
162
+ export function compile(template, variables = {}) {
163
+ const compiler = new PugCompiler();
164
+ return compiler.render(template, variables);
165
+ }
166
+
167
+ /**
168
+ * Convenience function to compile a template from a file
169
+ * @param {string} filename - Path to the Pug template file
170
+ * @param {Object} variables - Variables for the template
171
+ * @returns {string} - Compiled HTML
172
+ */
173
+ export function compileFile(filename, variables = {}) {
174
+ const template = readFileSync(filename, 'utf8');
175
+ return compile(template, variables);
176
+ }
177
+
178
+ /**
179
+ * Get the zig-pug version
180
+ * @returns {string} - Version string
181
+ */
182
+ export function version() {
183
+ return binding.version();
184
+ }
185
+
186
+ // Default export for compatibility
187
+ export default {
188
+ PugCompiler,
189
+ compile,
190
+ compileFile,
191
+ version
192
+ };
package/package.json CHANGED
@@ -1,15 +1,23 @@
1
1
  {
2
2
  "name": "zig-pug",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "High-performance Pug template engine powered by Zig and mujs. Native N-API addon with ES5.1 JavaScript support, full UTF-8 (emoji, accents), documentation comments (//!), and fast compilation. Compatible with Node.js and Bun.",
5
+ "type": "commonjs",
5
6
  "main": "index.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./index.mjs",
10
+ "require": "./index.js"
11
+ }
12
+ },
6
13
  "scripts": {
7
14
  "install": "node-gyp rebuild",
8
15
  "build": "node-gyp configure build",
9
16
  "rebuild": "node-gyp rebuild",
10
17
  "clean": "node-gyp clean",
11
18
  "test": "node test/test.js",
12
- "prepublishOnly": "npm run build"
19
+ "build-prebuilts": "./build-prebuilts.sh",
20
+ "prepublishOnly": "npm run build-prebuilts"
13
21
  },
14
22
  "keywords": [
15
23
  "pug",
@@ -76,12 +84,13 @@
76
84
  },
77
85
  "files": [
78
86
  "index.js",
87
+ "index.mjs",
79
88
  "binding.c",
80
89
  "binding.gyp",
81
90
  "common.gypi",
82
91
  "README.md",
83
92
  "LICENSE",
84
93
  "include/",
85
- "vendor/"
94
+ "prebuilts/"
86
95
  ]
87
96
  }
Binary file
Binary file
@@ -1,16 +0,0 @@
1
- ISC License
2
-
3
- Copyright (c) 2013-2020 Artifex Software, Inc.
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted, provided that the above
7
- copyright notice and this permission notice appear in all copies.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14
- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
16
-
@@ -1,50 +0,0 @@
1
- MuJS: an embeddable Javascript interpreter in C.
2
-
3
- ABOUT
4
-
5
- MuJS is a lightweight Javascript interpreter designed for embedding in
6
- other software to extend them with scripting capabilities.
7
-
8
- LICENSE
9
-
10
- MuJS is Copyright 2013-2017 Artifex Software, Inc.
11
-
12
- Permission to use, copy, modify, and/or distribute this software for any
13
- purpose with or without fee is hereby granted, provided that the above
14
- copyright notice and this permission notice appear in all copies.
15
-
16
- The software is provided "as is" and the author disclaims all warranties with
17
- regard to this software including all implied warranties of merchantability
18
- and fitness. In no event shall the author be liable for any special, direct,
19
- indirect, or consequential damages or any damages whatsoever resulting from
20
- loss of use, data or profits, whether in an action of contract, negligence
21
- or other tortious action, arising out of or in connection with the use or
22
- performance of this software.
23
-
24
- COMPILING
25
-
26
- If you are building from source you can either use the provided Unix Makefile:
27
-
28
- make release
29
-
30
- Or compile the source with your preferred compiler:
31
-
32
- cc -O2 -c one.c -o libmujs.o
33
-
34
- INSTALLING
35
-
36
- To install the MuJS command line interpreter, static library and header file:
37
-
38
- make prefix=/usr/local install
39
-
40
- DOWNLOAD
41
-
42
- The latest development source is available directly from the git repository:
43
-
44
- git clone http://git.ghostscript.com/mujs.git
45
-
46
- REPORTING BUGS AND PROBLEMS
47
-
48
- Report bugs on the ghostscript bugzilla, with MuJS as the selected component.
49
-
50
- http://bugs.ghostscript.com/
@@ -1,92 +0,0 @@
1
- "list",
2
- "fundec",
3
- "identifier",
4
- "exp_identifier",
5
- "exp_number",
6
- "exp_string",
7
- "exp_regexp",
8
- "exp_elision",
9
- "exp_null",
10
- "exp_true",
11
- "exp_false",
12
- "exp_this",
13
- "exp_array",
14
- "exp_object",
15
- "exp_prop_val",
16
- "exp_prop_get",
17
- "exp_prop_set",
18
- "exp_fun",
19
- "exp_index",
20
- "exp_member",
21
- "exp_call",
22
- "exp_new",
23
- "exp_postinc",
24
- "exp_postdec",
25
- "exp_delete",
26
- "exp_void",
27
- "exp_typeof",
28
- "exp_preinc",
29
- "exp_predec",
30
- "exp_pos",
31
- "exp_neg",
32
- "exp_bitnot",
33
- "exp_lognot",
34
- "exp_mod",
35
- "exp_div",
36
- "exp_mul",
37
- "exp_sub",
38
- "exp_add",
39
- "exp_ushr",
40
- "exp_shr",
41
- "exp_shl",
42
- "exp_in",
43
- "exp_instanceof",
44
- "exp_ge",
45
- "exp_le",
46
- "exp_gt",
47
- "exp_lt",
48
- "exp_strictne",
49
- "exp_stricteq",
50
- "exp_ne",
51
- "exp_eq",
52
- "exp_bitand",
53
- "exp_bitxor",
54
- "exp_bitor",
55
- "exp_logand",
56
- "exp_logor",
57
- "exp_cond",
58
- "exp_ass",
59
- "exp_ass_mul",
60
- "exp_ass_div",
61
- "exp_ass_mod",
62
- "exp_ass_add",
63
- "exp_ass_sub",
64
- "exp_ass_shl",
65
- "exp_ass_shr",
66
- "exp_ass_ushr",
67
- "exp_ass_bitand",
68
- "exp_ass_bitxor",
69
- "exp_ass_bitor",
70
- "exp_comma",
71
- "exp_var",
72
- "stm_block",
73
- "stm_empty",
74
- "stm_var",
75
- "stm_if",
76
- "stm_do",
77
- "stm_while",
78
- "stm_for",
79
- "stm_for_var",
80
- "stm_for_in",
81
- "stm_for_in_var",
82
- "stm_continue",
83
- "stm_break",
84
- "stm_return",
85
- "stm_with",
86
- "stm_switch",
87
- "stm_throw",
88
- "stm_try",
89
- "stm_debugger",
90
- "stm_label",
91
- "stm_case",
92
- "stm_default",