Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'require-glob' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
var data = options.data,
dataEach = options.dataEach,
debug = options.debug,
includeFile = options.file;
// Default to `true`
if (includeFile == null) {
includeFile = true;
}
// Generate data
if (data) {
options.keygen = options.parseDataName;
options.reducer = options.dataReducer;
data = requireGlob.sync(data, options);
}
// Register helpers and partials
registrar(hb.handlebars, options);
// Stream it
return through.obj(function (file, enc, cb) {
var context, template,
hbs = hb.handlebars;
try {
context = mixin({}, data);
if (includeFile) {
context.file = file;
}
// Register helpers
if (helpers) {
options.keygen = options.parseHelperName || parseHelperName;
options.reducer = options.helpersReducer || reducer.bind(options);
helpers = requireGlob.sync(helpers, options);
handlebars.registerHelper(helpers);
}
// Register partials
if (partials) {
options.keygen = options.parsePartialName || parsePartialName;
options.reducer = options.partialsReducer || reducer.bind(options);
partials = requireGlob.sync(partials, options);
handlebars.registerPartial(partials);
}
return handlebars;
}
function registrar(handlebars, options) {
options = options || {};
var helpers = options.helpers,
partials = options.partials;
// Expose handlebars to custom reducers
options.handlebars = handlebars;
// Register helpers
if (helpers) {
options.keygen = options.parseHelperName || parseHelperName;
options.reducer = options.helpersReducer || reducer.bind(options);
helpers = requireGlob.sync(helpers, options);
handlebars.registerHelper(helpers);
}
// Register partials
if (partials) {
options.keygen = options.parsePartialName || parsePartialName;
options.reducer = options.partialsReducer || reducer.bind(options);
partials = requireGlob.sync(partials, options);
handlebars.registerPartial(partials);
}
return handlebars;
}
if (getTypeOf(value) === TYPE_FUNCTION) {
value = value(options.handlebars, options);
if (getTypeOf(value) === TYPE_OBJECT) {
return value;
}
return {};
}
if (getTypeOf(value) === TYPE_OBJECT) {
return reducer(options, {}, {exports: value});
}
return requireGlob.sync(value, options);
}
public static loadServices(router: express.Router, patterns: string | Array, baseDir?: string) {
serverDebugger('Loading typescript-rest services %j. BaseDir: %s', patterns, baseDir);
const importedTypes: Array = [];
const requireGlob = require('require-glob');
baseDir = baseDir || process.cwd();
const loadedModules: Array = requireGlob.sync(patterns, {
cwd: baseDir
});
_.values(loadedModules).forEach(serviceModule => {
_.values(serviceModule)
.filter((service: Function) => typeof service === 'function')
.forEach((service: Function) => {
importedTypes.push(service);
});
});
try {
Server.buildServices(router, ...importedTypes);
} catch (e) {
serverDebugger('Error loading services for pattern: %j. Error: %o', patterns, e);
serverDebugger('ImportedTypes: %o', importedTypes);
const requireGLob = require('require-glob');
const helpers = require('../../config/helpers');
const { flatten } = helpers;
module.exports = flatten(requireGLob.sync(['**/*.json']), {}, 'LOCALES');
public static addSource(patterns: string | Array, baseDir?: string) {
const requireGlob = require('require-glob');
baseDir = baseDir || process.cwd();
requireGlob.sync(patterns, {
cwd: baseDir
});
}
}