arri 0.0.1 → 0.0.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.
@@ -0,0 +1,181 @@
1
+ const PLUS_RE = /\+/g;
2
+ function decode(text = "") {
3
+ try {
4
+ return decodeURIComponent("" + text);
5
+ } catch {
6
+ return "" + text;
7
+ }
8
+ }
9
+ function decodeQueryValue(text) {
10
+ return decode(text.replace(PLUS_RE, " "));
11
+ }
12
+
13
+ function parseQuery(parametersString = "") {
14
+ const object = {};
15
+ if (parametersString[0] === "?") {
16
+ parametersString = parametersString.slice(1);
17
+ }
18
+ for (const parameter of parametersString.split("&")) {
19
+ const s = parameter.match(/([^=]+)=?(.*)/) || [];
20
+ if (s.length < 2) {
21
+ continue;
22
+ }
23
+ const key = decode(s[1]);
24
+ if (key === "__proto__" || key === "constructor") {
25
+ continue;
26
+ }
27
+ const value = decodeQueryValue(s[2] || "");
28
+ if (typeof object[key] !== "undefined") {
29
+ if (Array.isArray(object[key])) {
30
+ object[key].push(value);
31
+ } else {
32
+ object[key] = [object[key], value];
33
+ }
34
+ } else {
35
+ object[key] = value;
36
+ }
37
+ }
38
+ return object;
39
+ }
40
+ const PROTOCOL_STRICT_REGEX = /^\w{2,}:([/\\]{1,2})/;
41
+ const PROTOCOL_REGEX = /^\w{2,}:([/\\]{2})?/;
42
+ const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
43
+ function hasProtocol(inputString, opts = {}) {
44
+ if (typeof opts === "boolean") {
45
+ opts = { acceptRelative: opts };
46
+ }
47
+ if (opts.strict) {
48
+ return PROTOCOL_STRICT_REGEX.test(inputString);
49
+ }
50
+ return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
51
+ }
52
+ const TRAILING_SLASH_RE = /\/$|\/\?/;
53
+ function hasTrailingSlash(input = "", queryParameters = false) {
54
+ if (!queryParameters) {
55
+ return input.endsWith("/");
56
+ }
57
+ return TRAILING_SLASH_RE.test(input);
58
+ }
59
+ function withTrailingSlash(input = "", queryParameters = false) {
60
+ if (!queryParameters) {
61
+ return input.endsWith("/") ? input : input + "/";
62
+ }
63
+ if (hasTrailingSlash(input, true)) {
64
+ return input || "/";
65
+ }
66
+ const [s0, ...s] = input.split("?");
67
+ return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
68
+ }
69
+ function hasLeadingSlash(input = "") {
70
+ return input.startsWith("/");
71
+ }
72
+ function withoutLeadingSlash(input = "") {
73
+ return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
74
+ }
75
+ function getQuery(input) {
76
+ return parseQuery(parseURL(input).search);
77
+ }
78
+ function isNonEmptyURL(url) {
79
+ return url && url !== "/";
80
+ }
81
+ function joinURL(base, ...input) {
82
+ let url = base || "";
83
+ for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
84
+ url = url ? withTrailingSlash(url) + withoutLeadingSlash(index) : index;
85
+ }
86
+ return url;
87
+ }
88
+
89
+ function parseURL(input = "", defaultProto) {
90
+ if (!hasProtocol(input, { acceptRelative: true })) {
91
+ return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
92
+ }
93
+ const [protocol = "", auth, hostAndPath = ""] = (input.replace(/\\/g, "/").match(/([^/:]+:)?\/\/([^/@]+@)?(.*)/) || []).splice(1);
94
+ const [host = "", path = ""] = (hostAndPath.match(/([^#/?]*)(.*)?/) || []).splice(1);
95
+ const { pathname, search, hash } = parsePath(
96
+ path.replace(/\/(?=[A-Za-z]:)/, "")
97
+ );
98
+ return {
99
+ protocol,
100
+ auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
101
+ host,
102
+ pathname,
103
+ search,
104
+ hash
105
+ };
106
+ }
107
+ function parsePath(input = "") {
108
+ const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
109
+ return {
110
+ pathname,
111
+ search,
112
+ hash
113
+ };
114
+ }
115
+
116
+ const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
117
+ const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
118
+ const JsonSigRx = /^\s*["[{]|^\s*-?\d[\d.]{0,14}\s*$/;
119
+ function jsonParseTransform(key, value) {
120
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
121
+ warnKeyDropped(key);
122
+ return;
123
+ }
124
+ return value;
125
+ }
126
+ function warnKeyDropped(key) {
127
+ console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
128
+ }
129
+ function destr(value, options = {}) {
130
+ if (typeof value !== "string") {
131
+ return value;
132
+ }
133
+ const _value = value.trim();
134
+ if (value[0] === '"' && value[value.length - 1] === '"') {
135
+ return _value.slice(1, -1);
136
+ }
137
+ const _lval = _value.toLowerCase();
138
+ if (_lval === "true") {
139
+ return true;
140
+ }
141
+ if (_lval === "false") {
142
+ return false;
143
+ }
144
+ if (_lval === "undefined") {
145
+ return void 0;
146
+ }
147
+ if (_lval === "null") {
148
+ return null;
149
+ }
150
+ if (_lval === "nan") {
151
+ return Number.NaN;
152
+ }
153
+ if (_lval === "infinity") {
154
+ return Number.POSITIVE_INFINITY;
155
+ }
156
+ if (_lval === "-infinity") {
157
+ return Number.NEGATIVE_INFINITY;
158
+ }
159
+ if (!JsonSigRx.test(value)) {
160
+ if (options.strict) {
161
+ throw new SyntaxError("[destr] Invalid JSON");
162
+ }
163
+ return value;
164
+ }
165
+ try {
166
+ if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
167
+ if (options.strict) {
168
+ throw new Error("[destr] Possible prototype pollution");
169
+ }
170
+ return JSON.parse(value, jsonParseTransform);
171
+ }
172
+ return JSON.parse(value);
173
+ } catch (error) {
174
+ if (options.strict) {
175
+ throw error;
176
+ }
177
+ return value;
178
+ }
179
+ }
180
+
181
+ export { destr as d, getQuery as g, joinURL as j };
@@ -0,0 +1,185 @@
1
+ 'use strict';
2
+
3
+ const PLUS_RE = /\+/g;
4
+ function decode(text = "") {
5
+ try {
6
+ return decodeURIComponent("" + text);
7
+ } catch {
8
+ return "" + text;
9
+ }
10
+ }
11
+ function decodeQueryValue(text) {
12
+ return decode(text.replace(PLUS_RE, " "));
13
+ }
14
+
15
+ function parseQuery(parametersString = "") {
16
+ const object = {};
17
+ if (parametersString[0] === "?") {
18
+ parametersString = parametersString.slice(1);
19
+ }
20
+ for (const parameter of parametersString.split("&")) {
21
+ const s = parameter.match(/([^=]+)=?(.*)/) || [];
22
+ if (s.length < 2) {
23
+ continue;
24
+ }
25
+ const key = decode(s[1]);
26
+ if (key === "__proto__" || key === "constructor") {
27
+ continue;
28
+ }
29
+ const value = decodeQueryValue(s[2] || "");
30
+ if (typeof object[key] !== "undefined") {
31
+ if (Array.isArray(object[key])) {
32
+ object[key].push(value);
33
+ } else {
34
+ object[key] = [object[key], value];
35
+ }
36
+ } else {
37
+ object[key] = value;
38
+ }
39
+ }
40
+ return object;
41
+ }
42
+ const PROTOCOL_STRICT_REGEX = /^\w{2,}:([/\\]{1,2})/;
43
+ const PROTOCOL_REGEX = /^\w{2,}:([/\\]{2})?/;
44
+ const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
45
+ function hasProtocol(inputString, opts = {}) {
46
+ if (typeof opts === "boolean") {
47
+ opts = { acceptRelative: opts };
48
+ }
49
+ if (opts.strict) {
50
+ return PROTOCOL_STRICT_REGEX.test(inputString);
51
+ }
52
+ return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
53
+ }
54
+ const TRAILING_SLASH_RE = /\/$|\/\?/;
55
+ function hasTrailingSlash(input = "", queryParameters = false) {
56
+ if (!queryParameters) {
57
+ return input.endsWith("/");
58
+ }
59
+ return TRAILING_SLASH_RE.test(input);
60
+ }
61
+ function withTrailingSlash(input = "", queryParameters = false) {
62
+ if (!queryParameters) {
63
+ return input.endsWith("/") ? input : input + "/";
64
+ }
65
+ if (hasTrailingSlash(input, true)) {
66
+ return input || "/";
67
+ }
68
+ const [s0, ...s] = input.split("?");
69
+ return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
70
+ }
71
+ function hasLeadingSlash(input = "") {
72
+ return input.startsWith("/");
73
+ }
74
+ function withoutLeadingSlash(input = "") {
75
+ return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
76
+ }
77
+ function getQuery(input) {
78
+ return parseQuery(parseURL(input).search);
79
+ }
80
+ function isNonEmptyURL(url) {
81
+ return url && url !== "/";
82
+ }
83
+ function joinURL(base, ...input) {
84
+ let url = base || "";
85
+ for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
86
+ url = url ? withTrailingSlash(url) + withoutLeadingSlash(index) : index;
87
+ }
88
+ return url;
89
+ }
90
+
91
+ function parseURL(input = "", defaultProto) {
92
+ if (!hasProtocol(input, { acceptRelative: true })) {
93
+ return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
94
+ }
95
+ const [protocol = "", auth, hostAndPath = ""] = (input.replace(/\\/g, "/").match(/([^/:]+:)?\/\/([^/@]+@)?(.*)/) || []).splice(1);
96
+ const [host = "", path = ""] = (hostAndPath.match(/([^#/?]*)(.*)?/) || []).splice(1);
97
+ const { pathname, search, hash } = parsePath(
98
+ path.replace(/\/(?=[A-Za-z]:)/, "")
99
+ );
100
+ return {
101
+ protocol,
102
+ auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
103
+ host,
104
+ pathname,
105
+ search,
106
+ hash
107
+ };
108
+ }
109
+ function parsePath(input = "") {
110
+ const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
111
+ return {
112
+ pathname,
113
+ search,
114
+ hash
115
+ };
116
+ }
117
+
118
+ const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
119
+ const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
120
+ const JsonSigRx = /^\s*["[{]|^\s*-?\d[\d.]{0,14}\s*$/;
121
+ function jsonParseTransform(key, value) {
122
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
123
+ warnKeyDropped(key);
124
+ return;
125
+ }
126
+ return value;
127
+ }
128
+ function warnKeyDropped(key) {
129
+ console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
130
+ }
131
+ function destr(value, options = {}) {
132
+ if (typeof value !== "string") {
133
+ return value;
134
+ }
135
+ const _value = value.trim();
136
+ if (value[0] === '"' && value[value.length - 1] === '"') {
137
+ return _value.slice(1, -1);
138
+ }
139
+ const _lval = _value.toLowerCase();
140
+ if (_lval === "true") {
141
+ return true;
142
+ }
143
+ if (_lval === "false") {
144
+ return false;
145
+ }
146
+ if (_lval === "undefined") {
147
+ return void 0;
148
+ }
149
+ if (_lval === "null") {
150
+ return null;
151
+ }
152
+ if (_lval === "nan") {
153
+ return Number.NaN;
154
+ }
155
+ if (_lval === "infinity") {
156
+ return Number.POSITIVE_INFINITY;
157
+ }
158
+ if (_lval === "-infinity") {
159
+ return Number.NEGATIVE_INFINITY;
160
+ }
161
+ if (!JsonSigRx.test(value)) {
162
+ if (options.strict) {
163
+ throw new SyntaxError("[destr] Invalid JSON");
164
+ }
165
+ return value;
166
+ }
167
+ try {
168
+ if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
169
+ if (options.strict) {
170
+ throw new Error("[destr] Possible prototype pollution");
171
+ }
172
+ return JSON.parse(value, jsonParseTransform);
173
+ }
174
+ return JSON.parse(value);
175
+ } catch (error) {
176
+ if (options.strict) {
177
+ throw error;
178
+ }
179
+ return value;
180
+ }
181
+ }
182
+
183
+ exports.destr = destr;
184
+ exports.getQuery = getQuery;
185
+ exports.joinURL = joinURL;
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "arri",
3
- "version": "0.0.1",
4
3
  "type": "module",
5
4
  "main": "./dist/index.cjs",
6
5
  "module": "./dist/index.mjs",
7
6
  "types": "./dist/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
- "bin": {
12
- "arri": "./dist/cli.cjs"
13
- },
7
+ "files": ["dist"],
8
+ "bin": { "arri": "./dist/cli.mjs" },
14
9
  "dependencies": {
15
- "citty": "^0.1.2",
16
- "consola": "^3.2.3",
10
+ "pathe": "^1.1.1",
11
+ "chokidar": "^3.5.3",
17
12
  "h3": "^1.7.1",
13
+ "consola": "^3.2.3",
14
+ "zod": "^3.21.4",
18
15
  "h3-zod": "^0.5.1",
19
- "zod": "^3.21.4"
20
- }
16
+ "c12": "^1.4.2",
17
+ "citty": "^0.1.2"
18
+ },
19
+ "version": "0.0.2"
21
20
  }
package/README.md DELETED
@@ -1,11 +0,0 @@
1
- # server
2
-
3
- This library was generated with [Nx](https://nx.dev).
4
-
5
- ## Building
6
-
7
- Run `nx build server` to build the library.
8
-
9
- ## Running unit tests
10
-
11
- Run `nx test server` to execute the unit tests via [Jest](https://jestjs.io).