From 7d2865d9bd2eade185c6d6d5271bdf653e6a72db Mon Sep 17 00:00:00 2001 From: Thomas Queste Date: Thu, 14 Nov 2024 06:53:11 +0100 Subject: [PATCH] refactor: remove useless use of composable --- src/index.ts | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index b0aaa4f..a6e3b06 100755 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import { promises as fs } from "node:fs"; import { sep } from "node:path"; -import { type Result, composable, pipe, success } from "composable-functions"; +import { type Result, pipe, success } from "composable-functions"; type Command = () => Promise; @@ -25,42 +25,39 @@ const loanCommand = async (): Promise => { return success(undefined); }; -const getHomeDir = composable( - (env: Record): string => { - const home = env.HOME; - if (home) return home; - throw new Error("unable to find home directory"); - }, -); +const getHomeDir = (env: Record): string => { + const home = env.HOME; + if (home) return home; + throw new Error("unable to find home directory"); +}; const getConfigFilename = (homeDir: string): string => `${homeDir}${sep}.config${sep}mediathequeroubaix${sep}config.json`; -const fileExist = composable(async (file: string): Promise => { +const fileExist = async (file: string): Promise => { try { await fs.access(file, fs.constants.R_OK); return file; } catch (e: unknown) { throw new Error(`file '${file}' is not readable: ${e}`); } -}); +}; -const readFile = composable( - (filename: string): Promise => fs.readFile(filename, "utf-8"), -); +const readFile = (filename: string): Promise => + fs.readFile(filename, "utf-8"); -const parseJson = composable((text: string): Promise => { +const parseJson = (text: string): Promise => { try { return JSON.parse(text); } catch (e: unknown) { throw new Error(`Unable to parse JSON: ${text}. Error: ${e}`); } -}); +}; -const printConfig = composable((config: object): Promise => { +const printConfig = (config: object): Promise => { console.log(JSON.stringify(config, null, 2)); return Promise.resolve(); -}); +}; const showConfigCommand = async (): Promise => { const showConfig = pipe(