1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | const url_1 = require("url");
|
17 | const unspecifiedProtocol = '-';
|
18 | function parseUrl(url, defaultProtocol = unspecifiedProtocol) {
|
19 | const urlObject = url_1.parse(ensureProtocol(url, defaultProtocol));
|
20 | if (urlObject.protocol &&
|
21 | urlObject.protocol.slice(0, -1) === unspecifiedProtocol) {
|
22 | urlObject.protocol = undefined;
|
23 | urlObject.href =
|
24 | urlObject.href && urlObject.href.slice(unspecifiedProtocol.length + 1);
|
25 | }
|
26 | return urlObject;
|
27 | }
|
28 | exports.parseUrl = parseUrl;
|
29 | function ensureProtocol(url, defaultProtocol) {
|
30 | return url.startsWith('//') ? `${defaultProtocol}:${url}` : url;
|
31 | }
|
32 | exports.ensureProtocol = ensureProtocol;
|
33 | function resolveUrl(baseUrl, targetUrl, defaultProtocol) {
|
34 | const baseProtocol = (url_1.parse(baseUrl).protocol || '').slice(0, -1);
|
35 | const protocol = baseProtocol !== 'file' && baseProtocol || defaultProtocol;
|
36 | return url_1.resolve(ensureProtocol(baseUrl, protocol), ensureProtocol(targetUrl, protocol));
|
37 | }
|
38 | exports.resolveUrl = resolveUrl;
|
39 | function trimLeft(str, char) {
|
40 | let leftEdge = 0;
|
41 | while (str[leftEdge] === char) {
|
42 | leftEdge++;
|
43 | }
|
44 | return str.substring(leftEdge);
|
45 | }
|
46 | exports.trimLeft = trimLeft;
|
47 | class Deferred {
|
48 | constructor() {
|
49 | this.resolved = false;
|
50 | this.rejected = false;
|
51 | this.promise = new Promise((resolve, reject) => {
|
52 | this.resolve = (result) => {
|
53 | if (this.resolved) {
|
54 | throw new Error('Already resolved');
|
55 | }
|
56 | if (this.rejected) {
|
57 | throw new Error('Already rejected');
|
58 | }
|
59 | this.resolved = true;
|
60 | resolve(result);
|
61 | };
|
62 | this.reject = (error) => {
|
63 | if (this.resolved) {
|
64 | throw new Error('Already resolved');
|
65 | }
|
66 | if (this.rejected) {
|
67 | throw new Error('Already rejected');
|
68 | }
|
69 | this.rejected = true;
|
70 | this.error = error;
|
71 | reject(error);
|
72 | };
|
73 | });
|
74 | }
|
75 | toNodeCallback() {
|
76 | return (error, value) => {
|
77 | if (error) {
|
78 | this.reject(error);
|
79 | }
|
80 | else {
|
81 | this.resolve(value);
|
82 | }
|
83 | };
|
84 | }
|
85 | }
|
86 | exports.Deferred = Deferred;
|
87 | function addAll(set1, set2) {
|
88 | for (const val of set2) {
|
89 | set1.add(val);
|
90 | }
|
91 | return set1;
|
92 | }
|
93 | exports.addAll = addAll;
|
94 |
|
\ | No newline at end of file |