Skip to content

Commit

Permalink
Add normalize() to path
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 29, 2022
1 parent 56a6e54 commit 5cafa79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/config/normalize/lib/keywords/list/path/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand All @@ -37,5 +36,6 @@ const validateFile = async function (input, keywords) {
export default {
name: 'path',
hasInput: true,
normalize,
main,
}
Original file line number Diff line number Diff line change
@@ -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}`,
)
}
}
Expand Down

0 comments on commit 5cafa79

Please sign in to comment.