summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--std/archive/mod.ts1
-rw-r--r--std/archive/tar.ts24
-rw-r--r--std/encoding/README.md99
-rw-r--r--std/encoding/csv.ts32
-rw-r--r--std/encoding/csv_test.ts6
-rw-r--r--std/encoding/mod.ts14
-rw-r--r--std/encoding/yaml.ts7
-rw-r--r--std/fmt/colors.ts4
-rw-r--r--std/fmt/colors_test.ts6
-rw-r--r--std/fmt/mod.ts2
-rw-r--r--std/http/mod.ts3
-rw-r--r--std/io/mod.ts4
-rw-r--r--std/manual.md17
-rw-r--r--std/mime/mod.ts1
-rw-r--r--std/multipart/mod.ts1
-rw-r--r--std/testing/README.md7
-rw-r--r--std/testing/mod.ts7
17 files changed, 89 insertions, 146 deletions
diff --git a/std/archive/mod.ts b/std/archive/mod.ts
new file mode 100644
index 000000000..254b8266f
--- /dev/null
+++ b/std/archive/mod.ts
@@ -0,0 +1 @@
+export * from "./tar.ts";
diff --git a/std/archive/tar.ts b/std/archive/tar.ts
index 8ebfa7fb5..e53cd9111 100644
--- a/std/archive/tar.ts
+++ b/std/archive/tar.ts
@@ -35,7 +35,7 @@ const ustar = "ustar\u000000";
/**
* Simple file reader
*/
-export class FileReader implements Deno.Reader {
+class FileReader implements Deno.Reader {
private file?: Deno.File;
constructor(private filePath: string, private mode: Deno.OpenMode = "r") {}
@@ -54,28 +54,6 @@ export class FileReader implements Deno.Reader {
}
/**
- * Simple file writer (call FileWriter.dispose() after use)
- */
-export class FileWriter implements Deno.Writer {
- private file?: Deno.File;
-
- constructor(private filePath: string, private mode: Deno.OpenMode = "w") {}
-
- public async write(p: Uint8Array): Promise<number> {
- if (!this.file) {
- this.file = await Deno.open(this.filePath, this.mode);
- }
- return Deno.write(this.file.rid, p);
- }
-
- public dispose(): void {
- if (!this.file) return;
- Deno.close(this.file.rid);
- this.file = undefined;
- }
-}
-
-/**
* Remove the trailing null codes
* @param buffer
*/
diff --git a/std/encoding/README.md b/std/encoding/README.md
index 767cbdcb4..ee06aa3ec 100644
--- a/std/encoding/README.md
+++ b/std/encoding/README.md
@@ -2,100 +2,21 @@
## CSV
-- **`readAll(reader: BufReader, opt: ParseOptions = { comma: ",", trimLeadingSpace: false, lazyQuotes: false } ): Promise<[string[][], BufState]>`**:
- Read the whole buffer and output the structured CSV datas
-- **`parse(csvString: string, opt: ParseOption): Promise<unknown[]>`**: See
- [parse](###Parse)
+- **`parseCsv(input: string | BufReader, opt: ParseCsvOptions): Promise<unknown[]>`**:
+ Read the string/buffer into an
-### Parse
-
-Parse the CSV string with the options provided.
-
-#### Options
-
-##### ParseOption
-
-- **`header: boolean | string[] | HeaderOption[];`**: If a boolean is provided,
- the first line will be used as Header definitions. If `string[]` or
- `HeaderOption[]` those names will be used for header definition.
-- **`parse?: (input: unknown) => unknown;`**: Parse function for the row, which
- will be executed after parsing of all columns. Therefore if you don't provide
- header and parse function with headers, input will be `string[]`.
-
-##### HeaderOption
-
-- **`name: string;`**: Name of the header to be used as property.
-- **`parse?: (input: string) => unknown;`**: Parse function for the column. This
- is executed on each entry of the header. This can be combined with the Parse
- function of the rows.
-
-#### Usage
+### Usage
```ts
-// input:
-// a,b,c
-// e,f,g
-
-const r = await parseFile(filepath, {
- header: false
-});
-// output:
-// [["a", "b", "c"], ["e", "f", "g"]]
+const string = "a,b,c\nd,e,f";
-const r = await parseFile(filepath, {
- header: true
-});
-// output:
-// [{ a: "e", b: "f", c: "g" }]
-
-const r = await parseFile(filepath, {
- header: ["this", "is", "sparta"]
-});
-// output:
-// [
-// { this: "a", is: "b", sparta: "c" },
-// { this: "e", is: "f", sparta: "g" }
-// ]
-
-const r = await parseFile(filepath, {
- header: [
- {
- name: "this",
- parse: (e: string): string => {
- return `b${e}$$`;
- }
- },
- {
- name: "is",
- parse: (e: string): number => {
- return e.length;
- }
- },
- {
- name: "sparta",
- parse: (e: string): unknown => {
- return { bim: `boom-${e}` };
- }
- }
- ]
-});
-// output:
-// [
-// { this: "ba$$", is: 1, sparta: { bim: `boom-c` } },
-// { this: "be$$", is: 1, sparta: { bim: `boom-g` } }
-// ]
-
-const r = await parseFile(filepath, {
- header: ["this", "is", "sparta"],
- parse: (e: Record<string, unknown>) => {
- return { super: e.this, street: e.is, fighter: e.sparta };
- }
-});
+console.log(
+ await parseCsv(string, {
+ header: false
+ })
+);
// output:
-// [
-// { super: "a", street: "b", fighter: "c" },
-// { super: "e", street: "f", fighter: "g" }
-// ]
+// [["a", "b", "c"], ["d", "e", "f"]]
```
## TOML
diff --git a/std/encoding/csv.ts b/std/encoding/csv.ts
index 10d72a8a5..8cfa1cab9 100644
--- a/std/encoding/csv.ts
+++ b/std/encoding/csv.ts
@@ -28,7 +28,7 @@ export class ParseError extends Error {
* @property fieldsPerRecord - Enabling the check of fields for each row.
* If == 0, first row is used as referal for the number of fields.
*/
-export interface ParseOptions {
+export interface ReadOptions {
comma?: string;
comment?: string;
trimLeadingSpace?: boolean;
@@ -36,7 +36,7 @@ export interface ParseOptions {
fieldsPerRecord?: number;
}
-function chkOptions(opt: ParseOptions): void {
+function chkOptions(opt: ReadOptions): void {
if (!opt.comma) opt.comma = ",";
if (!opt.trimLeadingSpace) opt.trimLeadingSpace = false;
if (
@@ -51,7 +51,7 @@ function chkOptions(opt: ParseOptions): void {
async function read(
Startline: number,
reader: BufReader,
- opt: ParseOptions = { comma: ",", trimLeadingSpace: false }
+ opt: ReadOptions = { comma: ",", trimLeadingSpace: false }
): Promise<string[] | Deno.EOF> {
const tp = new TextProtoReader(reader);
let line: string;
@@ -107,9 +107,9 @@ async function read(
return result;
}
-export async function readAll(
+export async function readMatrix(
reader: BufReader,
- opt: ParseOptions = {
+ opt: ReadOptions = {
comma: ",",
trimLeadingSpace: false,
lazyQuotes: false
@@ -151,17 +151,17 @@ export async function readAll(
}
/**
- * HeaderOption provides the column definition
+ * HeaderOptions provides the column definition
* and the parse function for each entry of the
* column.
*/
-export interface HeaderOption {
+export interface HeaderOptions {
name: string;
parse?: (input: string) => unknown;
}
-export interface ExtendedParseOptions extends ParseOptions {
- header: boolean | string[] | HeaderOption[];
+export interface ParseOptions extends ReadOptions {
+ header: boolean | string[] | HeaderOptions[];
parse?: (input: unknown) => unknown;
}
@@ -188,26 +188,26 @@ export interface ExtendedParseOptions extends ParseOptions {
*/
export async function parse(
input: string | BufReader,
- opt: ExtendedParseOptions = {
+ opt: ParseOptions = {
header: false
}
): Promise<unknown[]> {
let r: string[][];
if (input instanceof BufReader) {
- r = await readAll(input, opt);
+ r = await readMatrix(input, opt);
} else {
- r = await readAll(new BufReader(new StringReader(input)), opt);
+ r = await readMatrix(new BufReader(new StringReader(input)), opt);
}
if (opt.header) {
- let headers: HeaderOption[] = [];
+ let headers: HeaderOptions[] = [];
let i = 0;
if (Array.isArray(opt.header)) {
if (typeof opt.header[0] !== "string") {
- headers = opt.header as HeaderOption[];
+ headers = opt.header as HeaderOptions[];
} else {
const h = opt.header as string[];
headers = h.map(
- (e): HeaderOption => {
+ (e): HeaderOptions => {
return {
name: e
};
@@ -216,7 +216,7 @@ export async function parse(
}
} else {
headers = r.shift()!.map(
- (e): HeaderOption => {
+ (e): HeaderOptions => {
return {
name: e
};
diff --git a/std/encoding/csv_test.ts b/std/encoding/csv_test.ts
index 65a86a353..daa30d0fb 100644
--- a/std/encoding/csv_test.ts
+++ b/std/encoding/csv_test.ts
@@ -2,7 +2,7 @@
// https://github.com/golang/go/blob/2cc15b1/src/encoding/csv/reader_test.go
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals, assert } from "../testing/asserts.ts";
-import { readAll, parse } from "./csv.ts";
+import { readMatrix, parse } from "./csv.ts";
import { StringReader } from "../io/readers.ts";
import { BufReader } from "../io/bufio.ts";
@@ -477,7 +477,7 @@ for (const t of testCases) {
if (t.Error) {
let err;
try {
- actual = await readAll(new BufReader(new StringReader(t.Input!)), {
+ actual = await readMatrix(new BufReader(new StringReader(t.Input!)), {
comma: comma,
comment: comment,
trimLeadingSpace: trim,
@@ -490,7 +490,7 @@ for (const t of testCases) {
assert(err);
assertEquals(err.message, t.Error);
} else {
- actual = await readAll(new BufReader(new StringReader(t.Input!)), {
+ actual = await readMatrix(new BufReader(new StringReader(t.Input!)), {
comma: comma,
comment: comment,
trimLeadingSpace: trim,
diff --git a/std/encoding/mod.ts b/std/encoding/mod.ts
new file mode 100644
index 000000000..03bde0294
--- /dev/null
+++ b/std/encoding/mod.ts
@@ -0,0 +1,14 @@
+export {
+ HeaderOptions as CsvHeaderOptions,
+ ParseError as CsvParseError,
+ ParseOptions as ParseCsvOptions,
+ parse as parseCsv
+} from "./csv.ts";
+export {
+ decode as decodeHex,
+ decodeString as decodeHexString,
+ encode as encodeToHex,
+ encodeToString as encodeToHexString
+} from "./hex.ts";
+export { parse as parseToml, stringify as tomlStringify } from "./toml.ts";
+export { parse as parseYaml, stringify as yamlStringify } from "./yaml.ts";
diff --git a/std/encoding/yaml.ts b/std/encoding/yaml.ts
index 15b12c04f..27c2874ec 100644
--- a/std/encoding/yaml.ts
+++ b/std/encoding/yaml.ts
@@ -3,6 +3,9 @@
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-export * from "./yaml/parse.ts";
-export * from "./yaml/stringify.ts";
+export { ParseOptions, parse } from "./yaml/parse.ts";
+export {
+ DumpOptions as StringifyOptions,
+ stringify
+} from "./yaml/stringify.ts";
export * from "./yaml/schema/mod.ts";
diff --git a/std/fmt/colors.ts b/std/fmt/colors.ts
index 52ba22487..3f241d5b0 100644
--- a/std/fmt/colors.ts
+++ b/std/fmt/colors.ts
@@ -21,7 +21,7 @@ interface Code {
let enabled = !noColor;
-export function setEnabled(value: boolean): void {
+export function setColorEnabled(value: boolean): void {
if (noColor) {
return;
}
@@ -29,7 +29,7 @@ export function setEnabled(value: boolean): void {
enabled = value;
}
-export function getEnabled(): boolean {
+export function getColorEnabled(): boolean {
return enabled;
}
diff --git a/std/fmt/colors_test.ts b/std/fmt/colors_test.ts
index 949bc34e7..467cda1bb 100644
--- a/std/fmt/colors_test.ts
+++ b/std/fmt/colors_test.ts
@@ -17,10 +17,10 @@ test(function replacesCloseCharacters(): void {
});
test(function enablingColors(): void {
- assertEquals(c.getEnabled(), true);
- c.setEnabled(false);
+ assertEquals(c.getColorEnabled(), true);
+ c.setColorEnabled(false);
assertEquals(c.bgBlue(c.red("foo bar")), "foo bar");
- c.setEnabled(true);
+ c.setColorEnabled(true);
assertEquals(c.red("foo bar"), "foo bar");
});
diff --git a/std/fmt/mod.ts b/std/fmt/mod.ts
new file mode 100644
index 000000000..a0f8feb8b
--- /dev/null
+++ b/std/fmt/mod.ts
@@ -0,0 +1,2 @@
+export * from "./colors.ts";
+export * from "./sprintf.ts";
diff --git a/std/http/mod.ts b/std/http/mod.ts
new file mode 100644
index 000000000..3746242a9
--- /dev/null
+++ b/std/http/mod.ts
@@ -0,0 +1,3 @@
+export * from "./cookie.ts";
+export * from "./http_status.ts";
+export * from "./server.ts";
diff --git a/std/io/mod.ts b/std/io/mod.ts
new file mode 100644
index 000000000..ca07bac43
--- /dev/null
+++ b/std/io/mod.ts
@@ -0,0 +1,4 @@
+export * from "./bufio.ts";
+export * from "./ioutil.ts";
+export * from "./readers.ts";
+export * from "./writers.ts";
diff --git a/std/manual.md b/std/manual.md
index ca4a269f6..b99c8f28f 100644
--- a/std/manual.md
+++ b/std/manual.md
@@ -533,8 +533,11 @@ browser JavaScript, Deno can import libraries directly from URLs. This example
uses a URL to import a test runner library:
```ts
-import { test, runIfMain } from "https://deno.land/std/testing/mod.ts";
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import {
+ assertEquals,
+ runIfMain,
+ test
+} from "https://deno.land/std/testing/mod.ts";
test(function t1() {
assertEquals("hello", "hello");
@@ -597,13 +600,15 @@ everywhere in a large project?** The solution is to import and re-export your
external libraries in a central `deps.ts` file (which serves the same purpose as
Node's `package.json` file). For example, let's say you were using the above
testing library across a large project. Rather than importing
-`"https://deno.land/std/testing/mod.ts"` and
-`"https://deno.land/std/testing/asserts.ts"` everywhere, you could create a
+`"https://deno.land/std/testing/mod.ts"` everywhere, you could create a
`deps.ts` file that exports the third-party code:
```ts
-export { runTests, test } from "https://deno.land/std/testing/mod.ts";
-export { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+export {
+ assertEquals,
+ runTests,
+ test
+} from "https://deno.land/std/testing/mod.ts";
```
And throughout the same project, you can import from the `deps.ts` and avoid
diff --git a/std/mime/mod.ts b/std/mime/mod.ts
new file mode 100644
index 000000000..9b75002e0
--- /dev/null
+++ b/std/mime/mod.ts
@@ -0,0 +1 @@
+export * from "./multipart.ts";
diff --git a/std/multipart/mod.ts b/std/multipart/mod.ts
new file mode 100644
index 000000000..8e8a665a9
--- /dev/null
+++ b/std/multipart/mod.ts
@@ -0,0 +1 @@
+export * from "./formfile.ts";
diff --git a/std/testing/README.md b/std/testing/README.md
index 8d02f9d79..afaf76b86 100644
--- a/std/testing/README.md
+++ b/std/testing/README.md
@@ -48,8 +48,11 @@ Asserts are exposed in `testing/asserts.ts` module.
Basic usage:
```ts
-import { runTests, test } from "https://deno.land/std/testing/mod.ts";
-import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
+import {
+ assertEquals,
+ runTests,
+ test
+} from "https://deno.land/std/testing/mod.ts";
test({
name: "testing example",
diff --git a/std/testing/mod.ts b/std/testing/mod.ts
index 0d5d2702a..06a1df958 100644
--- a/std/testing/mod.ts
+++ b/std/testing/mod.ts
@@ -1,5 +1,12 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+export * from "./asserts.ts";
+export * from "./bench.ts";
+import diff from "./diff.ts";
+export { diff };
+export * from "./format.ts";
+export * from "./runner.ts";
+
import {
bgRed,
white,