1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 08:33:43 -05:00

Fix formatting of example code in typescript declaration files (#5475)

This commit is contained in:
Siddharth Parmar 2020-05-16 21:23:48 +02:00 committed by GitHub
parent acc821c2be
commit bfd4baf2d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 721 additions and 478 deletions

File diff suppressed because it is too large Load diff

View file

@ -1005,37 +1005,47 @@ declare class TextEncoder {
interface URLSearchParams {
/** Appends a specified key/value pair as a new search parameter.
*
* let searchParams = new URLSearchParams();
* searchParams.append('name', 'first');
* searchParams.append('name', 'second');
* ```ts
* let searchParams = new URLSearchParams();
* searchParams.append('name', 'first');
* searchParams.append('name', 'second');
* ```
*/
append(name: string, value: string): void;
/** Deletes the given search parameter and its associated value,
* from the list of all search parameters.
*
* let searchParams = new URLSearchParams([['name', 'value']]);
* searchParams.delete('name');
* ```ts
* let searchParams = new URLSearchParams([['name', 'value']]);
* searchParams.delete('name');
* ```
*/
delete(name: string): void;
/** Returns all the values associated with a given search parameter
* as an array.
*
* searchParams.getAll('name');
* ```ts
* searchParams.getAll('name');
* ```
*/
getAll(name: string): string[];
/** Returns the first value associated to the given search parameter.
*
* searchParams.get('name');
* ```ts
* searchParams.get('name');
* ```
*/
get(name: string): string | null;
/** Returns a Boolean that indicates whether a parameter with the
* specified name exists.
*
* searchParams.has('name');
* ```ts
* searchParams.has('name');
* ```
*/
has(name: string): boolean;
@ -1044,7 +1054,9 @@ interface URLSearchParams {
* deletes the others. If the search parameter doesn't exist, this
* method creates it.
*
* searchParams.set('name', 'value');
* ```ts
* searchParams.set('name', 'value');
* ```
*/
set(name: string, value: string): void;
@ -1052,7 +1064,9 @@ interface URLSearchParams {
* return undefined. The sort order is according to Unicode code
* points of the keys.
*
* searchParams.sort();
* ```ts
* searchParams.sort();
* ```
*/
sort(): void;
@ -1060,10 +1074,12 @@ interface URLSearchParams {
* place and return undefined. Optionally accepts an object to use
* as this when executing callback as second argument.
*
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* params.forEach((value, key, parent) => {
* console.log(value, key, parent);
* });
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* params.forEach((value, key, parent) => {
* console.log(value, key, parent);
* });
* ```
*
*/
forEach(
@ -1074,46 +1090,56 @@ interface URLSearchParams {
/** Returns an iterator allowing to go through all keys contained
* in this object.
*
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const key of params.keys()) {
* console.log(key);
* }
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const key of params.keys()) {
* console.log(key);
* }
* ```
*/
keys(): IterableIterator<string>;
/** Returns an iterator allowing to go through all values contained
* in this object.
*
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const value of params.values()) {
* console.log(value);
* }
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const value of params.values()) {
* console.log(value);
* }
* ```
*/
values(): IterableIterator<string>;
/** Returns an iterator allowing to go through all key/value
* pairs contained in this object.
*
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const [key, value] of params.entries()) {
* console.log(key, value);
* }
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const [key, value] of params.entries()) {
* console.log(key, value);
* }
* ```
*/
entries(): IterableIterator<[string, string]>;
/** Returns an iterator allowing to go through all key/value
* pairs contained in this object.
*
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const [key, value] of params) {
* console.log(key, value);
* }
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const [key, value] of params) {
* console.log(key, value);
* }
* ```
*/
[Symbol.iterator](): IterableIterator<[string, string]>;
/** Returns a query string suitable for use in a URL.
*
* searchParams.toString();
* ```ts
* searchParams.toString();
* ```
*/
toString(): string;
}
@ -1206,31 +1232,34 @@ declare class Worker extends EventTarget {
* Configurable permissions are on the roadmap to be implemented.
*
* Example:
* // mod.ts
* const worker = new Worker("./deno_worker.ts", { type: "module", deno: true });
* worker.postMessage({ cmd: "readFile", fileName: "./log.txt" });
*
* // deno_worker.ts
* ```ts
* // mod.ts
* const worker = new Worker("./deno_worker.ts", { type: "module", deno: true });
* worker.postMessage({ cmd: "readFile", fileName: "./log.txt" });
*
* // deno_worker.ts
*
*
* self.onmessage = async function (e) {
* const { cmd, fileName } = e.data;
* if (cmd !== "readFile") {
* throw new Error("Invalid command");
* }
* const buf = await Deno.readFile(fileName);
* const fileContents = new TextDecoder().decode(buf);
* console.log(fileContents);
* }
* self.onmessage = async function (e) {
* const { cmd, fileName } = e.data;
* if (cmd !== "readFile") {
* throw new Error("Invalid command");
* }
* const buf = await Deno.readFile(fileName);
* const fileContents = new TextDecoder().decode(buf);
* console.log(fileContents);
* }
* ```
*
* // log.txt
* hello world
* hello world 2
* // log.txt
* hello world
* hello world 2
*
* // run program
* $ deno run --allow-read mod.ts
* hello world
* hello world2
* // run program
* $ deno run --allow-read mod.ts
* hello world
* hello world2
*
*/
deno?: boolean;
@ -1246,8 +1275,10 @@ declare namespace performance {
*
* Use the flag --allow-hrtime return a precise value.
*
* const t = performance.now();
* console.log(`${t} ms since start!`);
* ```ts
* const t = performance.now();
* console.log(`${t} ms since start!`);
* ```
*/
export function now(): number;
}

View file

@ -11,9 +11,11 @@ declare namespace Deno {
* Retrieve the process umask. If `mask` is provided, sets the process umask.
* This call always returns what the umask was before the call.
*
* console.log(Deno.umask()); // e.g. 18 (0o022)
* const prevUmaskValue = Deno.umask(0o077); // e.g. 18 (0o022)
* console.log(Deno.umask()); // e.g. 63 (0o077)
* ```ts
* console.log(Deno.umask()); // e.g. 18 (0o022)
* const prevUmaskValue = Deno.umask(0o077); // e.g. 18 (0o022)
* console.log(Deno.umask()); // e.g. 63 (0o077)
* ```
*
* NOTE: This API is not implemented on Windows
*/
@ -21,7 +23,9 @@ declare namespace Deno {
/** Synchronously creates `newpath` as a hard link to `oldpath`.
*
* Deno.linkSync("old/name", "new/name");
* ```ts
* Deno.linkSync("old/name", "new/name");
* ```
*
* Requires `allow-read` and `allow-write` permissions. */
export function linkSync(oldpath: string, newpath: string): void;
@ -30,7 +34,9 @@ declare namespace Deno {
*
* **UNSTABLE**: needs security review.
*
* await Deno.link("old/name", "new/name");
* ```ts
* await Deno.link("old/name", "new/name");
* ```
*
* Requires `allow-read` and `allow-write` permissions. */
export function link(oldpath: string, newpath: string): Promise<void>;
@ -46,7 +52,9 @@ declare namespace Deno {
*
* NOTE: This function is not yet implemented on Windows.
*
* Deno.symlinkSync("old/name", "new/name");
* ```ts
* Deno.symlinkSync("old/name", "new/name");
* ```
*
* Requires `allow-read` and `allow-write` permissions. */
export function symlinkSync(
@ -66,7 +74,9 @@ declare namespace Deno {
*
* NOTE: This function is not yet implemented on Windows.
*
* await Deno.symlink("old/name", "new/name");
* ```ts
* await Deno.symlink("old/name", "new/name");
* ```
*
* Requires `allow-read` and `allow-write` permissions. */
export function symlink(
@ -100,7 +110,9 @@ declare namespace Deno {
*
* Returns the user and platform specific directories.
*
* const homeDirectory = Deno.dir("home");
* ```ts
* const homeDirectory = Deno.dir("home");
* ```
*
* Requires `allow-env` permission.
*
@ -248,7 +260,9 @@ declare namespace Deno {
* is no load. On Windows, the three values are always the same and represent
* the current load, not the 1, 5 and 15 minute load averages.
*
* console.log(Deno.loadavg()); // e.g. [ 0.71, 0.44, 0.44 ]
* ```ts
* console.log(Deno.loadavg()); // e.g. [ 0.71, 0.44, 0.44 ]
* ```
*
* Requires `allow-env` permission.
*
@ -259,7 +273,9 @@ declare namespace Deno {
/** Returns the release version of the Operating System.
*
* console.log(Deno.osRelease());
* ```ts
* console.log(Deno.osRelease());
* ```
*
* Requires `allow-env` permission.
*
@ -272,10 +288,12 @@ declare namespace Deno {
*
* Open and initialize a plugin.
*
* const rid = Deno.openPlugin("./path/to/some/plugin.so");
* const opId = Deno.core.ops()["some_op"];
* const response = Deno.core.dispatch(opId, new Uint8Array([1,2,3,4]));
* console.log(`Response from plugin ${response}`);
* ```ts
* const rid = Deno.openPlugin("./path/to/some/plugin.so");
* const opId = Deno.core.ops()["some_op"];
* const response = Deno.core.dispatch(opId, new Uint8Array([1,2,3,4]));
* console.log(`Response from plugin ${response}`);
* ```
*
* Requires `allow-plugin` permission.
*
@ -340,9 +358,11 @@ declare namespace Deno {
* Format an array of diagnostic items and return them as a single string in a
* user friendly format.
*
* const [diagnostics, result] = Deno.compile("file_with_compile_issues.ts");
* console.table(diagnostics); // Prints raw diagnostic data
* console.log(Deno.formatDiagnostics(diagnostics)); // User friendly output of diagnostics
* ```ts
* const [diagnostics, result] = Deno.compile("file_with_compile_issues.ts");
* console.table(diagnostics); // Prints raw diagnostic data
* console.log(Deno.formatDiagnostics(diagnostics)); // User friendly output of diagnostics
* ```
*
* @param items An array of diagnostic items to format
*/
@ -541,13 +561,15 @@ declare namespace Deno {
* irrespective of if sources are provided on the call. Like other Deno
* modules, there is no "magical" resolution. For example:
*
* Deno.compile(
* "./foo.js",
* undefined,
* {
* types: [ "./foo.d.ts", "https://deno.land/x/example/types.d.ts" ]
* }
* );
* ```ts
* Deno.compile(
* "./foo.js",
* undefined,
* {
* types: [ "./foo.d.ts", "https://deno.land/x/example/types.d.ts" ]
* }
* );
* ```
*/
types?: string[];
}
@ -569,9 +591,11 @@ declare namespace Deno {
* type checking and validation, it effectively "strips" the types from the
* file.
*
* const results = await Deno.transpileOnly({
* "foo.ts": `const foo: string = "foo";`
* });
* ```ts
* const results = await Deno.transpileOnly({
* "foo.ts": `const foo: string = "foo";`
* });
* ```
*
* @param sources A map where the key is the filename and the value is the text
* to transpile. The filename is only used in the transpile and
@ -598,12 +622,14 @@ declare namespace Deno {
* the key is the module name and the value is the content. The extension of
* the module name will be used to determine the media type of the module.
*
* const [ maybeDiagnostics1, output1 ] = await Deno.compile("foo.ts");
* ```ts
* const [ maybeDiagnostics1, output1 ] = await Deno.compile("foo.ts");
*
* const [ maybeDiagnostics2, output2 ] = await Deno.compile("/foo.ts", {
* "/foo.ts": `export * from "./bar.ts";`,
* "/bar.ts": `export const bar = "bar";`
* });
* const [ maybeDiagnostics2, output2 ] = await Deno.compile("/foo.ts", {
* "/foo.ts": `export * from "./bar.ts";`,
* "/bar.ts": `export const bar = "bar";`
* });
* ```
*
* @param rootName The root name of the module which will be used as the
* "starting point". If no `sources` is specified, Deno will
@ -638,13 +664,15 @@ declare namespace Deno {
* the key is the module name and the value is the content. The extension of the
* module name will be used to determine the media type of the module.
*
* // equivalent to "deno bundle foo.ts" from the command line
* const [ maybeDiagnostics1, output1 ] = await Deno.bundle("foo.ts");
* ```ts
* // equivalent to "deno bundle foo.ts" from the command line
* const [ maybeDiagnostics1, output1 ] = await Deno.bundle("foo.ts");
*
* const [ maybeDiagnostics2, output2 ] = await Deno.bundle("/foo.ts", {
* "/foo.ts": `export * from "./bar.ts";`,
* "/bar.ts": `export const bar = "bar";`
* });
* const [ maybeDiagnostics2, output2 ] = await Deno.bundle("/foo.ts", {
* "/foo.ts": `export * from "./bar.ts";`,
* "/bar.ts": `export const bar = "bar";`
* });
* ```
*
* @param rootName The root name of the module which will be used as the
* "starting point". If no `sources` is specified, Deno will
@ -691,12 +719,14 @@ declare namespace Deno {
*
* An example:
*
* const orig = Deno.applySourceMap({
* fileName: "file://my/module.ts",
* lineNumber: 5,
* columnNumber: 15
* });
* console.log(`${orig.filename}:${orig.line}:${orig.column}`);
* ```ts
* const orig = Deno.applySourceMap({
* fileName: "file://my/module.ts",
* lineNumber: 5,
* columnNumber: 15
* });
* console.log(`${orig.filename}:${orig.line}:${orig.column}`);
* ```
*/
export function applySourceMap(location: Location): Location;
@ -793,24 +823,30 @@ declare namespace Deno {
* Returns the stream of the given signal number. You can use it as an async
* iterator.
*
* for await (const _ of Deno.signal(Deno.Signal.SIGTERM)) {
* console.log("got SIGTERM!");
* }
* ```ts
* for await (const _ of Deno.signal(Deno.Signal.SIGTERM)) {
* console.log("got SIGTERM!");
* }
* ```
*
* You can also use it as a promise. In this case you can only receive the
* first one.
*
* await Deno.signal(Deno.Signal.SIGTERM);
* console.log("SIGTERM received!")
* ```ts
* await Deno.signal(Deno.Signal.SIGTERM);
* console.log("SIGTERM received!")
* ```
*
* If you want to stop receiving the signals, you can use `.dispose()` method
* of the signal stream object.
*
* const sig = Deno.signal(Deno.Signal.SIGTERM);
* setTimeout(() => { sig.dispose(); }, 5000);
* for await (const _ of sig) {
* console.log("SIGTERM!")
* }
* ```ts
* const sig = Deno.signal(Deno.Signal.SIGTERM);
* setTimeout(() => { sig.dispose(); }, 5000);
* for await (const _ of sig) {
* console.log("SIGTERM!")
* }
* ```
*
* The above for-await loop exits after 5 seconds when `sig.dispose()` is
* called.
@ -875,7 +911,9 @@ declare namespace Deno {
* Reading from a TTY device in raw mode is faster than reading from a TTY
* device in canonical mode.
*
* Deno.setRaw(myTTY.rid, true);
* ```ts
* Deno.setRaw(myTTY.rid, true);
* ```
*/
export function setRaw(rid: number, mode: boolean): void;
@ -885,7 +923,9 @@ declare namespace Deno {
* of a file system object referenced by `path`. Given times are either in
* seconds (UNIX epoch time) or as `Date` objects.
*
* Deno.utimeSync("myfile.txt", 1556495550, new Date());
* ```ts
* Deno.utimeSync("myfile.txt", 1556495550, new Date());
* ```
*
* Requires `allow-write` permission. */
export function utimeSync(
@ -900,7 +940,9 @@ declare namespace Deno {
* system object referenced by `path`. Given times are either in seconds
* (UNIX epoch time) or as `Date` objects.
*
* await Deno.utime("myfile.txt", 1556495550, new Date());
* ```ts
* await Deno.utime("myfile.txt", 1556495550, new Date());
* ```
*
* Requires `allow-write` permission. */
export function utime(
@ -927,9 +969,11 @@ declare namespace Deno {
*
* Matches behavior of POSIX shutdown(3).
*
* const listener = Deno.listen({ port: 80 });
* const conn = await listener.accept();
* Deno.shutdown(conn.rid, Deno.ShutdownMode.Write);
* ```ts
* const listener = Deno.listen({ port: 80 });
* const conn = await listener.accept();
* Deno.shutdown(conn.rid, Deno.ShutdownMode.Write);
* ```
*/
export function shutdown(rid: number, how: ShutdownMode): Promise<void>;
@ -964,7 +1008,9 @@ declare namespace Deno {
*
* Listen announces on the local transport address.
*
* const listener = Deno.listen({ path: "/foo/bar.sock", transport: "unix" })
* ```ts
* const listener = Deno.listen({ path: "/foo/bar.sock", transport: "unix" })
* ```
*
* Requires `allow-read` and `allow-write` permission. */
export function listen(
@ -975,15 +1021,17 @@ declare namespace Deno {
*
* Listen announces on the local transport address.
*
* const listener1 = Deno.listenDatagram({
* port: 80,
* transport: "udp"
* });
* const listener2 = Deno.listenDatagram({
* hostname: "golang.org",
* port: 80,
* transport: "udp"
* });
* ```ts
* const listener1 = Deno.listenDatagram({
* port: 80,
* transport: "udp"
* });
* const listener2 = Deno.listenDatagram({
* hostname: "golang.org",
* port: 80,
* transport: "udp"
* });
* ```
*
* Requires `allow-net` permission. */
export function listenDatagram(
@ -994,10 +1042,12 @@ declare namespace Deno {
*
* Listen announces on the local transport address.
*
* const listener = Deno.listenDatagram({
* address: "/foo/bar.sock",
* transport: "unixpacket"
* });
* ```ts
* const listener = Deno.listenDatagram({
* address: "/foo/bar.sock",
* transport: "unixpacket"
* });
* ```
*
* Requires `allow-read` and `allow-write` permission. */
export function listenDatagram(
@ -1013,11 +1063,13 @@ declare namespace Deno {
* Connects to the hostname (default is "127.0.0.1") and port on the named
* transport (default is "tcp"), and resolves to the connection (`Conn`).
*
* const conn1 = await Deno.connect({ port: 80 });
* const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 });
* const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 });
* const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" });
* const conn5 = await Deno.connect({ path: "/foo/bar.sock", transport: "unix" });
* ```ts
* const conn1 = await Deno.connect({ port: 80 });
* const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 });
* const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 });
* const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" });
* const conn5 = await Deno.connect({ path: "/foo/bar.sock", transport: "unix" });
* ```
*
* Requires `allow-net` permission for "tcp" and `allow-read` for unix. */
export function connect(
@ -1041,8 +1093,10 @@ declare namespace Deno {
* Using this function requires that the other end of the connection is
* prepared for TLS handshake.
*
* const conn = await Deno.connect({ port: 80, hostname: "127.0.0.1" });
* const tlsConn = await Deno.startTls(conn, { certFile: "./certs/my_custom_root_CA.pem", hostname: "127.0.0.1", port: 80 });
* ```ts
* const conn = await Deno.connect({ port: 80, hostname: "127.0.0.1" });
* const tlsConn = await Deno.startTls(conn, { certFile: "./certs/my_custom_root_CA.pem", hostname: "127.0.0.1", port: 80 });
* ```
*
* Requires `allow-net` permission.
*/
@ -1138,10 +1192,12 @@ declare namespace Deno {
export class Permissions {
/** Resolves to the current status of a permission.
*
* const status = await Deno.permissions.query({ name: "read", path: "/etc" });
* if (status.state === "granted") {
* data = await Deno.readFile("/etc/passwd");
* }
* ```ts
* const status = await Deno.permissions.query({ name: "read", path: "/etc" });
* if (status.state === "granted") {
* data = await Deno.readFile("/etc/passwd");
* }
* ```
*/
query(desc: PermissionDescriptor): Promise<PermissionStatus>;
@ -1154,12 +1210,14 @@ declare namespace Deno {
/** Requests the permission, and resolves to the state of the permission.
*
* const status = await Deno.permissions.request({ name: "env" });
* if (status.state === "granted") {
* console.log(Deno.homeDir());
* } else {
* console.log("'env' permission is denied.");
* }
* ```ts
* const status = await Deno.permissions.request({ name: "env" });
* if (status.state === "granted") {
* console.log(Deno.homeDir());
* } else {
* console.log("'env' permission is denied.");
* }
* ```
*/
request(desc: PermissionDescriptor): Promise<PermissionStatus>;
}
@ -1177,7 +1235,9 @@ declare namespace Deno {
/** Get the `hostname` of the machine the Deno process is running on.
*
* console.log(Deno.hostname());
* ```ts
* console.log(Deno.hostname());
* ```
*
* Requires `allow-env` permission.
*/