Skip to content

Commit

Permalink
[environment] add ensureConf helper
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Feb 17, 2024
1 parent 8c6c9d9 commit 8a5f0b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion component.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export const defineListComponent = createComponentDefiner(() => {
component.removeChild(prevChild)
}
// insert remaining
component.insertBefore(dom.fragment(insert.slice(insertStart).map(insState => {
component.insertBefore(dom.fragment(insert.slice(insertStart).map(/** @param {any} insState */ insState => {
const el = new Item()
el.setState(insState)
return el
Expand Down
13 changes: 12 additions & 1 deletion environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const getParam = (name, defaultVal) =>
/* c8 ignore next 4 */
export const getVariable = (name) =>
isNode
? conditions.undefinedToNull(process.env[name.toUpperCase()])
? conditions.undefinedToNull(process.env[name.toUpperCase().replaceAll('-', '_')])
: conditions.undefinedToNull(storage.varStorage.getItem(name))

/**
Expand All @@ -105,6 +105,17 @@ export const getVariable = (name) =>
export const getConf = (name) =>
computeParams().get('--' + name) || getVariable(name)

/**
* @param {string} name
* @return {string}
*/
/* c8 ignore next 5 */
export const ensureConf = (name) => {
const c = getConf(name)
if (c == null) throw new Error(`Expected configuration "${name.toUpperCase().replaceAll('-', '_')}"`)
return c
}

/**
* @param {string} name
* @return {boolean}
Expand Down

0 comments on commit 8a5f0b1

Please sign in to comment.