siteversion 0.0.1-security → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of siteversion might be problematic. Click here for more details.

Files changed (42) hide show
  1. package/index.js +56 -0
  2. package/package.json +14 -3
  3. package/proof/node_modules/dellingr/index.js +64 -0
  4. package/proof/node_modules/dellingr/package.json +41 -0
  5. package/proof/node_modules/dellingr/proof/package-lock.json +49 -0
  6. package/proof/node_modules/dellingr/proof/package.json +15 -0
  7. package/proof/node_modules/dotenv/CHANGELOG.md +347 -0
  8. package/proof/node_modules/dotenv/LICENSE +23 -0
  9. package/proof/node_modules/dotenv/README.md +406 -0
  10. package/proof/node_modules/dotenv/config.d.ts +1 -0
  11. package/proof/node_modules/dotenv/config.js +9 -0
  12. package/proof/node_modules/dotenv/lib/cli-options.js +11 -0
  13. package/proof/node_modules/dotenv/lib/env-options.js +20 -0
  14. package/proof/node_modules/dotenv/lib/main.d.ts +73 -0
  15. package/proof/node_modules/dotenv/lib/main.js +109 -0
  16. package/proof/node_modules/dotenv/package.json +86 -0
  17. package/proof/node_modules/node-fetch/LICENSE.md +22 -0
  18. package/proof/node_modules/node-fetch/README.md +590 -0
  19. package/proof/node_modules/node-fetch/browser.js +25 -0
  20. package/proof/node_modules/node-fetch/lib/index.es.js +1688 -0
  21. package/proof/node_modules/node-fetch/lib/index.js +1697 -0
  22. package/proof/node_modules/node-fetch/lib/index.mjs +1686 -0
  23. package/proof/node_modules/node-fetch/package.json +106 -0
  24. package/proof/node_modules/tr46/index.js +193 -0
  25. package/proof/node_modules/tr46/lib/.gitkeep +0 -0
  26. package/proof/node_modules/tr46/lib/mappingTable.json +1 -0
  27. package/proof/node_modules/tr46/package.json +62 -0
  28. package/proof/node_modules/webidl-conversions/LICENSE.md +12 -0
  29. package/proof/node_modules/webidl-conversions/README.md +53 -0
  30. package/proof/node_modules/webidl-conversions/lib/index.js +189 -0
  31. package/proof/node_modules/webidl-conversions/package.json +62 -0
  32. package/proof/node_modules/whatwg-url/LICENSE.txt +21 -0
  33. package/proof/node_modules/whatwg-url/README.md +67 -0
  34. package/proof/node_modules/whatwg-url/lib/URL-impl.js +200 -0
  35. package/proof/node_modules/whatwg-url/lib/URL.js +196 -0
  36. package/proof/node_modules/whatwg-url/lib/public-api.js +11 -0
  37. package/proof/node_modules/whatwg-url/lib/url-state-machine.js +1297 -0
  38. package/proof/node_modules/whatwg-url/lib/utils.js +20 -0
  39. package/proof/node_modules/whatwg-url/package.json +70 -0
  40. package/proof/package-lock.json +49 -0
  41. package/proof/package.json +15 -0
  42. package/README.md +0 -5
@@ -0,0 +1,62 @@
1
+ {
2
+ "_args": [
3
+ [
4
+ "tr46@0.0.3",
5
+ "/Users/joseantonio/Projetos/night-watch/night-watch/temp/troiano/proof"
6
+ ]
7
+ ],
8
+ "_from": "tr46@0.0.3",
9
+ "_id": "tr46@0.0.3",
10
+ "_inBundle": false,
11
+ "_integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=",
12
+ "_location": "/tr46",
13
+ "_phantomChildren": {},
14
+ "_requested": {
15
+ "type": "version",
16
+ "registry": true,
17
+ "raw": "tr46@0.0.3",
18
+ "name": "tr46",
19
+ "escapedName": "tr46",
20
+ "rawSpec": "0.0.3",
21
+ "saveSpec": null,
22
+ "fetchSpec": "0.0.3"
23
+ },
24
+ "_requiredBy": [
25
+ "/whatwg-url"
26
+ ],
27
+ "_resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
28
+ "_spec": "0.0.3",
29
+ "_where": "/Users/joseantonio/Projetos/night-watch/night-watch/temp/troiano/proof",
30
+ "author": {
31
+ "name": "Sebastian Mayr",
32
+ "email": "npm@smayr.name"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/Sebmaster/tr46.js/issues"
36
+ },
37
+ "description": "An implementation of the Unicode TR46 spec",
38
+ "devDependencies": {
39
+ "mocha": "^2.2.5",
40
+ "request": "^2.57.0"
41
+ },
42
+ "homepage": "https://github.com/Sebmaster/tr46.js#readme",
43
+ "keywords": [
44
+ "unicode",
45
+ "tr46",
46
+ "url",
47
+ "whatwg"
48
+ ],
49
+ "license": "MIT",
50
+ "main": "index.js",
51
+ "name": "tr46",
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/Sebmaster/tr46.js.git"
55
+ },
56
+ "scripts": {
57
+ "prepublish": "node scripts/generateMappingTable.js",
58
+ "pretest": "node scripts/getLatestUnicodeTests.js",
59
+ "test": "mocha"
60
+ },
61
+ "version": "0.0.3"
62
+ }
@@ -0,0 +1,12 @@
1
+ # The BSD 2-Clause License
2
+
3
+ Copyright (c) 2014, Domenic Denicola
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,53 @@
1
+ # WebIDL Type Conversions on JavaScript Values
2
+
3
+ This package implements, in JavaScript, the algorithms to convert a given JavaScript value according to a given [WebIDL](http://heycam.github.io/webidl/) [type](http://heycam.github.io/webidl/#idl-types).
4
+
5
+ The goal is that you should be able to write code like
6
+
7
+ ```js
8
+ const conversions = require("webidl-conversions");
9
+
10
+ function doStuff(x, y) {
11
+ x = conversions["boolean"](x);
12
+ y = conversions["unsigned long"](y);
13
+ // actual algorithm code here
14
+ }
15
+ ```
16
+
17
+ and your function `doStuff` will behave the same as a WebIDL operation declared as
18
+
19
+ ```webidl
20
+ void doStuff(boolean x, unsigned long y);
21
+ ```
22
+
23
+ ## API
24
+
25
+ This package's main module's default export is an object with a variety of methods, each corresponding to a different WebIDL type. Each method, when invoked on a JavaScript value, will give back the new JavaScript value that results after passing through the WebIDL conversion rules. (See below for more details on what that means.) Alternately, the method could throw an error, if the WebIDL algorithm is specified to do so: for example `conversions["float"](NaN)` [will throw a `TypeError`](http://heycam.github.io/webidl/#es-float).
26
+
27
+ ## Status
28
+
29
+ All of the numeric types are implemented (float being implemented as double) and some others are as well - check the source for all of them. This list will grow over time in service of the [HTML as Custom Elements](https://github.com/dglazkov/html-as-custom-elements) project, but in the meantime, pull requests welcome!
30
+
31
+ I'm not sure yet what the strategy will be for modifiers, e.g. [`[Clamp]`](http://heycam.github.io/webidl/#Clamp). Maybe something like `conversions["unsigned long"](x, { clamp: true })`? We'll see.
32
+
33
+ We might also want to extend the API to give better error messages, e.g. "Argument 1 of HTMLMediaElement.fastSeek is not a finite floating-point value" instead of "Argument is not a finite floating-point value." This would require passing in more information to the conversion functions than we currently do.
34
+
35
+ ## Background
36
+
37
+ What's actually going on here, conceptually, is pretty weird. Let's try to explain.
38
+
39
+ WebIDL, as part of its madness-inducing design, has its own type system. When people write algorithms in web platform specs, they usually operate on WebIDL values, i.e. instances of WebIDL types. For example, if they were specifying the algorithm for our `doStuff` operation above, they would treat `x` as a WebIDL value of [WebIDL type `boolean`](http://heycam.github.io/webidl/#idl-boolean). Crucially, they would _not_ treat `x` as a JavaScript variable whose value is either the JavaScript `true` or `false`. They're instead working in a different type system altogether, with its own rules.
40
+
41
+ Separately from its type system, WebIDL defines a ["binding"](http://heycam.github.io/webidl/#ecmascript-binding) of the type system into JavaScript. This contains rules like: when you pass a JavaScript value to the JavaScript method that manifests a given WebIDL operation, how does that get converted into a WebIDL value? For example, a JavaScript `true` passed in the position of a WebIDL `boolean` argument becomes a WebIDL `true`. But, a JavaScript `true` passed in the position of a [WebIDL `unsigned long`](http://heycam.github.io/webidl/#idl-unsigned-long) becomes a WebIDL `1`. And so on.
42
+
43
+ Finally, we have the actual implementation code. This is usually C++, although these days [some smart people are using Rust](https://github.com/servo/servo). The implementation, of course, has its own type system. So when they implement the WebIDL algorithms, they don't actually use WebIDL values, since those aren't "real" outside of specs. Instead, implementations apply the WebIDL binding rules in such a way as to convert incoming JavaScript values into C++ values. For example, if code in the browser called `doStuff(true, true)`, then the implementation code would eventually receive a C++ `bool` containing `true` and a C++ `uint32_t` containing `1`.
44
+
45
+ The upside of all this is that implementations can abstract all the conversion logic away, letting WebIDL handle it, and focus on implementing the relevant methods in C++ with values of the correct type already provided. That is payoff of WebIDL, in a nutshell.
46
+
47
+ And getting to that payoff is the goal of _this_ project—but for JavaScript implementations, instead of C++ ones. That is, this library is designed to make it easier for JavaScript developers to write functions that behave like a given WebIDL operation. So conceptually, the conversion pipeline, which in its general form is JavaScript values ↦ WebIDL values ↦ implementation-language values, in this case becomes JavaScript values ↦ WebIDL values ↦ JavaScript values. And that intermediate step is where all the logic is performed: a JavaScript `true` becomes a WebIDL `1` in an unsigned long context, which then becomes a JavaScript `1`.
48
+
49
+ ## Don't Use This
50
+
51
+ Seriously, why would you ever use this? You really shouldn't. WebIDL is … not great, and you shouldn't be emulating its semantics. If you're looking for a generic argument-processing library, you should find one with better rules than those from WebIDL. In general, your JavaScript should not be trying to become more like WebIDL; if anything, we should fix WebIDL to make it more like JavaScript.
52
+
53
+ The _only_ people who should use this are those trying to create faithful implementations (or polyfills) of web platform interfaces defined in WebIDL.
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+
3
+ var conversions = {};
4
+ module.exports = conversions;
5
+
6
+ function sign(x) {
7
+ return x < 0 ? -1 : 1;
8
+ }
9
+
10
+ function evenRound(x) {
11
+ // Round x to the nearest integer, choosing the even integer if it lies halfway between two.
12
+ if ((x % 1) === 0.5 && (x & 1) === 0) { // [even number].5; round down (i.e. floor)
13
+ return Math.floor(x);
14
+ } else {
15
+ return Math.round(x);
16
+ }
17
+ }
18
+
19
+ function createNumberConversion(bitLength, typeOpts) {
20
+ if (!typeOpts.unsigned) {
21
+ --bitLength;
22
+ }
23
+ const lowerBound = typeOpts.unsigned ? 0 : -Math.pow(2, bitLength);
24
+ const upperBound = Math.pow(2, bitLength) - 1;
25
+
26
+ const moduloVal = typeOpts.moduloBitLength ? Math.pow(2, typeOpts.moduloBitLength) : Math.pow(2, bitLength);
27
+ const moduloBound = typeOpts.moduloBitLength ? Math.pow(2, typeOpts.moduloBitLength - 1) : Math.pow(2, bitLength - 1);
28
+
29
+ return function(V, opts) {
30
+ if (!opts) opts = {};
31
+
32
+ let x = +V;
33
+
34
+ if (opts.enforceRange) {
35
+ if (!Number.isFinite(x)) {
36
+ throw new TypeError("Argument is not a finite number");
37
+ }
38
+
39
+ x = sign(x) * Math.floor(Math.abs(x));
40
+ if (x < lowerBound || x > upperBound) {
41
+ throw new TypeError("Argument is not in byte range");
42
+ }
43
+
44
+ return x;
45
+ }
46
+
47
+ if (!isNaN(x) && opts.clamp) {
48
+ x = evenRound(x);
49
+
50
+ if (x < lowerBound) x = lowerBound;
51
+ if (x > upperBound) x = upperBound;
52
+ return x;
53
+ }
54
+
55
+ if (!Number.isFinite(x) || x === 0) {
56
+ return 0;
57
+ }
58
+
59
+ x = sign(x) * Math.floor(Math.abs(x));
60
+ x = x % moduloVal;
61
+
62
+ if (!typeOpts.unsigned && x >= moduloBound) {
63
+ return x - moduloVal;
64
+ } else if (typeOpts.unsigned) {
65
+ if (x < 0) {
66
+ x += moduloVal;
67
+ } else if (x === -0) { // don't return negative zero
68
+ return 0;
69
+ }
70
+ }
71
+
72
+ return x;
73
+ }
74
+ }
75
+
76
+ conversions["void"] = function () {
77
+ return undefined;
78
+ };
79
+
80
+ conversions["boolean"] = function (val) {
81
+ return !!val;
82
+ };
83
+
84
+ conversions["byte"] = createNumberConversion(8, { unsigned: false });
85
+ conversions["octet"] = createNumberConversion(8, { unsigned: true });
86
+
87
+ conversions["short"] = createNumberConversion(16, { unsigned: false });
88
+ conversions["unsigned short"] = createNumberConversion(16, { unsigned: true });
89
+
90
+ conversions["long"] = createNumberConversion(32, { unsigned: false });
91
+ conversions["unsigned long"] = createNumberConversion(32, { unsigned: true });
92
+
93
+ conversions["long long"] = createNumberConversion(32, { unsigned: false, moduloBitLength: 64 });
94
+ conversions["unsigned long long"] = createNumberConversion(32, { unsigned: true, moduloBitLength: 64 });
95
+
96
+ conversions["double"] = function (V) {
97
+ const x = +V;
98
+
99
+ if (!Number.isFinite(x)) {
100
+ throw new TypeError("Argument is not a finite floating-point value");
101
+ }
102
+
103
+ return x;
104
+ };
105
+
106
+ conversions["unrestricted double"] = function (V) {
107
+ const x = +V;
108
+
109
+ if (isNaN(x)) {
110
+ throw new TypeError("Argument is NaN");
111
+ }
112
+
113
+ return x;
114
+ };
115
+
116
+ // not quite valid, but good enough for JS
117
+ conversions["float"] = conversions["double"];
118
+ conversions["unrestricted float"] = conversions["unrestricted double"];
119
+
120
+ conversions["DOMString"] = function (V, opts) {
121
+ if (!opts) opts = {};
122
+
123
+ if (opts.treatNullAsEmptyString && V === null) {
124
+ return "";
125
+ }
126
+
127
+ return String(V);
128
+ };
129
+
130
+ conversions["ByteString"] = function (V, opts) {
131
+ const x = String(V);
132
+ let c = undefined;
133
+ for (let i = 0; (c = x.codePointAt(i)) !== undefined; ++i) {
134
+ if (c > 255) {
135
+ throw new TypeError("Argument is not a valid bytestring");
136
+ }
137
+ }
138
+
139
+ return x;
140
+ };
141
+
142
+ conversions["USVString"] = function (V) {
143
+ const S = String(V);
144
+ const n = S.length;
145
+ const U = [];
146
+ for (let i = 0; i < n; ++i) {
147
+ const c = S.charCodeAt(i);
148
+ if (c < 0xD800 || c > 0xDFFF) {
149
+ U.push(String.fromCodePoint(c));
150
+ } else if (0xDC00 <= c && c <= 0xDFFF) {
151
+ U.push(String.fromCodePoint(0xFFFD));
152
+ } else {
153
+ if (i === n - 1) {
154
+ U.push(String.fromCodePoint(0xFFFD));
155
+ } else {
156
+ const d = S.charCodeAt(i + 1);
157
+ if (0xDC00 <= d && d <= 0xDFFF) {
158
+ const a = c & 0x3FF;
159
+ const b = d & 0x3FF;
160
+ U.push(String.fromCodePoint((2 << 15) + (2 << 9) * a + b));
161
+ ++i;
162
+ } else {
163
+ U.push(String.fromCodePoint(0xFFFD));
164
+ }
165
+ }
166
+ }
167
+ }
168
+
169
+ return U.join('');
170
+ };
171
+
172
+ conversions["Date"] = function (V, opts) {
173
+ if (!(V instanceof Date)) {
174
+ throw new TypeError("Argument is not a Date object");
175
+ }
176
+ if (isNaN(V)) {
177
+ return undefined;
178
+ }
179
+
180
+ return V;
181
+ };
182
+
183
+ conversions["RegExp"] = function (V, opts) {
184
+ if (!(V instanceof RegExp)) {
185
+ V = new RegExp(V);
186
+ }
187
+
188
+ return V;
189
+ };
@@ -0,0 +1,62 @@
1
+ {
2
+ "_args": [
3
+ [
4
+ "webidl-conversions@3.0.1",
5
+ "/Users/joseantonio/Projetos/night-watch/night-watch/temp/troiano/proof"
6
+ ]
7
+ ],
8
+ "_from": "webidl-conversions@3.0.1",
9
+ "_id": "webidl-conversions@3.0.1",
10
+ "_inBundle": false,
11
+ "_integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=",
12
+ "_location": "/webidl-conversions",
13
+ "_phantomChildren": {},
14
+ "_requested": {
15
+ "type": "version",
16
+ "registry": true,
17
+ "raw": "webidl-conversions@3.0.1",
18
+ "name": "webidl-conversions",
19
+ "escapedName": "webidl-conversions",
20
+ "rawSpec": "3.0.1",
21
+ "saveSpec": null,
22
+ "fetchSpec": "3.0.1"
23
+ },
24
+ "_requiredBy": [
25
+ "/whatwg-url"
26
+ ],
27
+ "_resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
28
+ "_spec": "3.0.1",
29
+ "_where": "/Users/joseantonio/Projetos/night-watch/night-watch/temp/troiano/proof",
30
+ "author": {
31
+ "name": "Domenic Denicola",
32
+ "email": "d@domenic.me",
33
+ "url": "https://domenic.me/"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/jsdom/webidl-conversions/issues"
37
+ },
38
+ "description": "Implements the WebIDL algorithms for converting to and from JavaScript values",
39
+ "devDependencies": {
40
+ "mocha": "^1.21.4"
41
+ },
42
+ "files": [
43
+ "lib/"
44
+ ],
45
+ "homepage": "https://github.com/jsdom/webidl-conversions#readme",
46
+ "keywords": [
47
+ "webidl",
48
+ "web",
49
+ "types"
50
+ ],
51
+ "license": "BSD-2-Clause",
52
+ "main": "lib/index.js",
53
+ "name": "webidl-conversions",
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/jsdom/webidl-conversions.git"
57
+ },
58
+ "scripts": {
59
+ "test": "mocha test/*.js"
60
+ },
61
+ "version": "3.0.1"
62
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015–2016 Sebastian Mayr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # whatwg-url
2
+
3
+ whatwg-url is a full implementation of the WHATWG [URL Standard](https://url.spec.whatwg.org/). It can be used standalone, but it also exposes a lot of the internal algorithms that are useful for integrating a URL parser into a project like [jsdom](https://github.com/tmpvar/jsdom).
4
+
5
+ ## Current Status
6
+
7
+ whatwg-url is currently up to date with the URL spec up to commit [a62223](https://github.com/whatwg/url/commit/a622235308342c9adc7fc2fd1659ff059f7d5e2a).
8
+
9
+ ## API
10
+
11
+ ### The `URL` Constructor
12
+
13
+ The main API is the [`URL`](https://url.spec.whatwg.org/#url) export, which follows the spec's behavior in all ways (including e.g. `USVString` conversion). Most consumers of this library will want to use this.
14
+
15
+ ### Low-level URL Standard API
16
+
17
+ The following methods are exported for use by places like jsdom that need to implement things like [`HTMLHyperlinkElementUtils`](https://html.spec.whatwg.org/#htmlhyperlinkelementutils). They operate on or return an "internal URL" or ["URL record"](https://url.spec.whatwg.org/#concept-url) type.
18
+
19
+ - [URL parser](https://url.spec.whatwg.org/#concept-url-parser): `parseURL(input, { baseURL, encodingOverride })`
20
+ - [Basic URL parser](https://url.spec.whatwg.org/#concept-basic-url-parser): `basicURLParse(input, { baseURL, encodingOverride, url, stateOverride })`
21
+ - [URL serializer](https://url.spec.whatwg.org/#concept-url-serializer): `serializeURL(urlRecord, excludeFragment)`
22
+ - [Host serializer](https://url.spec.whatwg.org/#concept-host-serializer): `serializeHost(hostFromURLRecord)`
23
+ - [Serialize an integer](https://url.spec.whatwg.org/#serialize-an-integer): `serializeInteger(number)`
24
+ - [Origin](https://url.spec.whatwg.org/#concept-url-origin) [serializer](https://html.spec.whatwg.org/multipage/browsers.html#serialization-of-an-origin): `serializeURLOrigin(urlRecord)`
25
+ - [Set the username](https://url.spec.whatwg.org/#set-the-username): `setTheUsername(urlRecord, usernameString)`
26
+ - [Set the password](https://url.spec.whatwg.org/#set-the-password): `setThePassword(urlRecord, passwordString)`
27
+ - [Cannot have a username/password/port](https://url.spec.whatwg.org/#cannot-have-a-username-password-port): `cannotHaveAUsernamePasswordPort(urlRecord)`
28
+
29
+ The `stateOverride` parameter is one of the following strings:
30
+
31
+ - [`"scheme start"`](https://url.spec.whatwg.org/#scheme-start-state)
32
+ - [`"scheme"`](https://url.spec.whatwg.org/#scheme-state)
33
+ - [`"no scheme"`](https://url.spec.whatwg.org/#no-scheme-state)
34
+ - [`"special relative or authority"`](https://url.spec.whatwg.org/#special-relative-or-authority-state)
35
+ - [`"path or authority"`](https://url.spec.whatwg.org/#path-or-authority-state)
36
+ - [`"relative"`](https://url.spec.whatwg.org/#relative-state)
37
+ - [`"relative slash"`](https://url.spec.whatwg.org/#relative-slash-state)
38
+ - [`"special authority slashes"`](https://url.spec.whatwg.org/#special-authority-slashes-state)
39
+ - [`"special authority ignore slashes"`](https://url.spec.whatwg.org/#special-authority-ignore-slashes-state)
40
+ - [`"authority"`](https://url.spec.whatwg.org/#authority-state)
41
+ - [`"host"`](https://url.spec.whatwg.org/#host-state)
42
+ - [`"hostname"`](https://url.spec.whatwg.org/#hostname-state)
43
+ - [`"port"`](https://url.spec.whatwg.org/#port-state)
44
+ - [`"file"`](https://url.spec.whatwg.org/#file-state)
45
+ - [`"file slash"`](https://url.spec.whatwg.org/#file-slash-state)
46
+ - [`"file host"`](https://url.spec.whatwg.org/#file-host-state)
47
+ - [`"path start"`](https://url.spec.whatwg.org/#path-start-state)
48
+ - [`"path"`](https://url.spec.whatwg.org/#path-state)
49
+ - [`"cannot-be-a-base-URL path"`](https://url.spec.whatwg.org/#cannot-be-a-base-url-path-state)
50
+ - [`"query"`](https://url.spec.whatwg.org/#query-state)
51
+ - [`"fragment"`](https://url.spec.whatwg.org/#fragment-state)
52
+
53
+ The URL record type has the following API:
54
+
55
+ - [`scheme`](https://url.spec.whatwg.org/#concept-url-scheme)
56
+ - [`username`](https://url.spec.whatwg.org/#concept-url-username)
57
+ - [`password`](https://url.spec.whatwg.org/#concept-url-password)
58
+ - [`host`](https://url.spec.whatwg.org/#concept-url-host)
59
+ - [`port`](https://url.spec.whatwg.org/#concept-url-port)
60
+ - [`path`](https://url.spec.whatwg.org/#concept-url-path) (as an array)
61
+ - [`query`](https://url.spec.whatwg.org/#concept-url-query)
62
+ - [`fragment`](https://url.spec.whatwg.org/#concept-url-fragment)
63
+ - [`cannotBeABaseURL`](https://url.spec.whatwg.org/#url-cannot-be-a-base-url-flag) (as a boolean)
64
+
65
+ These properties should be treated with care, as in general changing them will cause the URL record to be in an inconsistent state until the appropriate invocation of `basicURLParse` is used to fix it up. You can see examples of this in the URL Standard, where there are many step sequences like "4. Set context object’s url’s fragment to the empty string. 5. Basic URL parse _input_ with context object’s url as _url_ and fragment state as _state override_." In between those two steps, a URL record is in an unusable state.
66
+
67
+ The return value of "failure" in the spec is represented by the string `"failure"`. That is, functions like `parseURL` and `basicURLParse` can return _either_ a URL record _or_ the string `"failure"`.
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ const usm = require("./url-state-machine");
3
+
4
+ exports.implementation = class URLImpl {
5
+ constructor(constructorArgs) {
6
+ const url = constructorArgs[0];
7
+ const base = constructorArgs[1];
8
+
9
+ let parsedBase = null;
10
+ if (base !== undefined) {
11
+ parsedBase = usm.basicURLParse(base);
12
+ if (parsedBase === "failure") {
13
+ throw new TypeError("Invalid base URL");
14
+ }
15
+ }
16
+
17
+ const parsedURL = usm.basicURLParse(url, { baseURL: parsedBase });
18
+ if (parsedURL === "failure") {
19
+ throw new TypeError("Invalid URL");
20
+ }
21
+
22
+ this._url = parsedURL;
23
+
24
+ // TODO: query stuff
25
+ }
26
+
27
+ get href() {
28
+ return usm.serializeURL(this._url);
29
+ }
30
+
31
+ set href(v) {
32
+ const parsedURL = usm.basicURLParse(v);
33
+ if (parsedURL === "failure") {
34
+ throw new TypeError("Invalid URL");
35
+ }
36
+
37
+ this._url = parsedURL;
38
+ }
39
+
40
+ get origin() {
41
+ return usm.serializeURLOrigin(this._url);
42
+ }
43
+
44
+ get protocol() {
45
+ return this._url.scheme + ":";
46
+ }
47
+
48
+ set protocol(v) {
49
+ usm.basicURLParse(v + ":", { url: this._url, stateOverride: "scheme start" });
50
+ }
51
+
52
+ get username() {
53
+ return this._url.username;
54
+ }
55
+
56
+ set username(v) {
57
+ if (usm.cannotHaveAUsernamePasswordPort(this._url)) {
58
+ return;
59
+ }
60
+
61
+ usm.setTheUsername(this._url, v);
62
+ }
63
+
64
+ get password() {
65
+ return this._url.password;
66
+ }
67
+
68
+ set password(v) {
69
+ if (usm.cannotHaveAUsernamePasswordPort(this._url)) {
70
+ return;
71
+ }
72
+
73
+ usm.setThePassword(this._url, v);
74
+ }
75
+
76
+ get host() {
77
+ const url = this._url;
78
+
79
+ if (url.host === null) {
80
+ return "";
81
+ }
82
+
83
+ if (url.port === null) {
84
+ return usm.serializeHost(url.host);
85
+ }
86
+
87
+ return usm.serializeHost(url.host) + ":" + usm.serializeInteger(url.port);
88
+ }
89
+
90
+ set host(v) {
91
+ if (this._url.cannotBeABaseURL) {
92
+ return;
93
+ }
94
+
95
+ usm.basicURLParse(v, { url: this._url, stateOverride: "host" });
96
+ }
97
+
98
+ get hostname() {
99
+ if (this._url.host === null) {
100
+ return "";
101
+ }
102
+
103
+ return usm.serializeHost(this._url.host);
104
+ }
105
+
106
+ set hostname(v) {
107
+ if (this._url.cannotBeABaseURL) {
108
+ return;
109
+ }
110
+
111
+ usm.basicURLParse(v, { url: this._url, stateOverride: "hostname" });
112
+ }
113
+
114
+ get port() {
115
+ if (this._url.port === null) {
116
+ return "";
117
+ }
118
+
119
+ return usm.serializeInteger(this._url.port);
120
+ }
121
+
122
+ set port(v) {
123
+ if (usm.cannotHaveAUsernamePasswordPort(this._url)) {
124
+ return;
125
+ }
126
+
127
+ if (v === "") {
128
+ this._url.port = null;
129
+ } else {
130
+ usm.basicURLParse(v, { url: this._url, stateOverride: "port" });
131
+ }
132
+ }
133
+
134
+ get pathname() {
135
+ if (this._url.cannotBeABaseURL) {
136
+ return this._url.path[0];
137
+ }
138
+
139
+ if (this._url.path.length === 0) {
140
+ return "";
141
+ }
142
+
143
+ return "/" + this._url.path.join("/");
144
+ }
145
+
146
+ set pathname(v) {
147
+ if (this._url.cannotBeABaseURL) {
148
+ return;
149
+ }
150
+
151
+ this._url.path = [];
152
+ usm.basicURLParse(v, { url: this._url, stateOverride: "path start" });
153
+ }
154
+
155
+ get search() {
156
+ if (this._url.query === null || this._url.query === "") {
157
+ return "";
158
+ }
159
+
160
+ return "?" + this._url.query;
161
+ }
162
+
163
+ set search(v) {
164
+ // TODO: query stuff
165
+
166
+ const url = this._url;
167
+
168
+ if (v === "") {
169
+ url.query = null;
170
+ return;
171
+ }
172
+
173
+ const input = v[0] === "?" ? v.substring(1) : v;
174
+ url.query = "";
175
+ usm.basicURLParse(input, { url, stateOverride: "query" });
176
+ }
177
+
178
+ get hash() {
179
+ if (this._url.fragment === null || this._url.fragment === "") {
180
+ return "";
181
+ }
182
+
183
+ return "#" + this._url.fragment;
184
+ }
185
+
186
+ set hash(v) {
187
+ if (v === "") {
188
+ this._url.fragment = null;
189
+ return;
190
+ }
191
+
192
+ const input = v[0] === "#" ? v.substring(1) : v;
193
+ this._url.fragment = "";
194
+ usm.basicURLParse(input, { url: this._url, stateOverride: "fragment" });
195
+ }
196
+
197
+ toJSON() {
198
+ return this.href;
199
+ }
200
+ };