@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 +1 -1
- package/index.js +1 -1
- package/lib/attributes.d.ts +1 -1
- package/lib/attributes.js +131 -129
- package/lib/serve.d.ts +32 -32
- package/package.json +3 -3
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
|
package/lib/attributes.d.ts
CHANGED
|
@@ -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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.#
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
134
|
-
return this.#getValue();
|
|
135
|
-
} else {
|
|
136
|
-
throw new Error(`expected string or identifier, got ${this.#next}`);
|
|
123
|
+
return value;
|
|
137
124
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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.
|
|
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.
|
|
61
|
-
"@zipadee/static": "0.0.
|
|
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"
|