From 12c6055855af37d00be953080370909d0d7ea9b1 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Thu, 30 Apr 2020 03:36:44 +0200 Subject: Cleanup std/node/fs functions (#5000) --- std/node/_fs/_fs_chmod.ts | 6 ++---- std/node/_fs/_fs_copy.ts | 6 +----- std/node/_fs/_fs_mkdir.ts | 11 ++++------- 3 files changed, 7 insertions(+), 16 deletions(-) (limited to 'std/node/_fs') diff --git a/std/node/_fs/_fs_chmod.ts b/std/node/_fs/_fs_chmod.ts index 306113047..2adff59ff 100644 --- a/std/node/_fs/_fs_chmod.ts +++ b/std/node/_fs/_fs_chmod.ts @@ -31,10 +31,8 @@ function getResolvedMode(mode: string | number): number { return mode; } - if (typeof mode === "string") { - if (!allowedModes.test(mode)) { - throw new Error("Unrecognized mode: " + mode); - } + if (typeof mode === "string" && !allowedModes.test(mode)) { + throw new Error("Unrecognized mode: " + mode); } return parseInt(mode, 8); diff --git a/std/node/_fs/_fs_copy.ts b/std/node/_fs/_fs_copy.ts index 320c2fb3e..0193e77c4 100644 --- a/std/node/_fs/_fs_copy.ts +++ b/std/node/_fs/_fs_copy.ts @@ -13,9 +13,5 @@ export function copyFile( } export function copyFileSync(source: string, destination: string): void { - try { - Deno.copyFileSync(source, destination); - } catch (err) { - throw err; - } + Deno.copyFileSync(source, destination); } diff --git a/std/node/_fs/_fs_mkdir.ts b/std/node/_fs/_fs_mkdir.ts index 6e5439a38..fd2156c37 100644 --- a/std/node/_fs/_fs_mkdir.ts +++ b/std/node/_fs/_fs_mkdir.ts @@ -35,12 +35,12 @@ export function mkdir( ); Deno.mkdir(path, { recursive, mode }) .then(() => { - if (callback && typeof callback == "function") { + if (typeof callback === "function") { callback(); } }) .catch((err) => { - if (callback && typeof callback == "function") { + if (typeof callback === "function") { callback(err); } }); @@ -62,9 +62,6 @@ export function mkdirSync(path: Path, options?: MkdirOptions): void { throw new Deno.errors.InvalidData( "invalid recursive option , must be a boolean" ); - try { - Deno.mkdirSync(path, { recursive, mode }); - } catch (err) { - throw err; - } + + Deno.mkdirSync(path, { recursive, mode }); } -- cgit v1.2.3