Skip to content

Commit

Permalink
feat: split helpers into modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Aug 14, 2024
1 parent 045f97c commit 45bd759
Show file tree
Hide file tree
Showing 5 changed files with 428 additions and 405 deletions.
31 changes: 31 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict'

function createHelpersNamespaceObject(helpers, defaults = {}) {
const helperNames = Object.keys(helpers).sort()
const propNames = [
...new Set([...Object.values(helpers)].map(Object.keys).flat())
].sort()
const nsObject = Object.create(null)
for (let i = 0, { length } = propNames; i < length; i += 1) {
const propName = propNames[i]
const helpersForProp = Object.create(null)
for (
let j = 0, { length: length_j } = helperNames;
j < length_j;
j += 1
) {
const helperName = helperNames[j]
const helperValue =
helpers[helperName][propName] ?? defaults[helperName]
if (helperValue !== undefined) {
helpersForProp[helperName] = helperValue
}
}
nsObject[propName] = helpersForProp
}
return nsObject
}

module.exports = {
createHelpersNamespaceObject
}
Loading

0 comments on commit 45bd759

Please sign in to comment.