summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/test_runner.rs2
-rw-r--r--docs/linking_to_external_code/reloading_modules.md6
-rw-r--r--std/README.md35
-rw-r--r--std/_util/deep_assign.ts (renamed from std/util/deep_assign.ts)0
-rw-r--r--std/_util/deep_assign_test.ts (renamed from std/util/deep_assign_test.ts)0
-rw-r--r--std/_util/has_own_property.ts (renamed from std/util/has_own_property.ts)0
-rw-r--r--std/async/deferred.ts26
-rw-r--r--std/async/deferred_test.ts8
-rw-r--r--std/async/delay.ts9
-rw-r--r--std/async/mod.ts4
-rw-r--r--std/async/mux_async_iterator.ts58
-rw-r--r--std/async/mux_async_iterator_test.ts28
-rw-r--r--std/encoding/README.md4
-rw-r--r--std/encoding/_yaml/dumper/dumper.ts (renamed from std/encoding/yaml/dumper/dumper.ts)0
-rw-r--r--std/encoding/_yaml/dumper/dumper_state.ts (renamed from std/encoding/yaml/dumper/dumper_state.ts)0
-rw-r--r--std/encoding/_yaml/error.ts (renamed from std/encoding/yaml/error.ts)0
-rw-r--r--std/encoding/_yaml/example/dump.ts (renamed from std/encoding/yaml/example/dump.ts)0
-rw-r--r--std/encoding/_yaml/example/inout.ts (renamed from std/encoding/yaml/example/inout.ts)0
-rw-r--r--std/encoding/_yaml/example/parse.ts (renamed from std/encoding/yaml/example/parse.ts)0
-rw-r--r--std/encoding/_yaml/example/sample_document.ts (renamed from std/encoding/yaml/example/sample_document.ts)0
-rw-r--r--std/encoding/_yaml/example/sample_document.yml (renamed from std/encoding/yaml/example/sample_document.yml)0
-rw-r--r--std/encoding/_yaml/loader/loader.ts (renamed from std/encoding/yaml/loader/loader.ts)0
-rw-r--r--std/encoding/_yaml/loader/loader_state.ts (renamed from std/encoding/yaml/loader/loader_state.ts)0
-rw-r--r--std/encoding/_yaml/mark.ts (renamed from std/encoding/yaml/mark.ts)0
-rw-r--r--std/encoding/_yaml/parse.ts (renamed from std/encoding/yaml/parse.ts)0
-rw-r--r--std/encoding/_yaml/parse_test.ts (renamed from std/encoding/yaml/parse_test.ts)0
-rw-r--r--std/encoding/_yaml/schema.ts (renamed from std/encoding/yaml/schema.ts)0
-rw-r--r--std/encoding/_yaml/schema/core.ts (renamed from std/encoding/yaml/schema/core.ts)0
-rw-r--r--std/encoding/_yaml/schema/default.ts (renamed from std/encoding/yaml/schema/default.ts)0
-rw-r--r--std/encoding/_yaml/schema/failsafe.ts (renamed from std/encoding/yaml/schema/failsafe.ts)0
-rw-r--r--std/encoding/_yaml/schema/json.ts (renamed from std/encoding/yaml/schema/json.ts)0
-rw-r--r--std/encoding/_yaml/schema/mod.ts (renamed from std/encoding/yaml/schema/mod.ts)0
-rw-r--r--std/encoding/_yaml/state.ts (renamed from std/encoding/yaml/state.ts)0
-rw-r--r--std/encoding/_yaml/stringify.ts (renamed from std/encoding/yaml/stringify.ts)0
-rw-r--r--std/encoding/_yaml/stringify_test.ts (renamed from std/encoding/yaml/stringify_test.ts)0
-rw-r--r--std/encoding/_yaml/type.ts (renamed from std/encoding/yaml/type.ts)0
-rw-r--r--std/encoding/_yaml/type/binary.ts (renamed from std/encoding/yaml/type/binary.ts)0
-rw-r--r--std/encoding/_yaml/type/bool.ts (renamed from std/encoding/yaml/type/bool.ts)0
-rw-r--r--std/encoding/_yaml/type/float.ts (renamed from std/encoding/yaml/type/float.ts)0
-rw-r--r--std/encoding/_yaml/type/int.ts (renamed from std/encoding/yaml/type/int.ts)0
-rw-r--r--std/encoding/_yaml/type/map.ts (renamed from std/encoding/yaml/type/map.ts)0
-rw-r--r--std/encoding/_yaml/type/merge.ts (renamed from std/encoding/yaml/type/merge.ts)0
-rw-r--r--std/encoding/_yaml/type/mod.ts (renamed from std/encoding/yaml/type/mod.ts)0
-rw-r--r--std/encoding/_yaml/type/nil.ts (renamed from std/encoding/yaml/type/nil.ts)0
-rw-r--r--std/encoding/_yaml/type/omap.ts (renamed from std/encoding/yaml/type/omap.ts)0
-rw-r--r--std/encoding/_yaml/type/pairs.ts (renamed from std/encoding/yaml/type/pairs.ts)0
-rw-r--r--std/encoding/_yaml/type/seq.ts (renamed from std/encoding/yaml/type/seq.ts)0
-rw-r--r--std/encoding/_yaml/type/set.ts (renamed from std/encoding/yaml/type/set.ts)0
-rw-r--r--std/encoding/_yaml/type/str.ts (renamed from std/encoding/yaml/type/str.ts)0
-rw-r--r--std/encoding/_yaml/type/timestamp.ts (renamed from std/encoding/yaml/type/timestamp.ts)0
-rw-r--r--std/encoding/_yaml/utils.ts (renamed from std/encoding/yaml/utils.ts)0
-rw-r--r--std/encoding/toml.ts2
-rw-r--r--std/encoding/yaml.ts6
-rw-r--r--std/encoding/yaml_test.ts4
-rw-r--r--std/examples/chat/server_test.ts2
-rw-r--r--std/examples/flags.ts (renamed from std/flags/example.ts)6
-rw-r--r--std/flags/README.md13
-rw-r--r--std/flags/mod.ts9
-rw-r--r--std/fs/_util.ts (renamed from std/fs/utils.ts)0
-rw-r--r--std/fs/_util_test.ts (renamed from std/fs/utils_test.ts)2
-rw-r--r--std/fs/copy.ts2
-rw-r--r--std/fs/ensure_dir.ts2
-rw-r--r--std/fs/ensure_file.ts2
-rw-r--r--std/fs/ensure_link.ts2
-rw-r--r--std/fs/ensure_symlink.ts2
-rw-r--r--std/fs/expand_glob.ts3
-rw-r--r--std/fs/move.ts2
-rw-r--r--std/hash/sha1.ts (renamed from std/util/sha1.ts)0
-rw-r--r--std/hash/sha1_test.ts (renamed from std/util/sha1_test.ts)0
-rw-r--r--std/hash/sha256.ts (renamed from std/util/sha256.ts)0
-rw-r--r--std/hash/sha256_test.ts (renamed from std/util/sha256_test.ts)0
-rw-r--r--std/http/_io.ts (renamed from std/http/io.ts)0
-rw-r--r--std/http/_io_test.ts (renamed from std/http/io_test.ts)6
-rw-r--r--std/http/_mock_conn.ts (renamed from std/http/mock.ts)0
-rw-r--r--std/http/racing_server.ts2
-rw-r--r--std/http/server.ts4
-rw-r--r--std/http/server_test.ts4
-rw-r--r--std/io/_iotest.ts (renamed from std/io/iotest.ts)0
-rw-r--r--std/io/bufio_test.ts2
-rw-r--r--std/mime/multipart.ts2
-rw-r--r--std/node/module.ts2
-rw-r--r--std/path/_constants.ts (renamed from std/path/constants.ts)4
-rw-r--r--std/path/_globrex.ts (renamed from std/path/globrex.ts)0
-rw-r--r--std/path/_globrex_test.ts (renamed from std/path/globrex_test.ts)2
-rw-r--r--std/path/_util.ts (renamed from std/path/utils.ts)2
-rw-r--r--std/path/common.ts2
-rw-r--r--std/path/glob.ts4
-rw-r--r--std/path/mod.ts7
-rw-r--r--std/path/posix.ts4
-rw-r--r--std/path/separator.ts4
-rw-r--r--std/path/win32.ts4
-rw-r--r--std/signal/mod.ts2
-rw-r--r--std/signal/test.ts2
-rw-r--r--std/util/async.ts117
-rw-r--r--std/util/async_test.ts76
-rw-r--r--std/uuid/v5.ts2
-rw-r--r--std/ws/example_client.ts84
-rw-r--r--std/ws/example_server.ts78
-rw-r--r--std/ws/mod.ts8
-rw-r--r--std/ws/test.ts2
100 files changed, 303 insertions, 362 deletions
diff --git a/cli/test_runner.rs b/cli/test_runner.rs
index 8ad42d161..3e3ed1291 100644
--- a/cli/test_runner.rs
+++ b/cli/test_runner.rs
@@ -153,9 +153,9 @@ mod tests {
let root_url = Url::from_file_path(root).unwrap().to_string();
println!("root_url {}", root_url);
let expected: Vec<Url> = vec![
+ format!("{}/_io_test.ts", root_url),
format!("{}/cookie_test.ts", root_url),
format!("{}/file_server_test.ts", root_url),
- format!("{}/io_test.ts", root_url),
format!("{}/racing_server_test.ts", root_url),
format!("{}/server_test.ts", root_url),
]
diff --git a/docs/linking_to_external_code/reloading_modules.md b/docs/linking_to_external_code/reloading_modules.md
index 6589ea6bc..886cf5628 100644
--- a/docs/linking_to_external_code/reloading_modules.md
+++ b/docs/linking_to_external_code/reloading_modules.md
@@ -14,9 +14,9 @@ To reload all standard modules
`--reload=https://deno.land/std`
-To reload specific modules (in this example - colors and file system utils) use
-a comma to separate URLs
+To reload specific modules (in this example - colors and file system copy) use a
+comma to separate URLs
-`--reload=https://deno.land/std/fs/utils.ts,https://deno.land/std/fmt/colors.ts`
+`--reload=https://deno.land/std/fs/copy.ts,https://deno.land/std/fmt/colors.ts`
<!-- Should this be part of examples? --
diff --git a/std/README.md b/std/README.md
index 76c4b4545..641146902 100644
--- a/std/README.md
+++ b/std/README.md
@@ -10,28 +10,27 @@ Contributions are welcome!
These modules are tagged in accordance with Deno releases. So, for example, the
v0.3.0 tag is guaranteed to work with deno v0.3.0. You can link to v0.3.0 using
-the URL `https://deno.land/std@v0.3.0/`
+the URL `https://deno.land/std@v0.3.0/`. Not specifying a tag will link to the
+master branch.
-It's strongly recommended that you link to tagged releases rather than the
-master branch. The project is still young and we expect disruptive renames in
-the future.
+It is strongly recommended that you link to tagged releases to avoid unintended
+updates.
+
+Don't link to / import any module whose path:
+
+- Has a name or parent with an underscore prefix: `_foo.ts`, `_util/bar.ts`.
+- Is that of a test module or test data: `test.ts`, `foo_test.ts`,
+ `testdata/bar.txt`.
+
+No stability is guaranteed for these files.
## Documentation
-Here are the dedicated documentations of modules:
-
-- [colors](fmt/colors.ts)
-- [datetime](datetime/README.md)
-- [encoding](encoding/README.md)
-- [examples](examples/README.md)
-- [flags](flags/README.md)
-- [fs](fs/README.md)
-- [http](http/README.md)
-- [log](log/README.md)
-- [node](node/README.md)
-- [testing](testing/README.md)
-- [uuid](uuid/README.md)
-- [ws](ws/README.md)
+To browse documentation for modules:
+
+- Go to https://deno.land/std/.
+- Navigate to any module of interest.
+- Click the "DOCUMENTATION" link.
## Contributing
diff --git a/std/util/deep_assign.ts b/std/_util/deep_assign.ts
index 9034d89bd..9034d89bd 100644
--- a/std/util/deep_assign.ts
+++ b/std/_util/deep_assign.ts
diff --git a/std/util/deep_assign_test.ts b/std/_util/deep_assign_test.ts
index f1a56e1ad..f1a56e1ad 100644
--- a/std/util/deep_assign_test.ts
+++ b/std/_util/deep_assign_test.ts
diff --git a/std/util/has_own_property.ts b/std/_util/has_own_property.ts
index 351905cec..351905cec 100644
--- a/std/util/has_own_property.ts
+++ b/std/_util/has_own_property.ts
diff --git a/std/async/deferred.ts b/std/async/deferred.ts
new file mode 100644
index 000000000..109a1a37e
--- /dev/null
+++ b/std/async/deferred.ts
@@ -0,0 +1,26 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+// TODO(ry) It'd be better to make Deferred a class that inherits from
+// Promise, rather than an interface. This is possible in ES2016, however
+// typescript produces broken code when targeting ES5 code.
+// See https://github.com/Microsoft/TypeScript/issues/15202
+// At the time of writing, the github issue is closed but the problem remains.
+export interface Deferred<T> extends Promise<T> {
+ resolve: (value?: T | PromiseLike<T>) => void;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ reject: (reason?: any) => void;
+}
+
+/** Creates a Promise with the `reject` and `resolve` functions
+ * placed as methods on the promise object itself. It allows you to do:
+ *
+ * const p = deferred<number>();
+ * // ...
+ * p.resolve(42);
+ */
+export function deferred<T>(): Deferred<T> {
+ let methods;
+ const promise = new Promise<T>((resolve, reject): void => {
+ methods = { resolve, reject };
+ });
+ return Object.assign(promise, methods) as Deferred<T>;
+}
diff --git a/std/async/deferred_test.ts b/std/async/deferred_test.ts
new file mode 100644
index 000000000..83c317853
--- /dev/null
+++ b/std/async/deferred_test.ts
@@ -0,0 +1,8 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+import { deferred } from "./deferred.ts";
+
+Deno.test("[async] deferred", function (): Promise<void> {
+ const d = deferred<number>();
+ d.resolve(12);
+ return Promise.resolve();
+});
diff --git a/std/async/delay.ts b/std/async/delay.ts
new file mode 100644
index 000000000..e3aec368f
--- /dev/null
+++ b/std/async/delay.ts
@@ -0,0 +1,9 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+/* Resolves after the given number of milliseconds. */
+export function delay(ms: number): Promise<void> {
+ return new Promise((res): number =>
+ setTimeout((): void => {
+ res();
+ }, ms)
+ );
+}
diff --git a/std/async/mod.ts b/std/async/mod.ts
new file mode 100644
index 000000000..9efead91d
--- /dev/null
+++ b/std/async/mod.ts
@@ -0,0 +1,4 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+export * from "./deferred.ts";
+export * from "./delay.ts";
+export * from "./mux_async_iterator.ts";
diff --git a/std/async/mux_async_iterator.ts b/std/async/mux_async_iterator.ts
new file mode 100644
index 000000000..b32689a29
--- /dev/null
+++ b/std/async/mux_async_iterator.ts
@@ -0,0 +1,58 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+import { Deferred, deferred } from "./deferred.ts";
+
+interface TaggedYieldedValue<T> {
+ iterator: AsyncIterableIterator<T>;
+ value: T;
+}
+
+/** The MuxAsyncIterator class multiplexes multiple async iterators into a
+ * single stream. It currently makes a few assumptions:
+ * - The iterators do not throw.
+ * - The final result (the value returned and not yielded from the iterator)
+ * does not matter; if there is any, it is discarded.
+ */
+export class MuxAsyncIterator<T> implements AsyncIterable<T> {
+ private iteratorCount = 0;
+ private yields: Array<TaggedYieldedValue<T>> = [];
+ private signal: Deferred<void> = deferred();
+
+ add(iterator: AsyncIterableIterator<T>): void {
+ ++this.iteratorCount;
+ this.callIteratorNext(iterator);
+ }
+
+ private async callIteratorNext(
+ iterator: AsyncIterableIterator<T>
+ ): Promise<void> {
+ const { value, done } = await iterator.next();
+ if (done) {
+ --this.iteratorCount;
+ } else {
+ this.yields.push({ iterator, value });
+ }
+ this.signal.resolve();
+ }
+
+ async *iterate(): AsyncIterableIterator<T> {
+ while (this.iteratorCount > 0) {
+ // Sleep until any of the wrapped iterators yields.
+ await this.signal;
+
+ // Note that while we're looping over `yields`, new items may be added.
+ for (let i = 0; i < this.yields.length; i++) {
+ const { iterator, value } = this.yields[i];
+ yield value;
+ this.callIteratorNext(iterator);
+ }
+
+ // Clear the `yields` list and reset the `signal` promise.
+ this.yields.length = 0;
+ this.signal = deferred();
+ }
+ }
+
+ [Symbol.asyncIterator](): AsyncIterableIterator<T> {
+ return this.iterate();
+ }
+}
diff --git a/std/async/mux_async_iterator_test.ts b/std/async/mux_async_iterator_test.ts
new file mode 100644
index 000000000..7017a4eba
--- /dev/null
+++ b/std/async/mux_async_iterator_test.ts
@@ -0,0 +1,28 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+import { assertEquals } from "../testing/asserts.ts";
+import { MuxAsyncIterator } from "./mux_async_iterator.ts";
+
+// eslint-disable-next-line require-await
+async function* gen123(): AsyncIterableIterator<number> {
+ yield 1;
+ yield 2;
+ yield 3;
+}
+
+// eslint-disable-next-line require-await
+async function* gen456(): AsyncIterableIterator<number> {
+ yield 4;
+ yield 5;
+ yield 6;
+}
+
+Deno.test("[async] MuxAsyncIterator", async function (): Promise<void> {
+ const mux = new MuxAsyncIterator<number>();
+ mux.add(gen123());
+ mux.add(gen456());
+ const results = new Set();
+ for await (const value of mux) {
+ results.add(value);
+ }
+ assertEquals(results.size, 6);
+});
diff --git a/std/encoding/README.md b/std/encoding/README.md
index 7d9c89117..973713360 100644
--- a/std/encoding/README.md
+++ b/std/encoding/README.md
@@ -243,9 +243,7 @@ Serializes `object` as a YAML document.
### More example
-See [`./yaml/example`](./yaml/example) folder and [js-yaml] repository.
-
-[js-yaml]: https://github.com/nodeca/js-yaml
+See https://github.com/nodeca/js-yaml.
## base32
diff --git a/std/encoding/yaml/dumper/dumper.ts b/std/encoding/_yaml/dumper/dumper.ts
index 1280ee757..1280ee757 100644
--- a/std/encoding/yaml/dumper/dumper.ts
+++ b/std/encoding/_yaml/dumper/dumper.ts
diff --git a/std/encoding/yaml/dumper/dumper_state.ts b/std/encoding/_yaml/dumper/dumper_state.ts
index 94cd84878..94cd84878 100644
--- a/std/encoding/yaml/dumper/dumper_state.ts
+++ b/std/encoding/_yaml/dumper/dumper_state.ts
diff --git a/std/encoding/yaml/error.ts b/std/encoding/_yaml/error.ts
index 7f305ccf2..7f305ccf2 100644
--- a/std/encoding/yaml/error.ts
+++ b/std/encoding/_yaml/error.ts
diff --git a/std/encoding/yaml/example/dump.ts b/std/encoding/_yaml/example/dump.ts
index db3647274..db3647274 100644
--- a/std/encoding/yaml/example/dump.ts
+++ b/std/encoding/_yaml/example/dump.ts
diff --git a/std/encoding/yaml/example/inout.ts b/std/encoding/_yaml/example/inout.ts
index b0b47e3fe..b0b47e3fe 100644
--- a/std/encoding/yaml/example/inout.ts
+++ b/std/encoding/_yaml/example/inout.ts
diff --git a/std/encoding/yaml/example/parse.ts b/std/encoding/_yaml/example/parse.ts
index fc15daf9c..fc15daf9c 100644
--- a/std/encoding/yaml/example/parse.ts
+++ b/std/encoding/_yaml/example/parse.ts
diff --git a/std/encoding/yaml/example/sample_document.ts b/std/encoding/_yaml/example/sample_document.ts
index da969d679..da969d679 100644
--- a/std/encoding/yaml/example/sample_document.ts
+++ b/std/encoding/_yaml/example/sample_document.ts
diff --git a/std/encoding/yaml/example/sample_document.yml b/std/encoding/_yaml/example/sample_document.yml
index 1f3c2eb3e..1f3c2eb3e 100644
--- a/std/encoding/yaml/example/sample_document.yml
+++ b/std/encoding/_yaml/example/sample_document.yml
diff --git a/std/encoding/yaml/loader/loader.ts b/std/encoding/_yaml/loader/loader.ts
index f0d535624..f0d535624 100644
--- a/std/encoding/yaml/loader/loader.ts
+++ b/std/encoding/_yaml/loader/loader.ts
diff --git a/std/encoding/yaml/loader/loader_state.ts b/std/encoding/_yaml/loader/loader_state.ts
index ca50fcaf1..ca50fcaf1 100644
--- a/std/encoding/yaml/loader/loader_state.ts
+++ b/std/encoding/_yaml/loader/loader_state.ts
diff --git a/std/encoding/yaml/mark.ts b/std/encoding/_yaml/mark.ts
index 44cf175a0..44cf175a0 100644
--- a/std/encoding/yaml/mark.ts
+++ b/std/encoding/_yaml/mark.ts
diff --git a/std/encoding/yaml/parse.ts b/std/encoding/_yaml/parse.ts
index 2aa0042bd..2aa0042bd 100644
--- a/std/encoding/yaml/parse.ts
+++ b/std/encoding/_yaml/parse.ts
diff --git a/std/encoding/yaml/parse_test.ts b/std/encoding/_yaml/parse_test.ts
index 21f1b893b..21f1b893b 100644
--- a/std/encoding/yaml/parse_test.ts
+++ b/std/encoding/_yaml/parse_test.ts
diff --git a/std/encoding/yaml/schema.ts b/std/encoding/_yaml/schema.ts
index 579644dbb..579644dbb 100644
--- a/std/encoding/yaml/schema.ts
+++ b/std/encoding/_yaml/schema.ts
diff --git a/std/encoding/yaml/schema/core.ts b/std/encoding/_yaml/schema/core.ts
index 4fadc9bfe..4fadc9bfe 100644
--- a/std/encoding/yaml/schema/core.ts
+++ b/std/encoding/_yaml/schema/core.ts
diff --git a/std/encoding/yaml/schema/default.ts b/std/encoding/_yaml/schema/default.ts
index 4c5ceeba7..4c5ceeba7 100644
--- a/std/encoding/yaml/schema/default.ts
+++ b/std/encoding/_yaml/schema/default.ts
diff --git a/std/encoding/yaml/schema/failsafe.ts b/std/encoding/_yaml/schema/failsafe.ts
index 74e1897be..74e1897be 100644
--- a/std/encoding/yaml/schema/failsafe.ts
+++ b/std/encoding/_yaml/schema/failsafe.ts
diff --git a/std/encoding/yaml/schema/json.ts b/std/encoding/_yaml/schema/json.ts
index c30166fdf..c30166fdf 100644
--- a/std/encoding/yaml/schema/json.ts
+++ b/std/encoding/_yaml/schema/json.ts
diff --git a/std/encoding/yaml/schema/mod.ts b/std/encoding/_yaml/schema/mod.ts
index 7cbe0c283..7cbe0c283 100644
--- a/std/encoding/yaml/schema/mod.ts
+++ b/std/encoding/_yaml/schema/mod.ts
diff --git a/std/encoding/yaml/state.ts b/std/encoding/_yaml/state.ts
index 6df6dc047..6df6dc047 100644
--- a/std/encoding/yaml/state.ts
+++ b/std/encoding/_yaml/state.ts
diff --git a/std/encoding/yaml/stringify.ts b/std/encoding/_yaml/stringify.ts
index f037631d9..f037631d9 100644
--- a/std/encoding/yaml/stringify.ts
+++ b/std/encoding/_yaml/stringify.ts
diff --git a/std/encoding/yaml/stringify_test.ts b/std/encoding/_yaml/stringify_test.ts
index 03a3090d9..03a3090d9 100644
--- a/std/encoding/yaml/stringify_test.ts
+++ b/std/encoding/_yaml/stringify_test.ts
diff --git a/std/encoding/yaml/type.ts b/std/encoding/_yaml/type.ts
index 4a2c6bbac..4a2c6bbac 100644
--- a/std/encoding/yaml/type.ts
+++ b/std/encoding/_yaml/type.ts
diff --git a/std/encoding/yaml/type/binary.ts b/std/encoding/_yaml/type/binary.ts
index f4823b3f7..f4823b3f7 100644
--- a/std/encoding/yaml/type/binary.ts
+++ b/std/encoding/_yaml/type/binary.ts
diff --git a/std/encoding/yaml/type/bool.ts b/std/encoding/_yaml/type/bool.ts
index a5a85cf9e..a5a85cf9e 100644
--- a/std/encoding/yaml/type/bool.ts
+++ b/std/encoding/_yaml/type/bool.ts
diff --git a/std/encoding/yaml/type/float.ts b/std/encoding/_yaml/type/float.ts
index 5ae0689b2..5ae0689b2 100644
--- a/std/encoding/yaml/type/float.ts
+++ b/std/encoding/_yaml/type/float.ts
diff --git a/std/encoding/yaml/type/int.ts b/std/encoding/_yaml/type/int.ts
index 6a86aafe9..6a86aafe9 100644
--- a/std/encoding/yaml/type/int.ts
+++ b/std/encoding/_yaml/type/int.ts
diff --git a/std/encoding/yaml/type/map.ts b/std/encoding/_yaml/type/map.ts
index dcd99abca..dcd99abca 100644
--- a/std/encoding/yaml/type/map.ts
+++ b/std/encoding/_yaml/type/map.ts
diff --git a/std/encoding/yaml/type/merge.ts b/std/encoding/_yaml/type/merge.ts
index 68314bf2e..68314bf2e 100644
--- a/std/encoding/yaml/type/merge.ts
+++ b/std/encoding/_yaml/type/merge.ts
diff --git a/std/encoding/yaml/type/mod.ts b/std/encoding/_yaml/type/mod.ts
index 15f33301e..15f33301e 100644
--- a/std/encoding/yaml/type/mod.ts
+++ b/std/encoding/_yaml/type/mod.ts
diff --git a/std/encoding/yaml/type/nil.ts b/std/encoding/_yaml/type/nil.ts
index 8a48d02fb..8a48d02fb 100644
--- a/std/encoding/yaml/type/nil.ts
+++ b/std/encoding/_yaml/type/nil.ts
diff --git a/std/encoding/yaml/type/omap.ts b/std/encoding/_yaml/type/omap.ts
index d6d751505..d6d751505 100644
--- a/std/encoding/yaml/type/omap.ts
+++ b/std/encoding/_yaml/type/omap.ts
diff --git a/std/encoding/yaml/type/pairs.ts b/std/encoding/_yaml/type/pairs.ts
index e999748ae..e999748ae 100644
--- a/std/encoding/yaml/type/pairs.ts
+++ b/std/encoding/_yaml/type/pairs.ts
diff --git a/std/encoding/yaml/type/seq.ts b/std/encoding/_yaml/type/seq.ts
index b19565dbc..b19565dbc 100644
--- a/std/encoding/yaml/type/seq.ts
+++ b/std/encoding/_yaml/type/seq.ts
diff --git a/std/encoding/yaml/type/set.ts b/std/encoding/_yaml/type/set.ts
index 0bfe1c8db..0bfe1c8db 100644
--- a/std/encoding/yaml/type/set.ts
+++ b/std/encoding/_yaml/type/set.ts
diff --git a/std/encoding/yaml/type/str.ts b/std/encoding/_yaml/type/str.ts
index cd6e9430f..cd6e9430f 100644
--- a/std/encoding/yaml/type/str.ts
+++ b/std/encoding/_yaml/type/str.ts
diff --git a/std/encoding/yaml/type/timestamp.ts b/std/encoding/_yaml/type/timestamp.ts
index eb03b3825..eb03b3825 100644
--- a/std/encoding/yaml/type/timestamp.ts
+++ b/std/encoding/_yaml/type/timestamp.ts
diff --git a/std/encoding/yaml/utils.ts b/std/encoding/_yaml/utils.ts
index 4630a45a2..4630a45a2 100644
--- a/std/encoding/yaml/utils.ts
+++ b/std/encoding/_yaml/utils.ts
diff --git a/std/encoding/toml.ts b/std/encoding/toml.ts
index ce4519572..7e44bdc18 100644
--- a/std/encoding/toml.ts
+++ b/std/encoding/toml.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { deepAssign } from "../util/deep_assign.ts";
+import { deepAssign } from "../_util/deep_assign.ts";
import { assert } from "../testing/asserts.ts";
class KeyValuePair {
diff --git a/std/encoding/yaml.ts b/std/encoding/yaml.ts
index 76b1b8379..abe210d85 100644
--- a/std/encoding/yaml.ts
+++ b/std/encoding/yaml.ts
@@ -3,9 +3,9 @@
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-export { ParseOptions, parse, parseAll } from "./yaml/parse.ts";
+export { ParseOptions, parse, parseAll } from "./_yaml/parse.ts";
export {
DumpOptions as StringifyOptions,
stringify,
-} from "./yaml/stringify.ts";
-export * from "./yaml/schema/mod.ts";
+} from "./_yaml/stringify.ts";
+export { Schema, SchemaDefinition, TypeMap } from "./_yaml/schema/mod.ts";
diff --git a/std/encoding/yaml_test.ts b/std/encoding/yaml_test.ts
index a5a8374cc..d65be604c 100644
--- a/std/encoding/yaml_test.ts
+++ b/std/encoding/yaml_test.ts
@@ -1,4 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import "./yaml/parse_test.ts";
-import "./yaml/stringify_test.ts";
+import "./_yaml/parse_test.ts";
+import "./_yaml/stringify_test.ts";
diff --git a/std/examples/chat/server_test.ts b/std/examples/chat/server_test.ts
index 92eb50f92..7375de47a 100644
--- a/std/examples/chat/server_test.ts
+++ b/std/examples/chat/server_test.ts
@@ -3,7 +3,7 @@ import { assert, assertEquals } from "../../testing/asserts.ts";
import { TextProtoReader } from "../../textproto/mod.ts";
import { BufReader } from "../../io/bufio.ts";
import { connectWebSocket, WebSocket } from "../../ws/mod.ts";
-import { delay } from "../../util/async.ts";
+import { delay } from "../../async/delay.ts";
const { test } = Deno;
diff --git a/std/flags/example.ts b/std/examples/flags.ts
index ad0317269..4625b8c96 100644
--- a/std/flags/example.ts
+++ b/std/examples/flags.ts
@@ -1,5 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
const { args } = Deno;
-import { parse } from "./mod.ts";
+import { parse } from "../flags/mod.ts";
-console.dir(parse(args));
+if (import.meta.main) {
+ console.dir(parse(args));
+}
diff --git a/std/flags/README.md b/std/flags/README.md
index e9764f913..0b7f7fa65 100644
--- a/std/flags/README.md
+++ b/std/flags/README.md
@@ -12,12 +12,12 @@ console.dir(parse(args));
```
```
-$ deno run example.ts -a beep -b boop
+$ deno run https://deno.land/std/examples/flags.ts -a beep -b boop
{ _: [], a: 'beep', b: 'boop' }
```
```
-$ deno run example.ts -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
+$ deno run https://deno.land/std/examples/flags.ts -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
{ _: [ 'foo', 'bar', 'baz' ],
x: 3,
y: 4,
@@ -56,16 +56,13 @@ options can be:
the `--` and `parsedArgs['--']` with everything after the `--`. Here's an
example:
```ts
+ // $ deno run example.ts -- a arg1
const { args } = Deno;
import { parse } from "https://deno.land/std/flags/mod.ts";
- // options['--'] is now set to false
console.dir(parse(args, { "--": false }));
- // $ deno run example.ts -- a arg1
- // output: { _: [ "example.ts", "a", "arg1" ] }
- // options['--'] is now set to true
+ // output: { _: [ "a", "arg1" ] }
console.dir(parse(args, { "--": true }));
- // $ deno run example.ts -- a arg1
- // output: { _: [ "example.ts" ], --: [ "a", "arg1" ] }
+ // output: { _: [], --: [ "a", "arg1" ] }
```
- `options.unknown` - a function which is invoked with a command line parameter
not defined in the `options` configuration object. If the function returns
diff --git a/std/flags/mod.ts b/std/flags/mod.ts
index 0563dab61..e3680087d 100644
--- a/std/flags/mod.ts
+++ b/std/flags/mod.ts
@@ -14,16 +14,13 @@ export interface ArgParsingOptions {
/** When `true`, populate the result `_` with everything before the `--` and
* the result `['--']` with everything after the `--`. Here's an example:
*
+ * // $ deno run example.ts -- a arg1
* const { args } = Deno;
* import { parse } from "https://deno.land/std/flags/mod.ts";
- * // options['--'] is now set to false
* console.dir(parse(args, { "--": false }));
- * // $ deno run example.ts -- a arg1
- * // output: { _: [ "example.ts", "a", "arg1" ] }
- * // options['--'] is now set to true
+ * // output: { _: [ "a", "arg1" ] }
* console.dir(parse(args, { "--": true }));
- * // $ deno run example.ts -- a arg1
- * // output: { _: [ "example.ts" ], --: [ "a", "arg1" ] }
+ * // output: { _: [], --: [ "a", "arg1" ] }
*
* Defaults to `false`.
*/
diff --git a/std/fs/utils.ts b/std/fs/_util.ts
index 48a98a0b1..48a98a0b1 100644
--- a/std/fs/utils.ts
+++ b/std/fs/_util.ts
diff --git a/std/fs/utils_test.ts b/std/fs/_util_test.ts
index e104e3e7d..48fc33ecd 100644
--- a/std/fs/utils_test.ts
+++ b/std/fs/_util_test.ts
@@ -2,7 +2,7 @@
import { assertEquals } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
-import { isSubdir, getFileInfoType, PathType } from "./utils.ts";
+import { isSubdir, getFileInfoType, PathType } from "./_util.ts";
import { ensureFileSync } from "./ensure_file.ts";
import { ensureDirSync } from "./ensure_dir.ts";
diff --git a/std/fs/copy.ts b/std/fs/copy.ts
index 609a8437b..85558d905 100644
--- a/std/fs/copy.ts
+++ b/std/fs/copy.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
-import { isSubdir, getFileInfoType } from "./utils.ts";
+import { isSubdir, getFileInfoType } from "./_util.ts";
import { assert } from "../testing/asserts.ts";
export interface CopyOptions {
diff --git a/std/fs/ensure_dir.ts b/std/fs/ensure_dir.ts
index ecc7356ef..34053b157 100644
--- a/std/fs/ensure_dir.ts
+++ b/std/fs/ensure_dir.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { getFileInfoType } from "./utils.ts";
+import { getFileInfoType } from "./_util.ts";
const { lstat, lstatSync, mkdir, mkdirSync } = Deno;
/**
diff --git a/std/fs/ensure_file.ts b/std/fs/ensure_file.ts
index de6cab500..2539c71ac 100644
--- a/std/fs/ensure_file.ts
+++ b/std/fs/ensure_file.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
-import { getFileInfoType } from "./utils.ts";
+import { getFileInfoType } from "./_util.ts";
const { lstat, lstatSync, writeFile, writeFileSync } = Deno;
/**
diff --git a/std/fs/ensure_link.ts b/std/fs/ensure_link.ts
index e43325a25..f446df781 100644
--- a/std/fs/ensure_link.ts
+++ b/std/fs/ensure_link.ts
@@ -2,7 +2,7 @@
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { exists, existsSync } from "./exists.ts";
-import { getFileInfoType } from "./utils.ts";
+import { getFileInfoType } from "./_util.ts";
/**
* Ensures that the hard link exists.
diff --git a/std/fs/ensure_symlink.ts b/std/fs/ensure_symlink.ts
index 03c355b5d..2a184bb4f 100644
--- a/std/fs/ensure_symlink.ts
+++ b/std/fs/ensure_symlink.ts
@@ -2,7 +2,7 @@
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { exists, existsSync } from "./exists.ts";
-import { getFileInfoType } from "./utils.ts";
+import { getFileInfoType } from "./_util.ts";
/**
* Ensures that the link exists.
diff --git a/std/fs/expand_glob.ts b/std/fs/expand_glob.ts
index 803c67cdf..e5abdabcf 100644
--- a/std/fs/expand_glob.ts
+++ b/std/fs/expand_glob.ts
@@ -4,7 +4,6 @@ import {
globToRegExp,
isAbsolute,
isGlob,
- isWindows,
joinGlobs,
normalize,
} from "../path/mod.ts";
@@ -19,6 +18,8 @@ import { assert } from "../testing/asserts.ts";
const { cwd } = Deno;
type FileInfo = Deno.FileInfo;
+const isWindows = Deno.build.os == "windows";
+
export interface ExpandGlobOptions extends GlobOptions {
root?: string;
exclude?: string[];
diff --git a/std/fs/move.ts b/std/fs/move.ts
index cf1e49193..4a6395365 100644
--- a/std/fs/move.ts
+++ b/std/fs/move.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { exists, existsSync } from "./exists.ts";
-import { isSubdir } from "./utils.ts";
+import { isSubdir } from "./_util.ts";
interface MoveOptions {
overwrite?: boolean;
diff --git a/std/util/sha1.ts b/std/hash/sha1.ts
index f47192554..f47192554 100644
--- a/std/util/sha1.ts
+++ b/std/hash/sha1.ts
diff --git a/std/util/sha1_test.ts b/std/hash/sha1_test.ts
index 159bdd94d..159bdd94d 100644
--- a/std/util/sha1_test.ts
+++ b/std/hash/sha1_test.ts
diff --git a/std/util/sha256.ts b/std/hash/sha256.ts
index 02fff94d1..02fff94d1 100644
--- a/std/util/sha256.ts
+++ b/std/hash/sha256.ts
diff --git a/std/util/sha256_test.ts b/std/hash/sha256_test.ts
index a38786943..a38786943 100644
--- a/std/util/sha256_test.ts
+++ b/std/hash/sha256_test.ts
diff --git a/std/http/io.ts b/std/http/_io.ts
index 631adafd0..631adafd0 100644
--- a/std/http/io.ts
+++ b/std/http/_io.ts
diff --git a/std/http/io_test.ts b/std/http/_io_test.ts
index c0f57a1b7..c22ebdf07 100644
--- a/std/http/io_test.ts
+++ b/std/http/_io_test.ts
@@ -7,18 +7,18 @@ import {
} from "../testing/asserts.ts";
import {
bodyReader,
+ chunkedBodyReader,
writeTrailers,
readTrailers,
parseHTTPVersion,
readRequest,
writeResponse,
-} from "./io.ts";
+} from "./_io.ts";
import { encode, decode } from "../encoding/utf8.ts";
import { BufReader, ReadLineResult } from "../io/bufio.ts";
-import { chunkedBodyReader } from "./io.ts";
import { ServerRequest, Response } from "./server.ts";
import { StringReader } from "../io/readers.ts";
-import { mockConn } from "./mock.ts";
+import { mockConn } from "./_mock_conn.ts";
const { Buffer, test, readAll } = Deno;
test("bodyReader", async () => {
diff --git a/std/http/mock.ts b/std/http/_mock_conn.ts
index be07ede24..be07ede24 100644
--- a/std/http/mock.ts
+++ b/std/http/_mock_conn.ts
diff --git a/std/http/racing_server.ts b/std/http/racing_server.ts
index 0b0e5a8a5..67db029e0 100644
--- a/std/http/racing_server.ts
+++ b/std/http/racing_server.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { serve, ServerRequest } from "./server.ts";
-import { delay } from "../util/async.ts";
+import { delay } from "../async/delay.ts";
const addr = Deno.args[1] || "127.0.0.1:4501";
const server = serve(addr);
diff --git a/std/http/server.ts b/std/http/server.ts
index 9c678ad3d..a372b39a5 100644
--- a/std/http/server.ts
+++ b/std/http/server.ts
@@ -2,14 +2,14 @@
import { encode } from "../encoding/utf8.ts";
import { BufReader, BufWriter } from "../io/bufio.ts";
import { assert } from "../testing/asserts.ts";
-import { deferred, Deferred, MuxAsyncIterator } from "../util/async.ts";
+import { deferred, Deferred, MuxAsyncIterator } from "../async/mod.ts";
import {
bodyReader,
chunkedBodyReader,
emptyReader,
writeResponse,
readRequest,
-} from "./io.ts";
+} from "./_io.ts";
import Listener = Deno.Listener;
import Conn = Deno.Conn;
import Reader = Deno.Reader;
diff --git a/std/http/server_test.ts b/std/http/server_test.ts
index 03256dd25..807695c6b 100644
--- a/std/http/server_test.ts
+++ b/std/http/server_test.ts
@@ -15,9 +15,9 @@ import {
} from "../testing/asserts.ts";
import { Response, ServerRequest, Server, serve } from "./server.ts";
import { BufReader, BufWriter } from "../io/bufio.ts";
-import { delay } from "../util/async.ts";
+import { delay } from "../async/delay.ts";
import { encode, decode } from "../encoding/utf8.ts";
-import { mockConn } from "./mock.ts";
+import { mockConn } from "./_mock_conn.ts";
const { Buffer, test } = Deno;
diff --git a/std/io/iotest.ts b/std/io/_iotest.ts
index a309fb5e1..a309fb5e1 100644
--- a/std/io/iotest.ts
+++ b/std/io/_iotest.ts
diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts
index 17cc873fd..c49023814 100644
--- a/std/io/bufio_test.ts
+++ b/std/io/bufio_test.ts
@@ -15,7 +15,7 @@ import {
readStringDelim,
readLines,
} from "./bufio.ts";
-import * as iotest from "./iotest.ts";
+import * as iotest from "./_iotest.ts";
import { charCode, copyBytes, stringsReader } from "./util.ts";
const encoder = new TextEncoder();
diff --git a/std/mime/multipart.ts b/std/mime/multipart.ts
index 6aadef938..61faebefd 100644
--- a/std/mime/multipart.ts
+++ b/std/mime/multipart.ts
@@ -14,7 +14,7 @@ import { BufReader, BufWriter } from "../io/bufio.ts";
import { encoder } from "../encoding/utf8.ts";
import { assertStrictEq, assert } from "../testing/asserts.ts";
import { TextProtoReader } from "../textproto/mod.ts";
-import { hasOwnProperty } from "../util/has_own_property.ts";
+import { hasOwnProperty } from "../_util/has_own_property.ts";
/** FormFile object */
export interface FormFile {
diff --git a/std/node/module.ts b/std/node/module.ts
index 8969e80d9..f777e658f 100644
--- a/std/node/module.ts
+++ b/std/node/module.ts
@@ -36,7 +36,7 @@ const CHAR_FORWARD_SLASH = "/".charCodeAt(0);
const CHAR_BACKWARD_SLASH = "\\".charCodeAt(0);
const CHAR_COLON = ":".charCodeAt(0);
-const isWindows = path.isWindows;
+const isWindows = Deno.build.os == "windows";
const relativeResolveCache = Object.create(null);
diff --git a/std/path/constants.ts b/std/path/_constants.ts
index 97d3bcf58..ae0aac184 100644
--- a/std/path/constants.ts
+++ b/std/path/_constants.ts
@@ -48,7 +48,7 @@ export const CHAR_EQUAL = 61; /* = */
export const CHAR_0 = 48; /* 0 */
export const CHAR_9 = 57; /* 9 */
-export const isWindows = build.os === "windows";
-export const EOL = isWindows ? "\r\n" : "\n";
+const isWindows = build.os == "windows";
+
export const SEP = isWindows ? "\\" : "/";
export const SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/;
diff --git a/std/path/globrex.ts b/std/path/_globrex.ts
index 3fc69dd6c..3fc69dd6c 100644
--- a/std/path/globrex.ts
+++ b/std/path/_globrex.ts
diff --git a/std/path/globrex_test.ts b/std/path/_globrex_test.ts
index c52ed108e..2974b4719 100644
--- a/std/path/globrex_test.ts
+++ b/std/path/_globrex_test.ts
@@ -4,7 +4,7 @@
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
-import { GlobrexOptions, globrex } from "./globrex.ts";
+import { GlobrexOptions, globrex } from "./_globrex.ts";
const isWin = Deno.build.os === "windows";
const t = { equal: assertEquals, is: assertEquals };
diff --git a/std/path/utils.ts b/std/path/_util.ts
index fc3dc5be9..2776303cb 100644
--- a/std/path/utils.ts
+++ b/std/path/_util.ts
@@ -10,7 +10,7 @@ import {
CHAR_DOT,
CHAR_FORWARD_SLASH,
CHAR_BACKWARD_SLASH,
-} from "./constants.ts";
+} from "./_constants.ts";
export function assertPath(path: string): void {
if (typeof path !== "string") {
diff --git a/std/path/common.ts b/std/path/common.ts
index 0a4de3f0c..e0e51ef23 100644
--- a/std/path/common.ts
+++ b/std/path/common.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { SEP } from "./constants.ts";
+import { SEP } from "./separator.ts";
/** Determines the common path from a set of paths, using an optional separator,
* which defaults to the OS default separator.
diff --git a/std/path/glob.ts b/std/path/glob.ts
index a11865c26..80672579d 100644
--- a/std/path/glob.ts
+++ b/std/path/glob.ts
@@ -1,5 +1,5 @@
-import { SEP, SEP_PATTERN } from "./constants.ts";
-import { globrex } from "./globrex.ts";
+import { SEP, SEP_PATTERN } from "./separator.ts";
+import { globrex } from "./_globrex.ts";
import { join, normalize } from "./mod.ts";
import { assert } from "../testing/asserts.ts";
diff --git a/std/path/mod.ts b/std/path/mod.ts
index 104e0b616..9cb7f1edb 100644
--- a/std/path/mod.ts
+++ b/std/path/mod.ts
@@ -4,7 +4,7 @@
import * as _win32 from "./win32.ts";
import * as _posix from "./posix.ts";
-import { isWindows } from "./constants.ts";
+const isWindows = Deno.build.os == "windows";
const path = isWindows ? _win32 : _posix;
@@ -27,8 +27,7 @@ export const {
toNamespacedPath,
} = path;
-export { common } from "./common.ts";
-export { EOL, SEP, SEP_PATTERN, isWindows } from "./constants.ts";
+export * from "./common.ts";
+export { SEP, SEP_PATTERN } from "./separator.ts";
export * from "./interface.ts";
export * from "./glob.ts";
-export * from "./globrex.ts";
diff --git a/std/path/posix.ts b/std/path/posix.ts
index 156aba796..e88eb3f97 100644
--- a/std/path/posix.ts
+++ b/std/path/posix.ts
@@ -3,14 +3,14 @@
const { cwd } = Deno;
import { FormatInputPathObject, ParsedPath } from "./interface.ts";
-import { CHAR_DOT, CHAR_FORWARD_SLASH } from "./constants.ts";
+import { CHAR_DOT, CHAR_FORWARD_SLASH } from "./_constants.ts";
import {
assertPath,
normalizeString,
isPosixPathSeparator,
_format,
-} from "./utils.ts";
+} from "./_util.ts";
export const sep = "/";
export const delimiter = ":";
diff --git a/std/path/separator.ts b/std/path/separator.ts
new file mode 100644
index 000000000..fb990b808
--- /dev/null
+++ b/std/path/separator.ts
@@ -0,0 +1,4 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+const isWindows = Deno.build.os == "windows";
+export const SEP = isWindows ? "\\" : "/";
+export const SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/;
diff --git a/std/path/win32.ts b/std/path/win32.ts
index 401e572db..0557b3768 100644
--- a/std/path/win32.ts
+++ b/std/path/win32.ts
@@ -8,7 +8,7 @@ import {
CHAR_BACKWARD_SLASH,
CHAR_COLON,
CHAR_QUESTION_MARK,
-} from "./constants.ts";
+} from "./_constants.ts";
import {
assertPath,
@@ -16,7 +16,7 @@ import {
isWindowsDeviceRoot,
normalizeString,
_format,
-} from "./utils.ts";
+} from "./_util.ts";
import { assert } from "../testing/asserts.ts";
export const sep = "\\";
diff --git a/std/signal/mod.ts b/std/signal/mod.ts
index a463142e6..c15d1b326 100644
--- a/std/signal/mod.ts
+++ b/std/signal/mod.ts
@@ -1,4 +1,4 @@
-import { MuxAsyncIterator } from "../util/async.ts";
+import { MuxAsyncIterator } from "../async/mux_async_iterator.ts";
export type Disposable = { dispose: () => void };
diff --git a/std/signal/test.ts b/std/signal/test.ts
index c4d1bf3a7..15ebbdcc7 100644
--- a/std/signal/test.ts
+++ b/std/signal/test.ts
@@ -1,6 +1,6 @@
const { test } = Deno;
import { assertEquals, assertThrows } from "../testing/asserts.ts";
-import { delay } from "../util/async.ts";
+import { delay } from "../async/delay.ts";
import { signal, onSignal } from "./mod.ts";
test({
diff --git a/std/util/async.ts b/std/util/async.ts
deleted file mode 100644
index bb50e482d..000000000
--- a/std/util/async.ts
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-
-// TODO(ry) It'd be better to make Deferred a class that inherits from
-// Promise, rather than an interface. This is possible in ES2016, however
-// typescript produces broken code when targeting ES5 code.
-// See https://github.com/Microsoft/TypeScript/issues/15202
-// At the time of writing, the github issue is closed but the problem remains.
-export interface Deferred<T> extends Promise<T> {
- resolve: (value?: T | PromiseLike<T>) => void;
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- reject: (reason?: any) => void;
-}
-
-/** Creates a Promise with the `reject` and `resolve` functions
- * placed as methods on the promise object itself. It allows you to do:
- *
- * const p = deferred<number>();
- * // ...
- * p.resolve(42);
- */
-export function deferred<T>(): Deferred<T> {
- let methods;
- const promise = new Promise<T>((resolve, reject): void => {
- methods = { resolve, reject };
- });
- return Object.assign(promise, methods) as Deferred<T>;
-}
-
-interface TaggedYieldedValue<T> {
- iterator: AsyncIterableIterator<T>;
- value: T;
-}
-
-/** The MuxAsyncIterator class multiplexes multiple async iterators into a
- * single stream. It currently makes a few assumptions:
- * - The iterators do not throw.
- * - The final result (the value returned and not yielded from the iterator)
- * does not matter; if there is any, it is discarded.
- */
-export class MuxAsyncIterator<T> implements AsyncIterable<T> {
- private iteratorCount = 0;
- private yields: Array<TaggedYieldedValue<T>> = [];
- private signal: Deferred<void> = deferred();
-
- add(iterator: AsyncIterableIterator<T>): void {
- ++this.iteratorCount;
- this.callIteratorNext(iterator);
- }
-
- private async callIteratorNext(
- iterator: AsyncIterableIterator<T>
- ): Promise<void> {
- const { value, done } = await iterator.next();
- if (done) {
- --this.iteratorCount;
- } else {
- this.yields.push({ iterator, value });
- }
- this.signal.resolve();
- }
-
- async *iterate(): AsyncIterableIterator<T> {
- while (this.iteratorCount > 0) {
- // Sleep until any of the wrapped iterators yields.
- await this.signal;
-
- // Note that while we're looping over `yields`, new items may be added.
- for (let i = 0; i < this.yields.length; i++) {
- const { iterator, value } = this.yields[i];
- yield value;
- this.callIteratorNext(iterator);
- }
-
- // Clear the `yields` list and reset the `signal` promise.
- this.yields.length = 0;
- this.signal = deferred();
- }
- }
-
- [Symbol.asyncIterator](): AsyncIterableIterator<T> {
- return this.iterate();
- }
-}
-
-/** Collects all Uint8Arrays from an AsyncIterable and retuns a single
- * Uint8Array with the concatenated contents of all the collected arrays.
- */
-export async function collectUint8Arrays(
- it: AsyncIterable<Uint8Array>
-): Promise<Uint8Array> {
- const chunks = [];
- let length = 0;
- for await (const chunk of it) {
- chunks.push(chunk);
- length += chunk.length;
- }
- if (chunks.length === 1) {
- // No need to copy.
- return chunks[0];
- }
- const collected = new Uint8Array(length);
- let offset = 0;
- for (const chunk of chunks) {
- collected.set(chunk, offset);
- offset += chunk.length;
- }
- return collected;
-}
-
-// Delays the given milliseconds and resolves.
-export function delay(ms: number): Promise<void> {
- return new Promise((res): number =>
- setTimeout((): void => {
- res();
- }, ms)
- );
-}
diff --git a/std/util/async_test.ts b/std/util/async_test.ts
deleted file mode 100644
index f3f17312a..000000000
--- a/std/util/async_test.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { test } = Deno;
-import { assert, assertEquals, assertStrictEq } from "../testing/asserts.ts";
-import { collectUint8Arrays, deferred, MuxAsyncIterator } from "./async.ts";
-
-test("asyncDeferred", function (): Promise<void> {
- const d = deferred<number>();
- d.resolve(12);
- return Promise.resolve();
-});
-
-// eslint-disable-next-line require-await
-async function* gen123(): AsyncIterableIterator<number> {
- yield 1;
- yield 2;
- yield 3;
-}
-
-// eslint-disable-next-line require-await
-async function* gen456(): AsyncIterableIterator<number> {
- yield 4;
- yield 5;
- yield 6;
-}
-
-test("asyncMuxAsyncIterator", async function (): Promise<void> {
- const mux = new MuxAsyncIterator<number>();
- mux.add(gen123());
- mux.add(gen456());
- const results = new Set();
- for await (const value of mux) {
- results.add(value);
- }
- assertEquals(results.size, 6);
-});
-
-test("collectUint8Arrays0", async function (): Promise<void> {
- async function* gen(): AsyncIterableIterator<Uint8Array> {}
- const result = await collectUint8Arrays(gen());
- assert(result instanceof Uint8Array);
- assertEquals(result.length, 0);
-});
-
-test("collectUint8Arrays0", async function (): Promise<void> {
- async function* gen(): AsyncIterableIterator<Uint8Array> {}
- const result = await collectUint8Arrays(gen());
- assert(result instanceof Uint8Array);
- assertStrictEq(result.length, 0);
-});
-
-test("collectUint8Arrays1", async function (): Promise<void> {
- const buf = new Uint8Array([1, 2, 3]);
- // eslint-disable-next-line require-await
- async function* gen(): AsyncIterableIterator<Uint8Array> {
- yield buf;
- }
- const result = await collectUint8Arrays(gen());
- assertStrictEq(result, buf);
- assertStrictEq(result.length, 3);
-});
-
-test("collectUint8Arrays4", async function (): Promise<void> {
- // eslint-disable-next-line require-await
- async function* gen(): AsyncIterableIterator<Uint8Array> {
- yield new Uint8Array([1, 2, 3]);
- yield new Uint8Array([]);
- yield new Uint8Array([4, 5]);
- yield new Uint8Array([6]);
- }
- const result = await collectUint8Arrays(gen());
- assert(result instanceof Uint8Array);
- assertStrictEq(result.length, 6);
- for (let i = 0; i < 6; i++) {
- assertStrictEq(result[i], i + 1);
- }
-});
diff --git a/std/uuid/v5.ts b/std/uuid/v5.ts
index 1216762dd..3c04873fe 100644
--- a/std/uuid/v5.ts
+++ b/std/uuid/v5.ts
@@ -6,7 +6,7 @@ import {
stringToBytes,
uuidToBytes,
} from "./_common.ts";
-import { Sha1 } from "../util/sha1.ts";
+import { Sha1 } from "../hash/sha1.ts";
import { isString } from "../node/util.ts";
import { assert } from "../testing/asserts.ts";
diff --git a/std/ws/example_client.ts b/std/ws/example_client.ts
index 4213025f4..93f2f5c7b 100644
--- a/std/ws/example_client.ts
+++ b/std/ws/example_client.ts
@@ -3,57 +3,59 @@ import {
isWebSocketCloseEvent,
isWebSocketPingEvent,
isWebSocketPongEvent,
-} from "../ws/mod.ts";
+} from "./mod.ts";
import { encode } from "../encoding/utf8.ts";
import { BufReader } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
import { blue, green, red, yellow } from "../fmt/colors.ts";
-const endpoint = Deno.args[0] || "ws://127.0.0.1:8080";
-/** simple websocket cli */
-try {
- const sock = await connectWebSocket(endpoint);
- console.log(green("ws connected! (type 'close' to quit)"));
+if (import.meta.main) {
+ const endpoint = Deno.args[0] || "ws://127.0.0.1:8080";
+ /** simple websocket cli */
+ try {
+ const sock = await connectWebSocket(endpoint);
+ console.log(green("ws connected! (type 'close' to quit)"));
- const messages = async (): Promise<void> => {
- for await (const msg of sock) {
- if (typeof msg === "string") {
- console.log(yellow(`< ${msg}`));
- } else if (isWebSocketPingEvent(msg)) {
- console.log(blue("< ping"));
- } else if (isWebSocketPongEvent(msg)) {
- console.log(blue("< pong"));
- } else if (isWebSocketCloseEvent(msg)) {
- console.log(red(`closed: code=${msg.code}, reason=${msg.reason}`));
+ const messages = async (): Promise<void> => {
+ for await (const msg of sock) {
+ if (typeof msg === "string") {
+ console.log(yellow(`< ${msg}`));
+ } else if (isWebSocketPingEvent(msg)) {
+ console.log(blue("< ping"));
+ } else if (isWebSocketPongEvent(msg)) {
+ console.log(blue("< pong"));
+ } else if (isWebSocketCloseEvent(msg)) {
+ console.log(red(`closed: code=${msg.code}, reason=${msg.reason}`));
+ }
}
- }
- };
+ };
- const cli = async (): Promise<void> => {
- const tpr = new TextProtoReader(new BufReader(Deno.stdin));
- while (true) {
- await Deno.stdout.write(encode("> "));
- const line = await tpr.readLine();
- if (line === null) {
- break;
- }
- if (line === "close") {
- break;
- } else if (line === "ping") {
- await sock.ping();
- } else {
- await sock.send(line);
+ const cli = async (): Promise<void> => {
+ const tpr = new TextProtoReader(new BufReader(Deno.stdin));
+ while (true) {
+ await Deno.stdout.write(encode("> "));
+ const line = await tpr.readLine();
+ if (line === null) {
+ break;
+ }
+ if (line === "close") {
+ break;
+ } else if (line === "ping") {
+ await sock.ping();
+ } else {
+ await sock.send(line);
+ }
}
- }
- };
+ };
- await Promise.race([messages(), cli()]).catch(console.error);
+ await Promise.race([messages(), cli()]).catch(console.error);
- if (!sock.isClosed) {
- await sock.close(1000).catch(console.error);
+ if (!sock.isClosed) {
+ await sock.close(1000).catch(console.error);
+ }
+ } catch (err) {
+ console.error(red(`Could not connect to WebSocket: '${err}'`));
}
-} catch (err) {
- console.error(red(`Could not connect to WebSocket: '${err}'`));
-}
-Deno.exit(0);
+ Deno.exit(0);
+}
diff --git a/std/ws/example_server.ts b/std/ws/example_server.ts
index 947b807ca..3a9815957 100644
--- a/std/ws/example_server.ts
+++ b/std/ws/example_server.ts
@@ -6,50 +6,52 @@ import {
isWebSocketPingEvent,
} from "./mod.ts";
-/** websocket echo server */
-const port = Deno.args[0] || "8080";
-console.log(`websocket server is running on :${port}`);
-for await (const req of serve(`:${port}`)) {
- const { conn, r: bufReader, w: bufWriter, headers } = req;
+if (import.meta.main) {
+ /** websocket echo server */
+ const port = Deno.args[0] || "8080";
+ console.log(`websocket server is running on :${port}`);
+ for await (const req of serve(`:${port}`)) {
+ const { conn, r: bufReader, w: bufWriter, headers } = req;
- try {
- const sock = await acceptWebSocket({
- conn,
- bufReader,
- bufWriter,
- headers,
- });
+ try {
+ const sock = await acceptWebSocket({
+ conn,
+ bufReader,
+ bufWriter,
+ headers,
+ });
- console.log("socket connected!");
+ console.log("socket connected!");
- try {
- for await (const ev of sock) {
- if (typeof ev === "string") {
- // text message
- console.log("ws:Text", ev);
- await sock.send(ev);
- } else if (ev instanceof Uint8Array) {
- // binary message
- console.log("ws:Binary", ev);
- } else if (isWebSocketPingEvent(ev)) {
- const [, body] = ev;
- // ping
- console.log("ws:Ping", body);
- } else if (isWebSocketCloseEvent(ev)) {
- // close
- const { code, reason } = ev;
- console.log("ws:Close", code, reason);
+ try {
+ for await (const ev of sock) {
+ if (typeof ev === "string") {
+ // text message
+ console.log("ws:Text", ev);
+ await sock.send(ev);
+ } else if (ev instanceof Uint8Array) {
+ // binary message
+ console.log("ws:Binary", ev);
+ } else if (isWebSocketPingEvent(ev)) {
+ const [, body] = ev;
+ // ping
+ console.log("ws:Ping", body);
+ } else if (isWebSocketCloseEvent(ev)) {
+ // close
+ const { code, reason } = ev;
+ console.log("ws:Close", code, reason);
+ }
}
- }
- } catch (err) {
- console.error(`failed to receive frame: ${err}`);
+ } catch (err) {
+ console.error(`failed to receive frame: ${err}`);
- if (!sock.isClosed) {
- await sock.close(1000).catch(console.error);
+ if (!sock.isClosed) {
+ await sock.close(1000).catch(console.error);
+ }
}
+ } catch (err) {
+ console.error(`failed to accept websocket: ${err}`);
+ await req.respond({ status: 400 });
}
- } catch (err) {
- console.error(`failed to accept websocket: ${err}`);
- await req.respond({ status: 400 });
}
}
diff --git a/std/ws/mod.ts b/std/ws/mod.ts
index 47353d012..324588af0 100644
--- a/std/ws/mod.ts
+++ b/std/ws/mod.ts
@@ -1,13 +1,13 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { decode, encode } from "../encoding/utf8.ts";
-import { hasOwnProperty } from "../util/has_own_property.ts";
+import { hasOwnProperty } from "../_util/has_own_property.ts";
import { BufReader, BufWriter } from "../io/bufio.ts";
import { readLong, readShort, sliceLongToBytes } from "../io/ioutil.ts";
-import { Sha1 } from "../util/sha1.ts";
-import { writeResponse } from "../http/io.ts";
+import { Sha1 } from "../hash/sha1.ts";
+import { writeResponse } from "../http/_io.ts";
import { TextProtoReader } from "../textproto/mod.ts";
-import { Deferred, deferred } from "../util/async.ts";
+import { Deferred, deferred } from "../async/deferred.ts";
import { assert } from "../testing/asserts.ts";
import { concat } from "../bytes/mod.ts";
import Conn = Deno.Conn;
diff --git a/std/ws/test.ts b/std/ws/test.ts
index 8e97e6ec2..a1c396b18 100644
--- a/std/ws/test.ts
+++ b/std/ws/test.ts
@@ -21,7 +21,7 @@ import Writer = Deno.Writer;
import Reader = Deno.Reader;
import Conn = Deno.Conn;
import Buffer = Deno.Buffer;
-import { delay } from "../util/async.ts";
+import { delay } from "../async/delay.ts";
test("[ws] read unmasked text frame", async () => {
// unmasked single text frame with payload "Hello"