-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
3,104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
import { AssertionError } from "./assertion_error.ts"; | ||
|
||
/** Make an assertion, error will be thrown if `expr` does not have truthy value. */ | ||
export function assert(expr: unknown, msg = ""): asserts expr { | ||
if (!expr) { | ||
throw new AssertionError(msg); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/vendor/deno.land/[email protected]/assert/assertion_error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
export class AssertionError extends Error { | ||
override name = "AssertionError"; | ||
constructor(message: string) { | ||
super(message); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/vendor/deno.land/[email protected]/path/_common/assert_path.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
// Copyright the Browserify authors. MIT License. | ||
|
||
export function assertPath(path: string) { | ||
if (typeof path !== "string") { | ||
throw new TypeError( | ||
`Path must be a string. Received ${JSON.stringify(path)}`, | ||
); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/vendor/deno.land/[email protected]/path/_common/basename.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
// This module is browser compatible. | ||
|
||
import { assertPath } from "./assert_path.ts"; | ||
|
||
export function stripSuffix(name: string, suffix: string): string { | ||
if (suffix.length >= name.length) { | ||
return name; | ||
} | ||
|
||
const lenDiff = name.length - suffix.length; | ||
|
||
for (let i = suffix.length - 1; i >= 0; --i) { | ||
if (name.charCodeAt(lenDiff + i) !== suffix.charCodeAt(i)) { | ||
return name; | ||
} | ||
} | ||
|
||
return name.slice(0, -suffix.length); | ||
} | ||
|
||
export function lastPathSegment( | ||
path: string, | ||
isSep: (char: number) => boolean, | ||
start = 0, | ||
): string { | ||
let matchedNonSeparator = false; | ||
let end = path.length; | ||
|
||
for (let i = path.length - 1; i >= start; --i) { | ||
if (isSep(path.charCodeAt(i))) { | ||
if (matchedNonSeparator) { | ||
start = i + 1; | ||
break; | ||
} | ||
} else if (!matchedNonSeparator) { | ||
matchedNonSeparator = true; | ||
end = i + 1; | ||
} | ||
} | ||
|
||
return path.slice(start, end); | ||
} | ||
|
||
export function assertArgs(path: string, suffix: string) { | ||
assertPath(path); | ||
if (path.length === 0) return path; | ||
if (typeof suffix !== "string") { | ||
throw new TypeError( | ||
`Suffix must be a string. Received ${JSON.stringify(suffix)}`, | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/vendor/deno.land/[email protected]/path/_common/common.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
// This module is browser compatible. | ||
|
||
export function _common(paths: string[], sep: string): string { | ||
const [first = "", ...remaining] = paths; | ||
if (first === "" || remaining.length === 0) { | ||
return first.substring(0, first.lastIndexOf(sep) + 1); | ||
} | ||
const parts = first.split(sep); | ||
|
||
let endOfPrefix = parts.length; | ||
for (const path of remaining) { | ||
const compare = path.split(sep); | ||
for (let i = 0; i < endOfPrefix; i++) { | ||
if (compare[i] !== parts[i]) { | ||
endOfPrefix = i; | ||
} | ||
} | ||
|
||
if (endOfPrefix === 0) { | ||
return ""; | ||
} | ||
} | ||
const prefix = parts.slice(0, endOfPrefix).join(sep); | ||
return prefix.endsWith(sep) ? prefix : `${prefix}${sep}`; | ||
} |
49 changes: 49 additions & 0 deletions
49
src/vendor/deno.land/[email protected]/path/_common/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
// Copyright the Browserify authors. MIT License. | ||
// Ported from https://github.com/browserify/path-browserify/ | ||
// This module is browser compatible. | ||
|
||
// Alphabet chars. | ||
export const CHAR_UPPERCASE_A = 65; /* A */ | ||
export const CHAR_LOWERCASE_A = 97; /* a */ | ||
export const CHAR_UPPERCASE_Z = 90; /* Z */ | ||
export const CHAR_LOWERCASE_Z = 122; /* z */ | ||
|
||
// Non-alphabetic chars. | ||
export const CHAR_DOT = 46; /* . */ | ||
export const CHAR_FORWARD_SLASH = 47; /* / */ | ||
export const CHAR_BACKWARD_SLASH = 92; /* \ */ | ||
export const CHAR_VERTICAL_LINE = 124; /* | */ | ||
export const CHAR_COLON = 58; /* : */ | ||
export const CHAR_QUESTION_MARK = 63; /* ? */ | ||
export const CHAR_UNDERSCORE = 95; /* _ */ | ||
export const CHAR_LINE_FEED = 10; /* \n */ | ||
export const CHAR_CARRIAGE_RETURN = 13; /* \r */ | ||
export const CHAR_TAB = 9; /* \t */ | ||
export const CHAR_FORM_FEED = 12; /* \f */ | ||
export const CHAR_EXCLAMATION_MARK = 33; /* ! */ | ||
export const CHAR_HASH = 35; /* # */ | ||
export const CHAR_SPACE = 32; /* */ | ||
export const CHAR_NO_BREAK_SPACE = 160; /* \u00A0 */ | ||
export const CHAR_ZERO_WIDTH_NOBREAK_SPACE = 65279; /* \uFEFF */ | ||
export const CHAR_LEFT_SQUARE_BRACKET = 91; /* [ */ | ||
export const CHAR_RIGHT_SQUARE_BRACKET = 93; /* ] */ | ||
export const CHAR_LEFT_ANGLE_BRACKET = 60; /* < */ | ||
export const CHAR_RIGHT_ANGLE_BRACKET = 62; /* > */ | ||
export const CHAR_LEFT_CURLY_BRACKET = 123; /* { */ | ||
export const CHAR_RIGHT_CURLY_BRACKET = 125; /* } */ | ||
export const CHAR_HYPHEN_MINUS = 45; /* - */ | ||
export const CHAR_PLUS = 43; /* + */ | ||
export const CHAR_DOUBLE_QUOTE = 34; /* " */ | ||
export const CHAR_SINGLE_QUOTE = 39; /* ' */ | ||
export const CHAR_PERCENT = 37; /* % */ | ||
export const CHAR_SEMICOLON = 59; /* ; */ | ||
export const CHAR_CIRCUMFLEX_ACCENT = 94; /* ^ */ | ||
export const CHAR_GRAVE_ACCENT = 96; /* ` */ | ||
export const CHAR_AT = 64; /* @ */ | ||
export const CHAR_AMPERSAND = 38; /* & */ | ||
export const CHAR_EQUAL = 61; /* = */ | ||
|
||
// Digits | ||
export const CHAR_0 = 48; /* 0 */ | ||
export const CHAR_9 = 57; /* 9 */ |
9 changes: 9 additions & 0 deletions
9
src/vendor/deno.land/[email protected]/path/_common/dirname.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
// This module is browser compatible. | ||
|
||
import { assertPath } from "./assert_path.ts"; | ||
|
||
export function assertArg(path: string) { | ||
assertPath(path); | ||
if (path.length === 0) return "."; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/vendor/deno.land/[email protected]/path/_common/format.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
// This module is browser compatible. | ||
|
||
import type { FormatInputPathObject } from "../_interface.ts"; | ||
|
||
export function _format( | ||
sep: string, | ||
pathObject: FormatInputPathObject, | ||
): string { | ||
const dir: string | undefined = pathObject.dir || pathObject.root; | ||
const base: string = pathObject.base || | ||
(pathObject.name || "") + (pathObject.ext || ""); | ||
if (!dir) return base; | ||
if (base === sep) return dir; | ||
if (dir === pathObject.root) return dir + base; | ||
return dir + sep + base; | ||
} | ||
|
||
export function assertArg(pathObject: FormatInputPathObject) { | ||
if (pathObject === null || typeof pathObject !== "object") { | ||
throw new TypeError( | ||
`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`, | ||
); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/vendor/deno.land/[email protected]/path/_common/from_file_url.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
// This module is browser compatible. | ||
|
||
export function assertArg(url: URL | string) { | ||
url = url instanceof URL ? url : new URL(url); | ||
if (url.protocol !== "file:") { | ||
throw new TypeError("Must be a file URL."); | ||
} | ||
return url; | ||
} |
Oops, something went wrong.