@zipadee/javascript 0.0.19 → 0.0.21

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/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './lib/serve.js';
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './lib/serve.js';
2
- //# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
1
  export {};
2
- //# sourceMappingURL=attributes.d.ts.map
2
+ //# sourceMappingURL=attributes.d.ts.map
package/lib/attributes.js CHANGED
@@ -11,150 +11,152 @@
11
11
  * @internal
12
12
  */
13
13
  export const parseImportAttributes = (expr) => new Parser(expr).parse();
14
- const isWhitespace = (ch) =>
15
- ch === 9 /* \t */ ||
16
- ch === 10 /* \n */ ||
17
- ch === 13 /* \r */ ||
18
- ch === 32; /* space */
14
+ const isWhitespace = (ch) => ch === 9 /* \t */ ||
15
+ ch === 10 /* \n */ ||
16
+ ch === 13 /* \r */ ||
17
+ ch === 32; /* space */
19
18
  // TODO(justinfagnani): allow code points > 127
20
- const isIdentStart = (ch) =>
21
- ch === 95 /* _ */ ||
22
- ch === 36 /* $ */ ||
23
- // ch &= ~32 puts ch into the range [65,90] [A-Z] only if ch was already in
24
- // the that range or in the range [97,122] [a-z]. We must mutate ch only after
25
- // checking other characters, thus the comma operator.
26
- ((ch &= ~32), 65 /* A */ <= ch && ch <= 90); /* Z */
19
+ const isIdentStart = (ch) => ch === 95 /* _ */ ||
20
+ ch === 36 /* $ */ ||
21
+ // ch &= ~32 puts ch into the range [65,90] [A-Z] only if ch was already in
22
+ // the that range or in the range [97,122] [a-z]. We must mutate ch only after
23
+ // checking other characters, thus the comma operator.
24
+ ((ch &= ~32), 65 /* A */ <= ch && ch <= 90); /* Z */
27
25
  // TODO(justinfagnani): allow code points > 127
28
26
  const isIdentifier = (ch) => isIdentStart(ch);
29
27
  const isQuote = (ch) => ch === 34 /* " */ || ch === 39; /* ' */
30
- const escapeString = (str) =>
31
- str.replace(/\\(.)/g, (_match, group) => {
28
+ const escapeString = (str) => str.replace(/\\(.)/g, (_match, group) => {
32
29
  switch (group) {
33
- case 'n':
34
- return '\n';
35
- case 'r':
36
- return '\r';
37
- case 't':
38
- return '\t';
39
- case 'b':
40
- return '\b';
41
- case 'f':
42
- return '\f';
43
- default:
44
- return group;
30
+ case 'n':
31
+ return '\n';
32
+ case 'r':
33
+ return '\r';
34
+ case 't':
35
+ return '\t';
36
+ case 'b':
37
+ return '\b';
38
+ case 'f':
39
+ return '\f';
40
+ default:
41
+ return group;
45
42
  }
46
- });
43
+ });
47
44
  class Parser {
48
- #input;
49
- #index = -1;
50
- #tokenStart = 0;
51
- #next;
52
- constructor(input) {
53
- this.#input = input;
54
- this.#advance();
55
- }
56
- parse() {
57
- this.#parseMapStart();
58
- const entries = new Map();
59
- do {
60
- this.#advanceWhitespace();
61
- if (this.#next === 125 /* } */) {
62
- break; // end of map
63
- }
64
- const key = this.#parseKey();
65
- this.#parseColon();
66
- const value = this.#parseString();
67
- entries.set(key, value);
68
- } while (this.#parseCommaOrMapEnd());
69
- return entries;
70
- }
71
- #advance(resetTokenStart) {
72
- this.#index++;
73
- if (this.#index < this.#input.length) {
74
- this.#next = this.#input.charCodeAt(this.#index);
75
- if (resetTokenStart === true) {
76
- this.#tokenStart = this.#index;
77
- }
78
- } else {
79
- this.#next = undefined;
45
+ #input;
46
+ #index = -1;
47
+ #tokenStart = 0;
48
+ #next;
49
+ constructor(input) {
50
+ this.#input = input;
51
+ this.#advance();
80
52
  }
81
- }
82
- #advanceWhitespace() {
83
- const l = this.#input.length;
84
- let index = this.#index;
85
- let char = this.#next;
86
- while (index < l && isWhitespace(char)) {
87
- char = this.#input.charCodeAt(++index);
53
+ parse() {
54
+ this.#parseMapStart();
55
+ const entries = new Map();
56
+ do {
57
+ this.#advanceWhitespace();
58
+ if (this.#next === 125 /* } */) {
59
+ break; // end of map
60
+ }
61
+ const key = this.#parseKey();
62
+ this.#parseColon();
63
+ const value = this.#parseString();
64
+ entries.set(key, value);
65
+ } while (this.#parseCommaOrMapEnd());
66
+ return entries;
88
67
  }
89
- this.#tokenStart = this.#index = index;
90
- this.#next = char;
91
- }
92
- #getValue() {
93
- const v = this.#input.substring(this.#tokenStart, this.#index);
94
- this.#tokenStart = this.#index;
95
- return v;
96
- }
97
- #parseColon() {
98
- this.#advanceWhitespace();
99
- if (this.#next === 58 /* : */) {
100
- this.#advance();
101
- } else {
102
- throw new Error(`Expected :, got ${this.#next}`);
68
+ #advance(resetTokenStart) {
69
+ this.#index++;
70
+ if (this.#index < this.#input.length) {
71
+ this.#next = this.#input.charCodeAt(this.#index);
72
+ if (resetTokenStart === true) {
73
+ this.#tokenStart = this.#index;
74
+ }
75
+ }
76
+ else {
77
+ this.#next = undefined;
78
+ }
103
79
  }
104
- }
105
- #parseString() {
106
- this.#advanceWhitespace();
107
- const quoteChar = this.#next;
108
- this.#advance(true);
109
- while (this.#next !== quoteChar) {
110
- if (this.#next === undefined) {
111
- throw new Error('unterminated string');
112
- }
113
- // @ts-ignore
114
- if (this.#next === 92 /* \ */) {
115
- this.#advance();
116
- if (this.#next === undefined) {
117
- throw new Error('unterminated string');
80
+ #advanceWhitespace() {
81
+ const l = this.#input.length;
82
+ let index = this.#index;
83
+ let char = this.#next;
84
+ while (index < l && isWhitespace(char)) {
85
+ char = this.#input.charCodeAt(++index);
86
+ }
87
+ this.#tokenStart = this.#index = index;
88
+ this.#next = char;
89
+ }
90
+ #getValue() {
91
+ const v = this.#input.substring(this.#tokenStart, this.#index);
92
+ this.#tokenStart = this.#index;
93
+ return v;
94
+ }
95
+ #parseColon() {
96
+ this.#advanceWhitespace();
97
+ if (this.#next === 58 /* : */) {
98
+ this.#advance();
99
+ }
100
+ else {
101
+ throw new Error(`Expected :, got ${this.#next}`);
118
102
  }
119
- }
120
- this.#advance();
121
103
  }
122
- const value = escapeString(this.#getValue());
123
- this.#advance();
124
- return value;
125
- }
126
- #parseKey() {
127
- this.#advanceWhitespace();
128
- if (isQuote(this.#next)) {
129
- return this.#parseString();
130
- } else if (isIdentStart(this.#next)) {
131
- do {
104
+ #parseString() {
105
+ this.#advanceWhitespace();
106
+ const quoteChar = this.#next;
107
+ this.#advance(true);
108
+ while (this.#next !== quoteChar) {
109
+ if (this.#next === undefined) {
110
+ throw new Error('unterminated string');
111
+ }
112
+ // @ts-ignore
113
+ if (this.#next === 92 /* \ */) {
114
+ this.#advance();
115
+ if (this.#next === undefined) {
116
+ throw new Error('unterminated string');
117
+ }
118
+ }
119
+ this.#advance();
120
+ }
121
+ const value = escapeString(this.#getValue());
132
122
  this.#advance();
133
- } while (isIdentifier(this.#next));
134
- return this.#getValue();
135
- } else {
136
- throw new Error(`expected string or identifier, got ${this.#next}`);
123
+ return value;
137
124
  }
138
- }
139
- #parseMapStart() {
140
- this.#advanceWhitespace();
141
- if (this.#next === 123 /* { */) {
142
- this.#advance(true);
143
- } else {
144
- throw new Error(`expected {, got ${this.#next}`);
125
+ #parseKey() {
126
+ this.#advanceWhitespace();
127
+ if (isQuote(this.#next)) {
128
+ return this.#parseString();
129
+ }
130
+ else if (isIdentStart(this.#next)) {
131
+ do {
132
+ this.#advance();
133
+ } while (isIdentifier(this.#next));
134
+ return this.#getValue();
135
+ }
136
+ else {
137
+ throw new Error(`expected string or identifier, got ${this.#next}`);
138
+ }
145
139
  }
146
- }
147
- #parseCommaOrMapEnd() {
148
- this.#advanceWhitespace();
149
- if (this.#next === 125 /* } */) {
150
- this.#advance();
151
- return false;
140
+ #parseMapStart() {
141
+ this.#advanceWhitespace();
142
+ if (this.#next === 123 /* { */) {
143
+ this.#advance(true);
144
+ }
145
+ else {
146
+ throw new Error(`expected {, got ${this.#next}`);
147
+ }
152
148
  }
153
- if (this.#next === 44 /* , */) {
154
- this.#advance();
155
- return true;
149
+ #parseCommaOrMapEnd() {
150
+ this.#advanceWhitespace();
151
+ if (this.#next === 125 /* } */) {
152
+ this.#advance();
153
+ return false;
154
+ }
155
+ if (this.#next === 44 /* , */) {
156
+ this.#advance();
157
+ return true;
158
+ }
159
+ throw new Error(`expected }, got ${this.#next}`);
156
160
  }
157
- throw new Error(`expected }, got ${this.#next}`);
158
- }
159
161
  }
160
- //# sourceMappingURL=attributes.js.map
162
+ //# sourceMappingURL=attributes.js.map
package/lib/serve.d.ts CHANGED
@@ -1,38 +1,38 @@
1
- import {type Middleware} from '@zipadee/core';
1
+ import { type Middleware } from '@zipadee/core';
2
2
  export interface Options {
3
- /**
4
- * Root directory to restrict file access. Defaults to the current working
5
- * directory.
6
- */
7
- root?: string;
8
- /**
9
- * Base path to resolve imports from. Defaults to the current working
10
- * directory.
11
- */
12
- base?: string;
13
- /**
14
- * Imports resolved to outside of the base path will be prefixed with this
15
- * string. Defaults to `/__root__`.
16
- */
17
- rootPathPrefix?: string;
18
- /**
19
- * Array of file extensions to transform. Defaults to `['.js', '.mjs']`.
20
- *
21
- * Other extensions are served as plain files.
22
- */
23
- extensions?: Array<string>;
24
- /**
25
- * Array of import conditions to support. Defaults to `['browser', 'import']`.
26
- */
27
- conditions?: Array<string>;
28
- /**
29
- * If true, will transform CSS modules and imports with the `type: 'css'`
30
- * attribute.
31
- */
32
- cssModules?: boolean;
3
+ /**
4
+ * Root directory to restrict file access. Defaults to the current working
5
+ * directory.
6
+ */
7
+ root?: string;
8
+ /**
9
+ * Base path to resolve imports from. Defaults to the current working
10
+ * directory.
11
+ */
12
+ base?: string;
13
+ /**
14
+ * Imports resolved to outside of the base path will be prefixed with this
15
+ * string. Defaults to `/__root__`.
16
+ */
17
+ rootPathPrefix?: string;
18
+ /**
19
+ * Array of file extensions to transform. Defaults to `['.js', '.mjs']`.
20
+ *
21
+ * Other extensions are served as plain files.
22
+ */
23
+ extensions?: Array<string>;
24
+ /**
25
+ * Array of import conditions to support. Defaults to `['browser', 'import']`.
26
+ */
27
+ conditions?: Array<string>;
28
+ /**
29
+ * If true, will transform CSS modules and imports with the `type: 'css'`
30
+ * attribute.
31
+ */
32
+ cssModules?: boolean;
33
33
  }
34
34
  /**
35
35
  * Serve static JavaScript files from a `root` directory.
36
36
  */
37
37
  export declare const serve: (opts: Options) => Middleware;
38
- //# sourceMappingURL=serve.d.ts.map
38
+ //# sourceMappingURL=serve.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zipadee/javascript",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -57,8 +57,8 @@
57
57
  }
58
58
  },
59
59
  "dependencies": {
60
- "@zipadee/core": "0.0.19",
61
- "@zipadee/static": "0.0.19",
60
+ "@zipadee/core": "^0.0.21",
61
+ "@zipadee/static": "^0.0.21",
62
62
  "dedent": "^1.6.0",
63
63
  "enhanced-resolve": "^5.17.1",
64
64
  "es-module-lexer": "^1.5.4"