UNPKG

1.32 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const inflection = require('inflection');
4const changeCase = require('change-case');
5// supports kebab-case to KebabCase
6inflection.undasherize = str => str.split(/[-_]/).map(w => w[0].toUpperCase() + w.slice(1).toLowerCase()).join('');
7const helpers = {
8 capitalize(string) {
9 return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
10 },
11 inflection,
12 changeCase
13};
14const doCapitalization = (hsh, [key, value]) => {
15 hsh[key] = value;
16 if (localsToCapitalize.includes(key))
17 hsh[helpers.capitalize(key)] = helpers.capitalize(value);
18 return hsh;
19};
20const localsToCapitalize = ['name'];
21const localsDefaults = {
22 name: 'unnamed'
23};
24const capitalizedLocals = (locals) => Object.entries(locals).reduce(doCapitalization, {});
25const context = (locals, config) => {
26 const localsWithDefaults = Object.assign({}, localsDefaults, locals);
27 const configHelpers = config && (typeof config.helpers === "function" ? config.helpers(locals, config) : config.helpers) || {};
28 return Object.assign(localsWithDefaults, capitalizedLocals(localsWithDefaults), {
29 h: Object.assign(Object.assign({}, helpers), configHelpers)
30 });
31};
32module.exports = context;
33//# sourceMappingURL=context.js.map
\No newline at end of file