deno.land / x / deno@v1.28.2 / runtime / js / 06_util.js

نووسراو ببینە
1
2
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license."use strict";
((window) => { const { decodeURIComponent, ObjectPrototypeIsPrototypeOf, Promise, SafeArrayIterator, StringPrototypeReplace, TypeError, } = window.__bootstrap.primordials; const { build } = window.__bootstrap.build; const { URLPrototype } = window.__bootstrap.url; let logDebug = false; let logSource = "JS";
function setLogDebug(debug, source) { logDebug = debug; if (source) { logSource = source; } }
function log(...args) { if (logDebug) { // if we destructure `console` off `globalThis` too early, we don't bind to // the right console, therefore we don't log anything out. globalThis.console.log( `DEBUG ${logSource} -`, ...new SafeArrayIterator(args), ); } }
function createResolvable() { let resolve; let reject; const promise = new Promise((res, rej) => { resolve = res; reject = rej; }); promise.resolve = resolve; promise.reject = reject; return promise; }
// Keep in sync with `fromFileUrl()` in `std/path/win32.ts`. function pathFromURLWin32(url) { let p = StringPrototypeReplace( url.pathname, /^\/*([A-Za-z]:)(\/|$)/, "$1/", ); p = StringPrototypeReplace( p, /\//g, "\\", ); p = StringPrototypeReplace( p, /%(?![0-9A-Fa-f]{2})/g, "%25", ); let path = decodeURIComponent(p); if (url.hostname != "") { // Note: The `URL` implementation guarantees that the drive letter and // hostname are mutually exclusive. Otherwise it would not have been valid // to append the hostname and path like this. path = `\\\\${url.hostname}${path}`; } return path; }
// Keep in sync with `fromFileUrl()` in `std/path/posix.ts`. function pathFromURLPosix(url) { if (url.hostname !== "") { throw new TypeError(`Host must be empty.`); }
return decodeURIComponent( StringPrototypeReplace(url.pathname, /%(?![0-9A-Fa-f]{2})/g, "%25"), ); }
function pathFromURL(pathOrUrl) { if (ObjectPrototypeIsPrototypeOf(URLPrototype, pathOrUrl)) { if (pathOrUrl.protocol != "file:") { throw new TypeError("Must be a file URL."); }
return build.os == "windows" ? pathFromURLWin32(pathOrUrl) : pathFromURLPosix(pathOrUrl); } return pathOrUrl; }
window.__bootstrap.internals = { ...window.__bootstrap.internals ?? {}, pathFromURL, };
function writable(value) { return { value, writable: true, enumerable: true, configurable: true, }; }
function nonEnumerable(value) { return { value, writable: true, enumerable: false, configurable: true, }; }
function readOnly(value) { return { value, enumerable: true, writable: false, configurable: true, }; }
function getterOnly(getter) { return { get: getter, enumerable: true, configurable: true, }; }
window.__bootstrap.util = { log, setLogDebug, createResolvable, pathFromURL, writable, nonEnumerable, readOnly, getterOnly, };})(this);
deno

Version Info

Tagged at
a year ago