diff options
Diffstat (limited to 'std/path')
-rw-r--r-- | std/path/extname_test.ts | 6 | ||||
-rw-r--r-- | std/path/glob.ts | 2 | ||||
-rw-r--r-- | std/path/glob_test.ts | 24 | ||||
-rw-r--r-- | std/path/globrex.ts | 4 | ||||
-rw-r--r-- | std/path/globrex_test.ts | 66 | ||||
-rw-r--r-- | std/path/join_test.ts | 10 | ||||
-rw-r--r-- | std/path/parse_format_test.ts | 35 | ||||
-rw-r--r-- | std/path/posix.ts | 5 | ||||
-rw-r--r-- | std/path/relative_test.ts | 94 | ||||
-rw-r--r-- | std/path/resolve_test.ts | 10 | ||||
-rw-r--r-- | std/path/utils.ts | 2 | ||||
-rw-r--r-- | std/path/win32.ts | 15 |
12 files changed, 135 insertions, 138 deletions
diff --git a/std/path/extname_test.ts b/std/path/extname_test.ts index d9e14bb48..16ca7a2f9 100644 --- a/std/path/extname_test.ts +++ b/std/path/extname_test.ts @@ -49,11 +49,11 @@ const pairs = [ ["file/", ""], ["file//", ""], ["file./", "."], - ["file.//", "."] + ["file.//", "."], ]; test(function extname() { - pairs.forEach(function(p) { + pairs.forEach(function (p) { const input = p[0]; const expected = p[1]; assertEquals(expected, path.posix.extname(input)); @@ -71,7 +71,7 @@ test(function extname() { }); test(function extnameWin32() { - pairs.forEach(function(p) { + pairs.forEach(function (p) { const input = p[0].replace(slashRE, "\\"); const expected = p[1]; assertEquals(expected, path.win32.extname(input)); diff --git a/std/path/glob.ts b/std/path/glob.ts index 8eb106b25..a11865c26 100644 --- a/std/path/glob.ts +++ b/std/path/glob.ts @@ -44,7 +44,7 @@ export function globToRegExp( extended, globstar, strict: false, - filepath: true + filepath: true, }); assert(result.path != null); return result.path.regex; diff --git a/std/path/glob_test.ts b/std/path/glob_test.ts index d8da1a47b..8c49adeca 100644 --- a/std/path/glob_test.ts +++ b/std/path/glob_test.ts @@ -32,17 +32,17 @@ test({ ); assertEquals( globToRegExp(join("unicorn", "!(sleeping)", "bathroom.ts"), { - extended: true + extended: true, }).test(join("unicorn", "flying", "bathroom.ts")), true ); assertEquals( globToRegExp(join("unicorn", "(!sleeping)", "bathroom.ts"), { - extended: true + extended: true, }).test(join("unicorn", "sleeping", "bathroom.ts")), false ); - } + }, }); testWalk( @@ -55,7 +55,7 @@ testWalk( }, async function globInWalkWildcard(): Promise<void> { const arr = await walkArray(".", { - match: [globToRegExp(join("*", "*.ts"))] + match: [globToRegExp(join("*", "*.ts"))], }); assertEquals(arr.length, 2); assertEquals(arr[0], "a/x.ts"); @@ -74,9 +74,9 @@ testWalk( match: [ globToRegExp(join("a", "**", "*.ts"), { flags: "g", - globstar: true - }) - ] + globstar: true, + }), + ], }); assertEquals(arr.length, 1); assertEquals(arr[0], "a/yo/x.ts"); @@ -98,9 +98,9 @@ testWalk( match: [ globToRegExp(join("a", "+(raptor|deno)", "*.ts"), { flags: "g", - extended: true - }) - ] + extended: true, + }), + ], }); assertEquals(arr.length, 2); assertEquals(arr[0], "a/deno/x.ts"); @@ -116,7 +116,7 @@ testWalk( }, async function globInWalkWildcardExtension(): Promise<void> { const arr = await walkArray(".", { - match: [globToRegExp("x.*", { flags: "g", globstar: true })] + match: [globToRegExp("x.*", { flags: "g", globstar: true })], }); assertEquals(arr.length, 2); assertEquals(arr[0], "x.js"); @@ -236,7 +236,7 @@ test({ assert(!isGlob("\\a/b/c/\\[a-z\\].js")); assert(!isGlob("abc/\\(aaa|bbb).js")); assert(!isGlob("abc/\\?.js")); - } + }, }); test(function normalizeGlobGlobstar(): void { diff --git a/std/path/globrex.ts b/std/path/globrex.ts index 695294834..0fe833a52 100644 --- a/std/path/globrex.ts +++ b/std/path/globrex.ts @@ -54,7 +54,7 @@ export function globrex( globstar = false, strict = false, filepath = false, - flags = "" + flags = "", }: GlobrexOptions = {} ): GlobrexResult { const sepPattern = new RegExp(`^${SEP}${strict ? "" : "+"}$`); @@ -319,7 +319,7 @@ export function globrex( globstar: new RegExp( !flags.includes("g") ? `^${GLOBSTAR_SEGMENT}$` : GLOBSTAR_SEGMENT, flags - ) + ), }; } diff --git a/std/path/globrex_test.ts b/std/path/globrex_test.ts index 29f039837..27541a5c8 100644 --- a/std/path/globrex_test.ts +++ b/std/path/globrex_test.ts @@ -34,7 +34,7 @@ test({ t.equal(typeof globrex, "function", "constructor is a typeof function"); t.equal(res instanceof Object, true, "returns object"); t.equal(res.regex.toString(), "/^.*\\.js$/", "returns regex object"); - } + }, }); test({ @@ -64,7 +64,7 @@ test({ true, "match zero characters" ); - } + }, }); test({ @@ -72,7 +72,7 @@ test({ fn(): void { t.equal( match("*.min.js", "http://example.com/jquery.min.js", { - globstar: false + globstar: false, }), true, "complex match" @@ -84,7 +84,7 @@ test({ ); t.equal( match("*/js/*.js", "http://example.com/js/jquery.min.js", { - globstar: false + globstar: false, }), true, "complex match" @@ -171,11 +171,11 @@ test({ t.equal(match("/js*jq*.js", "http://example.com/js/jquery.min.js"), false); t.equal( match("/js*jq*.js", "http://example.com/js/jquery.min.js", { - flags: "g" + flags: "g", }), true ); - } + }, }); test({ @@ -215,7 +215,7 @@ test({ tester(true); tester(false); - } + }, }); test({ @@ -246,7 +246,7 @@ test({ tester(true); tester(false); - } + }, }); test({ @@ -304,7 +304,7 @@ test({ match("[[:digit:]b]/bar.txt", "a/bar.txt", { extended: true }), false ); - } + }, }); test({ @@ -320,7 +320,7 @@ test({ match("foo{bar,baaz}", "foobaaz", { extended: true, globstar, - flag: "g" + flag: "g", }), true ); @@ -328,7 +328,7 @@ test({ match("foo{bar,baaz}", "foobar", { extended: true, globstar, - flag: "g" + flag: "g", }), true ); @@ -336,7 +336,7 @@ test({ match("foo{bar,baaz}", "foobuzz", { extended: true, globstar, - flag: "g" + flag: "g", }), false ); @@ -344,7 +344,7 @@ test({ match("foo{bar,b*z}", "foobuzz", { extended: true, globstar, - flag: "g" + flag: "g", }), true ); @@ -352,7 +352,7 @@ test({ tester(true); tester(false); - } + }, }); test({ @@ -444,7 +444,7 @@ test({ tester(true); tester(false); - } + }, }); test({ @@ -471,7 +471,7 @@ test({ match("http://foo.com/**", "http://foo.com/bar/baz/jquery.min.js", { extended: true, globstar, - flags: "g" + flags: "g", }), true ); @@ -479,7 +479,7 @@ test({ tester(true); tester(false); - } + }, }); test({ @@ -496,7 +496,7 @@ test({ tester(true); tester(false); - } + }, }); test({ @@ -574,25 +574,25 @@ test({ t.equal( match("http://foo.com/*", "http://foo.com/bar/baz/jquery.min.js", { extended: true, - globstar: true + globstar: true, }), false ); t.equal( match("http://foo.com/*", "http://foo.com/bar/baz/jquery.min.js", { - globstar: true + globstar: true, }), false ); t.equal( match("http://foo.com/*", "http://foo.com/bar/baz/jquery.min.js", { - globstar: false + globstar: false, }), true ); t.equal( match("http://foo.com/**", "http://foo.com/bar/baz/jquery.min.js", { - globstar: true + globstar: true, }), true ); @@ -636,7 +636,7 @@ test({ ), false ); - } + }, }); test({ @@ -689,7 +689,7 @@ test({ match("?(ba[!zr]|qux)baz.txt", "bazbaz.txt", { extended: true }), false ); - } + }, }); test({ @@ -715,18 +715,18 @@ test({ t.equal( match("*(foo|bar)/**/*.txt", "foo/hello/world/bar.txt", { extended: true, - globstar: true + globstar: true, }), true ); t.equal( match("*(foo|bar)/**/*.txt", "foo/world/bar.txt", { extended: true, - globstar: true + globstar: true, }), true ); - } + }, }); test({ @@ -736,7 +736,7 @@ test({ t.equal(match("+foo.txt", "+foo.txt", { extended: true }), true); t.equal(match("+(foo).txt", ".txt", { extended: true }), false); t.equal(match("+(foo|bar).txt", "foobar.txt", { extended: true }), true); - } + }, }); test({ @@ -757,7 +757,7 @@ test({ match("@(foo|baz)bar.txt", "toofoobar.txt", { extended: true }), false ); - } + }, }); test({ @@ -774,7 +774,7 @@ test({ match("!({foo,bar})baz.txt", "foobaz.txt", { extended: true }), false ); - } + }, }); test({ @@ -783,7 +783,7 @@ test({ t.equal(match("foo//bar.txt", "foo/bar.txt"), true); t.equal(match("foo///bar.txt", "foo/bar.txt"), true); t.equal(match("foo///bar.txt", "foo/bar.txt", { strict: true }), false); - } + }, }); test({ @@ -791,7 +791,7 @@ test({ fn(): void { t.equal( match("**/*/?yfile.{md,js,txt}", "foo/bar/baz/myfile.md", { - extended: true + extended: true, }), true ); @@ -823,5 +823,5 @@ test({ match("[[:digit:]_.]/file.js", "z/file.js", { extended: true }), false ); - } + }, }); diff --git a/std/path/join_test.ts b/std/path/join_test.ts index a73cf3679..d9a38fb82 100644 --- a/std/path/join_test.ts +++ b/std/path/join_test.ts @@ -53,7 +53,7 @@ const joinTests = [["/", "//foo"], "/foo"], [["/", "", "/foo"], "/foo"], [["", "/", "foo"], "/foo"], - [["", "/", "/foo"], "/foo"] + [["", "/", "/foo"], "/foo"], ]; // Windows-specific join tests @@ -103,11 +103,11 @@ const windowsJoinTests = [ [["c:.", "/"], "c:.\\"], [["c:.", "file"], "c:file"], [["c:", "/"], "c:\\"], - [["c:", "file"], "c:\\file"] + [["c:", "file"], "c:\\file"], ]; test(function join() { - joinTests.forEach(function(p) { + joinTests.forEach(function (p) { const _p = p[0] as string[]; const actual = path.posix.join.apply(null, _p); assertEquals(actual, p[1]); @@ -115,12 +115,12 @@ test(function join() { }); test(function joinWin32() { - joinTests.forEach(function(p) { + joinTests.forEach(function (p) { const _p = p[0] as string[]; const actual = path.win32.join.apply(null, _p).replace(backslashRE, "/"); assertEquals(actual, p[1]); }); - windowsJoinTests.forEach(function(p) { + windowsJoinTests.forEach(function (p) { const _p = p[0] as string[]; const actual = path.win32.join.apply(null, _p); assertEquals(actual, p[1]); diff --git a/std/path/parse_format_test.ts b/std/path/parse_format_test.ts index 0a7e83bba..60be3c9a1 100644 --- a/std/path/parse_format_test.ts +++ b/std/path/parse_format_test.ts @@ -24,15 +24,14 @@ const winPaths = [ ["C:\\", "C:\\"], ["C:\\abc", "C:\\"], ["", ""], - // unc ["\\\\server\\share\\file_path", "\\\\server\\share\\"], [ "\\\\server two\\shared folder\\file path.zip", - "\\\\server two\\shared folder\\" + "\\\\server two\\shared folder\\", ], ["\\\\teela\\admin$\\system32", "\\\\teela\\admin$\\"], - ["\\\\?\\UNC\\server\\share", "\\\\?\\UNC\\"] + ["\\\\?\\UNC\\server\\share", "\\\\?\\UNC\\"], ]; const winSpecialCaseParseTests = [["/foo/bar", { root: "/" }]]; @@ -44,7 +43,7 @@ const winSpecialCaseFormatTests = [ [{ name: "index", ext: ".html" }, "index.html"], [{ dir: "some\\dir", name: "index", ext: ".html" }, "some\\dir\\index.html"], [{ root: "C:\\", name: "index", ext: ".html" }, "C:\\index.html"], - [{}, ""] + [{}, ""], ]; const unixPaths = [ @@ -68,7 +67,7 @@ const unixPaths = [ ["/.", "/"], ["/.foo", "/"], ["/.foo.bar", "/"], - ["/foo/bar.baz", "/"] + ["/foo/bar.baz", "/"], ]; const unixSpecialCaseFormatTests = [ @@ -78,11 +77,11 @@ const unixSpecialCaseFormatTests = [ [{ name: "index", ext: ".html" }, "index.html"], [{ dir: "some/dir", name: "index", ext: ".html" }, "some/dir/index.html"], [{ root: "/", name: "index", ext: ".html" }, "/index.html"], - [{}, ""] + [{}, ""], ]; function checkParseFormat(path: any, paths: any): void { - paths.forEach(function(p: Array<Record<string, unknown>>) { + paths.forEach(function (p: Array<Record<string, unknown>>) { const element = p[0]; const output = path.parse(element); assertEquals(typeof output.root, "string"); @@ -98,18 +97,18 @@ function checkParseFormat(path: any, paths: any): void { } function checkSpecialCaseParseFormat(path: any, testCases: any): void { - testCases.forEach(function(testCase: Array<Record<string, unknown>>) { + testCases.forEach(function (testCase: Array<Record<string, unknown>>) { const element = testCase[0]; const expect = testCase[1]; const output = path.parse(element); - Object.keys(expect).forEach(function(key) { + Object.keys(expect).forEach(function (key) { assertEquals(output[key], expect[key]); }); }); } function checkFormat(path: any, testCases: unknown[][]): void { - testCases.forEach(function(testCase) { + testCases.forEach(function (testCase) { assertEquals(path.format(testCase[0]), testCase[1]); }); } @@ -138,7 +137,7 @@ const windowsTrailingTests = [ ["\\\\", { root: "\\", dir: "\\", base: "", ext: "", name: "" }], [ "c:\\foo\\\\\\", - { root: "c:\\", dir: "c:\\", base: "foo", ext: "", name: "foo" } + { root: "c:\\", dir: "c:\\", base: "foo", ext: "", name: "foo" }, ], [ "D:\\foo\\\\\\bar.baz", @@ -147,9 +146,9 @@ const windowsTrailingTests = [ dir: "D:\\foo\\\\", base: "bar.baz", ext: ".baz", - name: "bar" - } - ] + name: "bar", + }, + ], ]; const posixTrailingTests = [ @@ -159,12 +158,12 @@ const posixTrailingTests = [ ["/foo///", { root: "/", dir: "/", base: "foo", ext: "", name: "foo" }], [ "/foo///bar.baz", - { root: "/", dir: "/foo//", base: "bar.baz", ext: ".baz", name: "bar" } - ] + { root: "/", dir: "/foo//", base: "bar.baz", ext: ".baz", name: "bar" }, + ], ]; test(function parseTrailingWin32() { - windowsTrailingTests.forEach(function(p) { + windowsTrailingTests.forEach(function (p) { const actual = path.win32.parse(p[0] as string); const expected = p[1]; assertEquals(actual, expected); @@ -172,7 +171,7 @@ test(function parseTrailingWin32() { }); test(function parseTrailing() { - posixTrailingTests.forEach(function(p) { + posixTrailingTests.forEach(function (p) { const actual = path.posix.parse(p[0] as string); const expected = p[1]; assertEquals(actual, expected); diff --git a/std/path/posix.ts b/std/path/posix.ts index 4377fd542..ba4cf7499 100644 --- a/std/path/posix.ts +++ b/std/path/posix.ts @@ -9,7 +9,7 @@ import { assertPath, normalizeString, isPosixPathSeparator, - _format + _format, } from "./utils.ts"; export const sep = "/"; @@ -205,8 +205,9 @@ export function dirname(path: string): string { } export function basename(path: string, ext = ""): string { - if (ext !== undefined && typeof ext !== "string") + if (ext !== undefined && typeof ext !== "string") { throw new TypeError('"ext" argument must be a string'); + } assertPath(path); let start = 0; diff --git a/std/path/relative_test.ts b/std/path/relative_test.ts index 3fe5aab4b..af5896236 100644 --- a/std/path/relative_test.ts +++ b/std/path/relative_test.ts @@ -6,58 +6,52 @@ import { assertEquals } from "../testing/asserts.ts"; import * as path from "./mod.ts"; const relativeTests = { - win32: - // arguments result - [ - ["c:/blah\\blah", "d:/games", "d:\\games"], - ["c:/aaaa/bbbb", "c:/aaaa", ".."], - ["c:/aaaa/bbbb", "c:/cccc", "..\\..\\cccc"], - ["c:/aaaa/bbbb", "c:/aaaa/bbbb", ""], - ["c:/aaaa/bbbb", "c:/aaaa/cccc", "..\\cccc"], - ["c:/aaaa/", "c:/aaaa/cccc", "cccc"], - ["c:/", "c:\\aaaa\\bbbb", "aaaa\\bbbb"], - ["c:/aaaa/bbbb", "d:\\", "d:\\"], - ["c:/AaAa/bbbb", "c:/aaaa/bbbb", ""], - ["c:/aaaaa/", "c:/aaaa/cccc", "..\\aaaa\\cccc"], - ["C:\\foo\\bar\\baz\\quux", "C:\\", "..\\..\\..\\.."], - [ - "C:\\foo\\test", - "C:\\foo\\test\\bar\\package.json", - "bar\\package.json" - ], - ["C:\\foo\\bar\\baz-quux", "C:\\foo\\bar\\baz", "..\\baz"], - ["C:\\foo\\bar\\baz", "C:\\foo\\bar\\baz-quux", "..\\baz-quux"], - ["\\\\foo\\bar", "\\\\foo\\bar\\baz", "baz"], - ["\\\\foo\\bar\\baz", "\\\\foo\\bar", ".."], - ["\\\\foo\\bar\\baz-quux", "\\\\foo\\bar\\baz", "..\\baz"], - ["\\\\foo\\bar\\baz", "\\\\foo\\bar\\baz-quux", "..\\baz-quux"], - ["C:\\baz-quux", "C:\\baz", "..\\baz"], - ["C:\\baz", "C:\\baz-quux", "..\\baz-quux"], - ["\\\\foo\\baz-quux", "\\\\foo\\baz", "..\\baz"], - ["\\\\foo\\baz", "\\\\foo\\baz-quux", "..\\baz-quux"], - ["C:\\baz", "\\\\foo\\bar\\baz", "\\\\foo\\bar\\baz"], - ["\\\\foo\\bar\\baz", "C:\\baz", "C:\\baz"] - ], - posix: - // arguments result - [ - ["/var/lib", "/var", ".."], - ["/var/lib", "/bin", "../../bin"], - ["/var/lib", "/var/lib", ""], - ["/var/lib", "/var/apache", "../apache"], - ["/var/", "/var/lib", "lib"], - ["/", "/var/lib", "var/lib"], - ["/foo/test", "/foo/test/bar/package.json", "bar/package.json"], - ["/Users/a/web/b/test/mails", "/Users/a/web/b", "../.."], - ["/foo/bar/baz-quux", "/foo/bar/baz", "../baz"], - ["/foo/bar/baz", "/foo/bar/baz-quux", "../baz-quux"], - ["/baz-quux", "/baz", "../baz"], - ["/baz", "/baz-quux", "../baz-quux"] - ] + // arguments result + win32: [ + ["c:/blah\\blah", "d:/games", "d:\\games"], + ["c:/aaaa/bbbb", "c:/aaaa", ".."], + ["c:/aaaa/bbbb", "c:/cccc", "..\\..\\cccc"], + ["c:/aaaa/bbbb", "c:/aaaa/bbbb", ""], + ["c:/aaaa/bbbb", "c:/aaaa/cccc", "..\\cccc"], + ["c:/aaaa/", "c:/aaaa/cccc", "cccc"], + ["c:/", "c:\\aaaa\\bbbb", "aaaa\\bbbb"], + ["c:/aaaa/bbbb", "d:\\", "d:\\"], + ["c:/AaAa/bbbb", "c:/aaaa/bbbb", ""], + ["c:/aaaaa/", "c:/aaaa/cccc", "..\\aaaa\\cccc"], + ["C:\\foo\\bar\\baz\\quux", "C:\\", "..\\..\\..\\.."], + ["C:\\foo\\test", "C:\\foo\\test\\bar\\package.json", "bar\\package.json"], + ["C:\\foo\\bar\\baz-quux", "C:\\foo\\bar\\baz", "..\\baz"], + ["C:\\foo\\bar\\baz", "C:\\foo\\bar\\baz-quux", "..\\baz-quux"], + ["\\\\foo\\bar", "\\\\foo\\bar\\baz", "baz"], + ["\\\\foo\\bar\\baz", "\\\\foo\\bar", ".."], + ["\\\\foo\\bar\\baz-quux", "\\\\foo\\bar\\baz", "..\\baz"], + ["\\\\foo\\bar\\baz", "\\\\foo\\bar\\baz-quux", "..\\baz-quux"], + ["C:\\baz-quux", "C:\\baz", "..\\baz"], + ["C:\\baz", "C:\\baz-quux", "..\\baz-quux"], + ["\\\\foo\\baz-quux", "\\\\foo\\baz", "..\\baz"], + ["\\\\foo\\baz", "\\\\foo\\baz-quux", "..\\baz-quux"], + ["C:\\baz", "\\\\foo\\bar\\baz", "\\\\foo\\bar\\baz"], + ["\\\\foo\\bar\\baz", "C:\\baz", "C:\\baz"], + ], + // arguments result + posix: [ + ["/var/lib", "/var", ".."], + ["/var/lib", "/bin", "../../bin"], + ["/var/lib", "/var/lib", ""], + ["/var/lib", "/var/apache", "../apache"], + ["/var/", "/var/lib", "lib"], + ["/", "/var/lib", "var/lib"], + ["/foo/test", "/foo/test/bar/package.json", "bar/package.json"], + ["/Users/a/web/b/test/mails", "/Users/a/web/b", "../.."], + ["/foo/bar/baz-quux", "/foo/bar/baz", "../baz"], + ["/foo/bar/baz", "/foo/bar/baz-quux", "../baz-quux"], + ["/baz-quux", "/baz", "../baz"], + ["/baz", "/baz-quux", "../baz-quux"], + ], }; test(function relative() { - relativeTests.posix.forEach(function(p) { + relativeTests.posix.forEach(function (p) { const expected = p[2]; const actual = path.posix.relative(p[0], p[1]); assertEquals(actual, expected); @@ -65,7 +59,7 @@ test(function relative() { }); test(function relativeWin32() { - relativeTests.win32.forEach(function(p) { + relativeTests.win32.forEach(function (p) { const expected = p[2]; const actual = path.win32.relative(p[0], p[1]); assertEquals(actual, expected); diff --git a/std/path/resolve_test.ts b/std/path/resolve_test.ts index 2fc49e398..95aa84cce 100644 --- a/std/path/resolve_test.ts +++ b/std/path/resolve_test.ts @@ -20,8 +20,8 @@ const windowsTests = [["c:/", "///some//dir"], "c:\\some\\dir"], [ ["C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js"], - "C:\\foo\\tmp.3\\cycles\\root.js" - ] + "C:\\foo\\tmp.3\\cycles\\root.js", + ], ]; const posixTests = // arguments result @@ -31,11 +31,11 @@ const posixTests = [["a/b/c/", "../../.."], cwd()], [["."], cwd()], [["/some/dir", ".", "/absolute/"], "/absolute"], - [["/foo/tmp.3/", "../tmp.3/cycles/root.js"], "/foo/tmp.3/cycles/root.js"] + [["/foo/tmp.3/", "../tmp.3/cycles/root.js"], "/foo/tmp.3/cycles/root.js"], ]; test(function resolve() { - posixTests.forEach(function(p) { + posixTests.forEach(function (p) { const _p = p[0] as string[]; const actual = path.posix.resolve.apply(null, _p); assertEquals(actual, p[1]); @@ -43,7 +43,7 @@ test(function resolve() { }); test(function resolveWin32() { - windowsTests.forEach(function(p) { + windowsTests.forEach(function (p) { const _p = p[0] as string[]; const actual = path.win32.resolve.apply(null, _p); assertEquals(actual, p[1]); diff --git a/std/path/utils.ts b/std/path/utils.ts index cb1c14c16..fc3dc5be9 100644 --- a/std/path/utils.ts +++ b/std/path/utils.ts @@ -9,7 +9,7 @@ import { CHAR_LOWERCASE_Z, CHAR_DOT, CHAR_FORWARD_SLASH, - CHAR_BACKWARD_SLASH + CHAR_BACKWARD_SLASH, } from "./constants.ts"; export function assertPath(path: string): void { diff --git a/std/path/win32.ts b/std/path/win32.ts index 2f28d22c1..d4febf706 100644 --- a/std/path/win32.ts +++ b/std/path/win32.ts @@ -7,7 +7,7 @@ import { CHAR_DOT, CHAR_BACKWARD_SLASH, CHAR_COLON, - CHAR_QUESTION_MARK + CHAR_QUESTION_MARK, } from "./constants.ts"; import { @@ -15,7 +15,7 @@ import { isPathSeparator, isWindowsDeviceRoot, normalizeString, - _format + _format, } from "./utils.ts"; import { assert } from "../testing/asserts.ts"; @@ -259,8 +259,9 @@ export function normalize(path: string): string { tail = ""; } if (tail.length === 0 && !isAbsolute) tail = "."; - if (tail.length > 0 && isPathSeparator(path.charCodeAt(len - 1))) + if (tail.length > 0 && isPathSeparator(path.charCodeAt(len - 1))) { tail += "\\"; + } if (device === undefined) { if (isAbsolute) { if (tail.length > 0) return `\\${tail}`; @@ -459,8 +460,9 @@ export function relative(from: string, to: string): string { // Lastly, append the rest of the destination (`to`) path that comes after // the common path parts - if (out.length > 0) return out + toOrig.slice(toStart + lastCommonSep, toEnd); - else { + if (out.length > 0) { + return out + toOrig.slice(toStart + lastCommonSep, toEnd); + } else { toStart += lastCommonSep; if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) ++toStart; return toOrig.slice(toStart, toEnd); @@ -590,8 +592,9 @@ export function dirname(path: string): string { } export function basename(path: string, ext = ""): string { - if (ext !== undefined && typeof ext !== "string") + if (ext !== undefined && typeof ext !== "string") { throw new TypeError('"ext" argument must be a string'); + } assertPath(path); |