diff --git a/index.js b/index.js index b224f8c..9f554df 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,17 @@ // eslint-disable-next-line eslint-comments/disable-enable-pair -/* eslint-disable security/detect-object-injection */ +/* eslint-disable security/detect-non-literal-fs-filename, security/detect-object-injection */ import fs from 'node:fs/promises'; +import path from 'node:path'; let codeTypes = {}; let codeTypeFieldValues = {}; +const currentFolder = path.dirname(import.meta.filename ?? '.'); /** * Returns an object of code types. * @returns {Promise>} - An object with "code type" keys and "code type description" values. */ export async function getCodeTypes() { if (Object.keys(codeTypes).length === 0) { - const codeTypesData = await fs.readFile('./data/codeTypes.json'); + const codeTypesData = await fs.readFile(path.join(currentFolder, 'data', 'codeTypes.json')); codeTypes = JSON.parse(codeTypesData); } return codeTypes; @@ -40,8 +42,7 @@ export async function getCodeTypeDescription(codeType) { export async function getFieldValues(codeType) { if ((await isCodeType(codeType)) && !Object.hasOwn(codeTypeFieldValues, codeType)) { - // eslint-disable-next-line security/detect-non-literal-fs-filename - const fieldValueData = await fs.readFile(`./data/${codeType}.json`); + const fieldValueData = await fs.readFile(path.join(currentFolder, 'data', `${codeType}.json`)); codeTypeFieldValues[codeType] = JSON.parse(fieldValueData); } return codeTypeFieldValues[codeType] ?? {}; diff --git a/index.ts b/index.ts index 6e026ed..ebda0dd 100644 --- a/index.ts +++ b/index.ts @@ -1,18 +1,21 @@ // eslint-disable-next-line eslint-comments/disable-enable-pair -/* eslint-disable security/detect-object-injection */ +/* eslint-disable security/detect-non-literal-fs-filename, security/detect-object-injection */ import fs from 'node:fs/promises' +import path from 'node:path' let codeTypes: Record = {} let codeTypeFieldValues: Record> = {} +const currentFolder = path.dirname(import.meta.filename ?? '.') + /** * Returns an object of code types. * @returns {Promise>} - An object with "code type" keys and "code type description" values. */ export async function getCodeTypes(): Promise> { if (Object.keys(codeTypes).length === 0) { - const codeTypesData = await fs.readFile('./data/codeTypes.json') + const codeTypesData = await fs.readFile(path.join(currentFolder, 'data', 'codeTypes.json')) codeTypes = JSON.parse(codeTypesData as unknown as string) } @@ -53,8 +56,7 @@ export async function getFieldValues( (await isCodeType(codeType)) && !Object.hasOwn(codeTypeFieldValues, codeType) ) { - // eslint-disable-next-line security/detect-non-literal-fs-filename - const fieldValueData = await fs.readFile(`./data/${codeType}.json`) + const fieldValueData = await fs.readFile(path.join(currentFolder, 'data', `${codeType}.json`)) codeTypeFieldValues[codeType] = JSON.parse( fieldValueData as unknown as string diff --git a/package-lock.json b/package-lock.json index 95bcf11..4f62163 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@cityssm/ncic-lookup", - "version": "0.1.0", + "version": "0.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@cityssm/ncic-lookup", - "version": "0.1.0", + "version": "0.1.1", "license": "MIT", "devDependencies": { "@types/mocha": "^10.0.6", diff --git a/package.json b/package.json index 4e98659..3bf1aa1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cityssm/ncic-lookup", - "version": "0.1.0", + "version": "0.1.1", "type": "module", "engines": { "node": ">=18.0.0" @@ -16,6 +16,7 @@ "coverage": "c8 mocha" }, "keywords": [ + "automobiles", "ncic", "neim", "vma"