@whook/whook
Version:
Build strong and efficient REST web services.
30 lines • 1.42 kB
JavaScript
import { noop } from 'common-services';
import { location, autoService, name } from 'knifecycle';
/**
* Allow to proxy constants directly by serializing it in the
* build, saving some computing and increasing boot time of
* the build.
* @param {Object} BUILD_CONSTANTS_NAMES
* The serializable constants name to gather
* @param {Object} BUILD_CONSTANTS_PREFIXES
* The serializable constants name prefixes to gather
* @param {Object} BUILD_CONSTANTS_SUFFIXES
* The serializable constants name suffixes to gather
* @param {Object} [services.log=noop]
* An optional logging service
* @return {Promise<Function>}
* A promise of filter function.
*/
async function initBuildConstantFilter({ BUILD_CONSTANTS_NAMES = [], BUILD_CONSTANTS_PREFIXES = [], BUILD_CONSTANTS_SUFFIXES = [], log = noop, }) {
return (name) => {
const isConstant = BUILD_CONSTANTS_NAMES.some((constantName) => name === constantName) ||
BUILD_CONSTANTS_PREFIXES.some((constantName) => name.startsWith(constantName)) ||
BUILD_CONSTANTS_SUFFIXES.some((constantName) => name.endsWith(constantName));
if (isConstant) {
log('debug', `🔧 - Flagged ${name} as a constant.`);
}
return isConstant;
};
}
export default location(name('BUILD_CONSTANT_FILTER', autoService(initBuildConstantFilter)), import.meta.url);
//# sourceMappingURL=BUILD_CONSTANT_FILTER.js.map