From 43e8825531f44a4fbd57599e7b46f61e63f74271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez=20Jim=C3=A9nez?= Date: Mon, 13 Sep 2021 23:11:31 +0200 Subject: [PATCH] chore: allow load collection from custom json --- lib/finder.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/finder.ts b/lib/finder.ts index f7c44d2..6e11dbf 100644 --- a/lib/finder.ts +++ b/lib/finder.ts @@ -8,7 +8,7 @@ * For the full copyright and license information, please view the license.txt * file that is available in this file's directory. */ -import { promises as fs } from 'fs' +import { PathLike, promises as fs } from 'fs' import { fileURLToPath } from 'url' import { dirname, resolve } from 'upath' @@ -401,7 +401,17 @@ export const rootDir = () => dir * @param {string} name Collection name * @returns {string} Path to collection json file */ -export const locate = (name: string) => `${dir}/json/${name}.json` +export const locate = (name: string): PathLike => `${dir}/json/${name}.json` + +/** + * Loads a collection. + * + * @param {PathLike} path The path to locate the `json` collection file. + * @return {Promise} + */ +export const loadCollection = async(path: PathLike): Promise => { + return JSON.parse(await fs.readFile(path, 'utf8')) +} /** * Get a collection. @@ -410,7 +420,7 @@ export const locate = (name: string) => `${dir}/json/${name}.json` * @return {Promise} */ export const collection = async(name: string): Promise => { - return JSON.parse(await fs.readFile(locate(name), 'utf8')) + return await loadCollection(locate(name)) } /**