diff --git a/core/shared/config/helpers.js b/core/shared/config/helpers.js index 1acb43637f..1d64d43470 100644 --- a/core/shared/config/helpers.js +++ b/core/shared/config/helpers.js @@ -1,5 +1,10 @@ const path = require('path'); +/** + * @callback isPrivacyDisabledFn + * @param {string} privacyFlag - the flag to be looked up + * @returns {boolean} + */ const isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) { if (!this.get('privacy')) { return false; @@ -19,7 +24,9 @@ const isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) { }; /** - * we can later support setting folder names via custom config values + * @callback getContentPathFn + * @param {string} type - the type of context you want the path for + * @returns {string} */ const getContentPath = function getContentPath(type) { switch (type) { @@ -43,7 +50,12 @@ const getContentPath = function getContentPath(type) { } }; -module.exports = { - isPrivacyDisabled, - getContentPath +/** + * @typedef ConfigHelpers + * @property {isPrivacyDisabledFn} isPrivacyDisabled + * @property {getContentPathFn} getContentPath + */ +module.exports.bindAll = (nconf) => { + nconf.isPrivacyDisabled = isPrivacyDisabled.bind(nconf); + nconf.getContentPath = getContentPath.bind(nconf); }; diff --git a/core/shared/config/loader.js b/core/shared/config/loader.js index 8c2c4c43bd..2ebd87139d 100644 --- a/core/shared/config/loader.js +++ b/core/shared/config/loader.js @@ -11,7 +11,7 @@ const env = process.env.NODE_ENV || 'development'; /** * @param {object} options - * @returns {Nconf.Provider & urlHelpers.BoundHelpers} + * @returns {Nconf.Provider & urlHelpers.BoundHelpers & helpers.ConfigHelpers} */ function loadNconf(options) { debug('config start'); @@ -50,8 +50,7 @@ function loadNconf(options) { nconf.checkUrlProtocol = localUtils.checkUrlProtocol.bind(nconf); // Expose dynamic utility methods - nconf.isPrivacyDisabled = helpers.isPrivacyDisabled.bind(nconf); - nconf.getContentPath = helpers.getContentPath.bind(nconf); + helpers.bindAll(nconf); urlHelpers.bindAll(nconf); // ## Sanitization