1 | "use strict";
|
2 |
|
3 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
4 |
|
5 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6 |
|
7 | const inflection = require('inflection');
|
8 |
|
9 | const changeCase = require('change-case');
|
10 |
|
11 |
|
12 | inflection.undasherize = str => str.split(/[-_]/).map(w => w[0].toUpperCase() + w.slice(1).toLowerCase()).join('');
|
13 |
|
14 | const helpers = {
|
15 | capitalize(string) {
|
16 | return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
|
17 | },
|
18 |
|
19 | inflection,
|
20 | changeCase
|
21 | };
|
22 |
|
23 | const doCapitalization = (hsh, [key, value]) => {
|
24 | hsh[key] = value;
|
25 | if (localsToCapitalize.includes(key)) hsh[helpers.capitalize(key)] = helpers.capitalize(value);
|
26 | return hsh;
|
27 | };
|
28 |
|
29 | const localsToCapitalize = ['name'];
|
30 | const localsDefaults = {
|
31 | name: 'unnamed'
|
32 | };
|
33 |
|
34 | const capitalizedLocals = locals => Object.entries(locals).reduce(doCapitalization, {});
|
35 |
|
36 | const context = (locals, config) => {
|
37 | const localsWithDefaults = Object.assign({}, localsDefaults, locals);
|
38 | const configHelpers = config && (typeof config.helpers === "function" ? config.helpers(locals, config) : config.helpers) || {};
|
39 | return Object.assign(localsWithDefaults, capitalizedLocals(localsWithDefaults), {
|
40 | h: _objectSpread({}, helpers, configHelpers)
|
41 | });
|
42 | };
|
43 |
|
44 | module.exports = context; |
\ | No newline at end of file |