From 6abf126c2a7a451cded8c6b5e6ddf1b69c84055d Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Tue, 2 Feb 2021 19:05:46 +0800 Subject: chore: remove std directory (#9361) This removes the std folder from the tree. Various parts of the tests are pretty tightly dependent on std (47 direct imports and 75 indirect imports, not counting the cli tests that use them as fixtures) so I've added std as a submodule for now. --- std/_util/assert.ts | 15 ------------- std/_util/assert_test.ts | 31 --------------------------- std/_util/deep_assign.ts | 49 ------------------------------------------- std/_util/deep_assign_test.ts | 23 -------------------- std/_util/has_own_property.ts | 30 -------------------------- std/_util/os.ts | 18 ---------------- 6 files changed, 166 deletions(-) delete mode 100644 std/_util/assert.ts delete mode 100644 std/_util/assert_test.ts delete mode 100644 std/_util/deep_assign.ts delete mode 100644 std/_util/deep_assign_test.ts delete mode 100644 std/_util/has_own_property.ts delete mode 100644 std/_util/os.ts (limited to 'std/_util') diff --git a/std/_util/assert.ts b/std/_util/assert.ts deleted file mode 100644 index 2588190de..000000000 --- a/std/_util/assert.ts +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. - -export class DenoStdInternalError extends Error { - constructor(message: string) { - super(message); - this.name = "DenoStdInternalError"; - } -} - -/** Make an assertion, if not `true`, then throw. */ -export function assert(expr: unknown, msg = ""): asserts expr { - if (!expr) { - throw new DenoStdInternalError(msg); - } -} diff --git a/std/_util/assert_test.ts b/std/_util/assert_test.ts deleted file mode 100644 index 919767fd0..000000000 --- a/std/_util/assert_test.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, DenoStdInternalError } from "./assert.ts"; -import { assertThrows } from "../testing/asserts.ts"; - -Deno.test({ - name: "assert valid scenario", - fn(): void { - assert(true); - }, -}); - -Deno.test({ - name: "assert invalid scenario, no message", - fn(): void { - assertThrows(() => { - assert(false); - }, DenoStdInternalError); - }, -}); -Deno.test({ - name: "assert invalid scenario, with message", - fn(): void { - assertThrows( - () => { - assert(false, "Oops! Should be true"); - }, - DenoStdInternalError, - "Oops! Should be true", - ); - }, -}); diff --git a/std/_util/deep_assign.ts b/std/_util/deep_assign.ts deleted file mode 100644 index d38788add..000000000 --- a/std/_util/deep_assign.ts +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert } from "./assert.ts"; - -export function deepAssign(target: T, source: U): T & U; -export function deepAssign( - target: T, - source1: U, - source2: V, -): T & U & V; -export function deepAssign( - target: T, - source1: U, - source2: V, - source3: W, -): T & U & V & W; -export function deepAssign( - // deno-lint-ignore no-explicit-any - target: Record, - // deno-lint-ignore no-explicit-any - ...sources: any[] -): // deno-lint-ignore ban-types -object | undefined { - for (let i = 0; i < sources.length; i++) { - const source = sources[i]; - if (!source || typeof source !== `object`) { - return; - } - Object.entries(source).forEach(([key, value]): void => { - if (value instanceof Date) { - target[key] = new Date(value); - return; - } - if (!value || typeof value !== `object`) { - target[key] = value; - return; - } - if (Array.isArray(value)) { - target[key] = []; - } - // value is an Object - if (typeof target[key] !== `object` || !target[key]) { - target[key] = {}; - } - assert(value); - deepAssign(target[key] as Record, value); - }); - } - return target; -} diff --git a/std/_util/deep_assign_test.ts b/std/_util/deep_assign_test.ts deleted file mode 100644 index 8ec7b3aef..000000000 --- a/std/_util/deep_assign_test.ts +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; -import { deepAssign } from "./deep_assign.ts"; - -Deno.test("deepAssignTest", function (): void { - const date = new Date("1979-05-27T07:32:00Z"); - const reg = RegExp(/DENOWOWO/); - const obj1 = { deno: { bar: { deno: ["is", "not", "node"] } } }; - const obj2 = { foo: { deno: date } }; - const obj3 = { foo: { bar: "deno" }, reg: reg }; - const actual = deepAssign(obj1, obj2, obj3); - const expected = { - foo: { - deno: new Date("1979-05-27T07:32:00Z"), - bar: "deno", - }, - deno: { bar: { deno: ["is", "not", "node"] } }, - reg: RegExp(/DENOWOWO/), - }; - assert(date !== expected.foo.deno); - assert(reg !== expected.reg); - assertEquals(actual, expected); -}); diff --git a/std/_util/has_own_property.ts b/std/_util/has_own_property.ts deleted file mode 100644 index f9e4acbb2..000000000 --- a/std/_util/has_own_property.ts +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. - -/** - * Determines whether an object has a property with the specified name. - * Avoid calling prototype builtin `hasOwnProperty` for two reasons: - * - * 1. `hasOwnProperty` is defined on the object as something else: - * - * const options = { - * ending: 'utf8', - * hasOwnProperty: 'foo' - * }; - * options.hasOwnProperty('ending') // throws a TypeError - * - * 2. The object doesn't inherit from `Object.prototype`: - * - * const options = Object.create(null); - * options.ending = 'utf8'; - * options.hasOwnProperty('ending'); // throws a TypeError - * - * @param obj A Object. - * @param v A property name. - * @see https://eslint.org/docs/rules/no-prototype-builtins - */ -export function hasOwnProperty(obj: T, v: PropertyKey): boolean { - if (obj == null) { - return false; - } - return Object.prototype.hasOwnProperty.call(obj, v); -} diff --git a/std/_util/os.ts b/std/_util/os.ts deleted file mode 100644 index 3b56b6d8a..000000000 --- a/std/_util/os.ts +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -// This module is browser compatible. - -export const osType = (() => { - if (globalThis.Deno != null) { - return Deno.build.os; - } - - // deno-lint-ignore no-explicit-any - const navigator = (globalThis as any).navigator; - if (navigator?.appVersion?.includes?.("Win") ?? false) { - return "windows"; - } - - return "linux"; -})(); - -export const isWindows = osType === "windows"; -- cgit v1.2.3