Skip to content

Commit

Permalink
Refactor normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 16, 2022
1 parent cd0537f commit 5fd0efd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/config/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const checkArrayLength = function (value, name) {

export const checkDefinedStringArray = function (value, name) {
value.forEach((item, index) => {
checkString(value, name)
checkDefinedString(item, getIndexName(index, name))
})
}
Expand All @@ -56,14 +57,12 @@ const getIndexName = function (index, name) {
}

export const checkDefinedString = function (value, name) {
checkString(value, name)

if (value.trim() === '') {
throw new UserError(`'${name}' must not be empty.`)
}
}

const checkString = function (value, name) {
export const checkString = function (value, name) {
if (typeof value !== 'string') {
throw new UserError(`'${name}' must be a string: ${inspect(value)}`)
}
Expand Down
2 changes: 2 additions & 0 deletions src/config/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { normalizePrecision } from '../run/precision.js'
import {
checkBoolean,
checkInteger,
checkString,
normalizeOptionalArray,
checkArrayLength,
checkStringArray,
Expand Down Expand Up @@ -67,6 +68,7 @@ const applyNormalizer = function (value, name, normalizer) {

const validateTitles = function (value, name) {
Object.entries(value).forEach(([childName, propValue]) => {
checkString(propValue, `${name}.${childName}`)
checkDefinedString(propValue, `${name}.${childName}`)
})
}
Expand Down

0 comments on commit 5fd0efd

Please sign in to comment.