Skip to content

Commit

Permalink
Move encode, decode helpers to /std/encoding/utf8.ts, delete /std/str…
Browse files Browse the repository at this point in the history
…ings/ (denoland#4565)

also removes std/encoding/mod.ts and std/archive/mod.ts which are useless.
  • Loading branch information
ry committed Apr 1, 2020
1 parent 3a0b617 commit 12c6b23
Show file tree
Hide file tree
Showing 22 changed files with 30 additions and 75 deletions.
1 change: 0 additions & 1 deletion std/archive/mod.ts

This file was deleted.

2 changes: 1 addition & 1 deletion std/bytes/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
concat,
} from "./mod.ts";
import { assertEquals, assertThrows, assert } from "../testing/asserts.ts";
import { encode, decode } from "../strings/mod.ts";
import { encode, decode } from "../encoding/utf8.ts";

Deno.test("[bytes] findIndex1", () => {
const i = findIndex(
Expand Down
15 changes: 0 additions & 15 deletions std/encoding/mod.ts

This file was deleted.

15 changes: 15 additions & 0 deletions std/encoding/utf8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** A default TextEncoder instance */
export const encoder = new TextEncoder();

/** Shorthand for new TextEncoder().encode() */
export function encode(input?: string): Uint8Array {
return encoder.encode(input);
}

/** A default TextDecoder instance */
export const decoder = new TextDecoder();

/** Shorthand for new TextDecoder().decode() */
export function decode(input?: Uint8Array): string {
return decoder.decode(input);
}
2 changes: 1 addition & 1 deletion std/examples/tests/xeval_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { xeval } from "../xeval.ts";
import { stringsReader } from "../../io/util.ts";
import { decode, encode } from "../../strings/mod.ts";
import { decode, encode } from "../../encoding/utf8.ts";
import {
assertEquals,
assertStrContains,
Expand Down
2 changes: 1 addition & 1 deletion std/fs/expand_glob_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { cwd, execPath, run } = Deno;
import { decode } from "../strings/mod.ts";
import { decode } from "../encoding/utf8.ts";
import { assert, assertEquals, assertStrContains } from "../testing/asserts.ts";
import {
isWindows,
Expand Down
2 changes: 1 addition & 1 deletion std/http/io.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BufReader, BufWriter } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
import { assert } from "../testing/asserts.ts";
import { encoder } from "../strings/mod.ts";
import { encoder } from "../encoding/utf8.ts";
import { ServerRequest, Response } from "./server.ts";
import { STATUS_TEXT } from "./http_status.ts";

Expand Down
2 changes: 1 addition & 1 deletion std/http/io_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
readRequest,
writeResponse,
} from "./io.ts";
import { encode, decode } from "../strings/mod.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";
Expand Down
2 changes: 1 addition & 1 deletion std/http/server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { Response, ServerRequest, Server, serve } from "./server.ts";
import { BufReader, BufWriter } from "../io/bufio.ts";
import { delay } from "../util/async.ts";
import { encode, decode } from "../strings/mod.ts";
import { encode, decode } from "../encoding/utf8.ts";
import { mockConn } from "./mock.ts";

const { Buffer, test } = Deno;
Expand Down
2 changes: 1 addition & 1 deletion std/io/readers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
type Reader = Deno.Reader;
import { encode } from "../strings/mod.ts";
import { encode } from "../encoding/utf8.ts";

/** Reader utility for strings */
export class StringReader implements Reader {
Expand Down
2 changes: 1 addition & 1 deletion std/io/readers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { assertEquals } from "../testing/asserts.ts";
import { MultiReader, StringReader } from "./readers.ts";
import { StringWriter } from "./writers.ts";
import { copyN } from "./ioutil.ts";
import { decode } from "../strings/mod.ts";
import { decode } from "../encoding/utf8.ts";

test(async function ioStringReader(): Promise<void> {
const r = new StringReader("abcdef");
Expand Down
2 changes: 1 addition & 1 deletion std/io/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Buffer, mkdir, open } = Deno;
type File = Deno.File;
type Reader = Deno.Reader;
import * as path from "../path/mod.ts";
import { encode } from "../strings/mod.ts";
import { encode } from "../encoding/utf8.ts";

// `off` is the offset into `dst` where it will at which to begin writing values
// from `src`.
Expand Down
2 changes: 1 addition & 1 deletion std/io/writers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
type Writer = Deno.Writer;
import { decode, encode } from "../strings/mod.ts";
import { decode, encode } from "../encoding/utf8.ts";

/** Writer utility for buffering string chunks */
export class StringWriter implements Writer {
Expand Down
2 changes: 1 addition & 1 deletion std/mime/multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MultiReader } from "../io/readers.ts";
import { extname } from "../path/mod.ts";
import { tempFile } from "../io/util.ts";
import { BufReader, BufWriter } from "../io/bufio.ts";
import { encoder } from "../strings/mod.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";
Expand Down
26 changes: 0 additions & 26 deletions std/strings/README.md

This file was deleted.

7 changes: 0 additions & 7 deletions std/strings/decode.ts

This file was deleted.

7 changes: 0 additions & 7 deletions std/strings/encode.ts

This file was deleted.

4 changes: 0 additions & 4 deletions std/strings/mod.ts

This file was deleted.

2 changes: 1 addition & 1 deletion std/textproto/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { BufReader } from "../io/bufio.ts";
import { charCode } from "../io/util.ts";
import { concat } from "../bytes/mod.ts";
import { decode } from "../strings/mod.ts";
import { decode } from "../encoding/utf8.ts";

function str(buf: Uint8Array | null | undefined): string {
if (buf == null) {
Expand Down
2 changes: 1 addition & 1 deletion std/ws/example_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
isWebSocketPingEvent,
isWebSocketPongEvent,
} from "../ws/mod.ts";
import { encode } from "../strings/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";
Expand Down
2 changes: 1 addition & 1 deletion std/ws/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

import { decode, encode } from "../strings/mod.ts";
import { decode, encode } from "../encoding/utf8.ts";
import { hasOwnProperty } from "../util/has_own_property.ts";
import { BufReader, BufWriter } from "../io/bufio.ts";
import { readLong, readShort, sliceLongToBytes } from "../io/ioutil.ts";
Expand Down
2 changes: 1 addition & 1 deletion std/ws/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
writeFrame,
createWebSocket,
} from "./mod.ts";
import { encode, decode } from "../strings/mod.ts";
import { encode, decode } from "../encoding/utf8.ts";
import Writer = Deno.Writer;
import Reader = Deno.Reader;
import Conn = Deno.Conn;
Expand Down

0 comments on commit 12c6b23

Please sign in to comment.