Move encode, decode helpers to /std/encoding/utf8.ts, delete /std/strings/ (#4565)

also removes std/encoding/mod.ts and std/archive/mod.ts which are useless.
This commit is contained in:
Ryan Dahl 2020-04-01 15:23:39 -04:00 committed by GitHub
parent 3a0b617503
commit 12c6b2395b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 30 additions and 75 deletions

View file

@ -1 +0,0 @@
export * from "./tar.ts";

View file

@ -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(

View file

@ -1,15 +0,0 @@
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";
export * from "./binary.ts";

15
std/encoding/utf8.ts Normal file
View file

@ -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);
}

View file

@ -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,

View file

@ -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,

View file

@ -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";

View file

@ -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";

View file

@ -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;

View file

@ -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 {

View file

@ -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");

View file

@ -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`.

View file

@ -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 {

View file

@ -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";

View file

@ -1,26 +0,0 @@
# Strings
This module provides a few basic utilities to manipulate strings.
## Usage
### pad
Input string is processed to output a string with a minimal length. If the
parameter `strict` is set to true, the output string length is equal to the
`strLen` parameter.
Basic usage:
```ts
import { pad } from "https://deno.land/std/strings/pad.ts";
pad("deno", 6, { char: "*", side: "left" }); // output : "**deno"
pad("deno", 6, { char: "*", side: "right" }); // output : "deno**"
pad("denosorusrex", 6, {
char: "*",
side: "left",
strict: true,
strictSide: "right",
strictChar: "...",
}); // output : "den..."
```

View file

@ -1,7 +0,0 @@
/** A default TextDecoder instance */
export const decoder = new TextDecoder();
/** Shorthand for new TextDecoder().decode() */
export function decode(input?: Uint8Array): string {
return decoder.decode(input);
}

View file

@ -1,7 +0,0 @@
/** A default TextEncoder instance */
export const encoder = new TextEncoder();
/** Shorthand for new TextEncoder().encode() */
export function encode(input?: string): Uint8Array {
return encoder.encode(input);
}

View file

@ -1,4 +0,0 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
export * from "./encode.ts";
export * from "./decode.ts";

View file

@ -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) {

View file

@ -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";

View file

@ -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";

View file

@ -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;