From c6505c5de6cb39b8134003658dfff43098f2993f Mon Sep 17 00:00:00 2001 From: axetroy Date: Fri, 24 May 2019 20:24:04 +0800 Subject: remove function prefix of bytes module Original: https://github.com/denoland/deno_std/commit/a4579426783f36cd5e46c4ebfb75ef702b2a15ba --- bytes/bytes.ts | 10 +++++----- bytes/bytes_test.ts | 47 ++++++++++++++++------------------------------- 2 files changed, 21 insertions(+), 36 deletions(-) (limited to 'bytes') diff --git a/bytes/bytes.ts b/bytes/bytes.ts index 127dad1c2..a42eaffd2 100644 --- a/bytes/bytes.ts +++ b/bytes/bytes.ts @@ -2,7 +2,7 @@ import { copyBytes } from "../io/util.ts"; /** Find first index of binary pattern from a. If not found, then return -1 **/ -export function bytesFindIndex(a: Uint8Array, pat: Uint8Array): number { +export function findIndex(a: Uint8Array, pat: Uint8Array): number { const s = pat[0]; for (let i = 0; i < a.length; i++) { if (a[i] !== s) continue; @@ -24,7 +24,7 @@ export function bytesFindIndex(a: Uint8Array, pat: Uint8Array): number { } /** Find last index of binary pattern from a. If not found, then return -1 **/ -export function bytesFindLastIndex(a: Uint8Array, pat: Uint8Array): number { +export function findLastIndex(a: Uint8Array, pat: Uint8Array): number { const e = pat[pat.length - 1]; for (let i = a.length - 1; i >= 0; i--) { if (a[i] !== e) continue; @@ -46,7 +46,7 @@ export function bytesFindLastIndex(a: Uint8Array, pat: Uint8Array): number { } /** Check whether binary arrays are equal to each other **/ -export function bytesEqual(a: Uint8Array, match: Uint8Array): boolean { +export function equal(a: Uint8Array, match: Uint8Array): boolean { if (a.length !== match.length) return false; for (let i = 0; i < match.length; i++) { if (a[i] !== match[i]) return false; @@ -55,7 +55,7 @@ export function bytesEqual(a: Uint8Array, match: Uint8Array): boolean { } /** Check whether binary array has binary prefix **/ -export function bytesHasPrefix(a: Uint8Array, prefix: Uint8Array): boolean { +export function hasPrefix(a: Uint8Array, prefix: Uint8Array): boolean { for (let i = 0, max = prefix.length; i < max; i++) { if (a[i] !== prefix[i]) return false; } @@ -67,7 +67,7 @@ export function bytesHasPrefix(a: Uint8Array, prefix: Uint8Array): boolean { * @param b The origin bytes * @param count The count you want to repeat. */ -export function bytesRepeat(b: Uint8Array, count: number): Uint8Array { +export function repeat(b: Uint8Array, count: number): Uint8Array { if (count === 0) { return new Uint8Array(); } diff --git a/bytes/bytes_test.ts b/bytes/bytes_test.ts index 8ca4cb386..e53f81fcd 100644 --- a/bytes/bytes_test.ts +++ b/bytes/bytes_test.ts @@ -1,58 +1,46 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { - bytesFindIndex, - bytesFindLastIndex, - bytesEqual, - bytesHasPrefix, - bytesRepeat -} from "./bytes.ts"; +import { findIndex, findLastIndex, equal, hasPrefix, repeat } from "./bytes.ts"; import { test } from "../testing/mod.ts"; import { assertEquals, assertThrows } from "../testing/asserts.ts"; -test(function bytesBytesFindIndex1(): void { - const i = bytesFindIndex( +test(function bytesfindIndex1(): void { + const i = findIndex( new Uint8Array([1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 3]), new Uint8Array([0, 1, 2]) ); assertEquals(i, 2); }); -test(function bytesBytesFindIndex2(): void { - const i = bytesFindIndex(new Uint8Array([0, 0, 1]), new Uint8Array([0, 1])); +test(function bytesfindIndex2(): void { + const i = findIndex(new Uint8Array([0, 0, 1]), new Uint8Array([0, 1])); assertEquals(i, 1); }); -test(function bytesBytesFindLastIndex1(): void { - const i = bytesFindLastIndex( +test(function bytesfindLastIndex1(): void { + const i = findLastIndex( new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 3]), new Uint8Array([0, 1, 2]) ); assertEquals(i, 3); }); -test(function bytesBytesFindLastIndex2(): void { - const i = bytesFindLastIndex( - new Uint8Array([0, 1, 1]), - new Uint8Array([0, 1]) - ); +test(function bytesfindLastIndex2(): void { + const i = findLastIndex(new Uint8Array([0, 1, 1]), new Uint8Array([0, 1])); assertEquals(i, 0); }); -test(function bytesBytesBytesEqual(): void { - const v = bytesEqual( - new Uint8Array([0, 1, 2, 3]), - new Uint8Array([0, 1, 2, 3]) - ); +test(function bytesBytesequal(): void { + const v = equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 3])); assertEquals(v, true); }); -test(function bytesBytesHasPrefix(): void { - const v = bytesHasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1])); +test(function byteshasPrefix(): void { + const v = hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1])); assertEquals(v, true); }); -test(function bytesBytesRepeat(): void { +test(function bytesrepeat(): void { // input / output / count / error message const repeatTestCase = [ ["", "", 0], @@ -69,16 +57,13 @@ test(function bytesBytesRepeat(): void { if (errMsg) { assertThrows( (): void => { - bytesRepeat( - new TextEncoder().encode(input as string), - count as number - ); + repeat(new TextEncoder().encode(input as string), count as number); }, Error, errMsg as string ); } else { - const newBytes = bytesRepeat( + const newBytes = repeat( new TextEncoder().encode(input as string), count as number ); -- cgit v1.2.3