From 5cafa79c7a81658fdfa8c4602a7fb0a52d0d8fe9 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 29 May 2022 17:24:23 +0200 Subject: [PATCH] Add normalize() to `path` --- .../normalize/lib/keywords/list/path/main.js | 6 +++--- .../list/path/{check.js => normalize.js} | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) rename src/config/normalize/lib/keywords/list/path/{check.js => normalize.js} (62%) diff --git a/src/config/normalize/lib/keywords/list/path/main.js b/src/config/normalize/lib/keywords/list/path/main.js index 4758ce1d..f879b007 100644 --- a/src/config/normalize/lib/keywords/list/path/main.js +++ b/src/config/normalize/lib/keywords/list/path/main.js @@ -3,14 +3,13 @@ import { resolve } from 'path' import { validateDefinedString } from '../../../type.js' import { validateAccess } from './access.js' -import { checkKeywords } from './check.js' +import { normalize } from './normalize.js' import { fileExists, validateExists } from './exist.js' import { validateType } from './type.js' -const main = async function (definition, input, { cwd }) { +const main = async function (keywords, input, { cwd }) { validateDefinedString(input) const inputA = resolve(cwd, input) - const keywords = checkKeywords(definition) await validateFile(inputA, keywords) return { input: inputA } } @@ -37,5 +36,6 @@ const validateFile = async function (input, keywords) { export default { name: 'path', hasInput: true, + normalize, main, } diff --git a/src/config/normalize/lib/keywords/list/path/check.js b/src/config/normalize/lib/keywords/list/path/normalize.js similarity index 62% rename from src/config/normalize/lib/keywords/list/path/check.js rename to src/config/normalize/lib/keywords/list/path/normalize.js index b1339f55..5e5395ff 100644 --- a/src/config/normalize/lib/keywords/list/path/check.js +++ b/src/config/normalize/lib/keywords/list/path/normalize.js @@ -1,22 +1,22 @@ -// Ensure the `path` value is correct -export const checkKeywords = function (keywords) { - if (!Array.isArray(keywords)) { - throw new TypeError(`The "path" must be an array.`) +// Ensure the `path` definition is correct +export const normalize = function (definition) { + if (!Array.isArray(definition)) { + throw new TypeError(`The definition must be an array.`) } - keywords.forEach(checkKeyword) - return new Set(keywords) + definition.forEach(checkKeyword) + return new Set(definition) } const checkKeyword = function (keyword) { if (typeof keyword !== 'string') { - throw new TypeError(`The "path" value ${keyword} must be a string.`) + throw new TypeError(`The definition value ${keyword} must be a string.`) } if (!KEYWORDS_SET.has(keyword)) { const availableKeywords = KEYWORDS.map(quoteWord).join(', ') throw new TypeError( - `The "path" value "${keyword}" must be one of: ${availableKeywords}`, + `The definition value "${keyword}" must be one of: ${availableKeywords}`, ) } }