How to use the hoek.applyToDefaults function in hoek

To help you get started, we’ve selected a few hoek examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bigcommerce / stencil-cli / lib / stencil-init.js View on Github external
internals.parseAnswers = function(JspmAssembler, ThemeConfig, dotStencilFile, dotStencilFilePath, answers) {

    // Check for custom layout configurations
    // If already set, do nothing otherwise write the empty configurations
    if (!dotStencilFile || dotStencilFile && !dotStencilFile.customLayouts) {
        answers.customLayouts = {
            'brand': {},
            'category': {},
            'page': {},
            'product': {},
        };
    }

    var defaults = dotStencilFile ? hoek.applyToDefaults(dotStencilFile, answers) : answers;

    Fs.writeFile(dotStencilFilePath, JSON.stringify(defaults, null, 2), function (err) {
        var ready = 'You are now ready to go! To start developing, run $ ' + 'stencil start'.cyan,
            bundleTask;

        if (err) {
            throw err;
        }

        // bundle dev dependencies
        configuration = ThemeConfig.getInstance(themePath).getConfig();
        if (configuration.jspm) {
            if (!Fs.existsSync(Path.join(themePath, configuration.jspm.jspm_packages_path))) {
                console.log('Error: The path you specified for your "jspm_packages" folder does not exist.'.red);
                return console.log(
                    'Please check your '.red +
github hemerajs / hemera / packages / hemera-web / lib / index.js View on Github external
// for tracing
      if (xRequestId) {
        pattern.requestParentId$ = xRequestId
      }

      // include json payload to pattern
      if (Typeis(req, contentTypeJson)) {
        const body = await Micro.json(req)

        if (body) {
          pattern = Hoek.applyToDefaults(pattern, body)
        }
      } else if (Typeis(req, contentForm)) { // include form data to pattern
        const body = await Micro.text(req)
        const post = Qs.parse(body)
        pattern = Hoek.applyToDefaults(pattern, post)
      } else if (Typeis(req, contentBinaryStream)) { // handle as raw binary data
        pattern.binaryData = await Micro.buffer(req) // limit 1MB
      } else if (Typeis(req, contentText)) { // handle as raw text data
        pattern.textData = await Micro.text(req)
      }

      return this._hemera.act(pattern).catch((err) => {
        res.statusCode = err.statusCode || 500
        return {
          error: _.omit(err, this._options.errors.propBlacklist)
        }
      })
    })
  }
github harrybarnard / hapi-couchdb / lib / index.js View on Github external
internals.init = function (options) {
        var error = Joi.validate(options, internals.schema).error;
        Hoek.assert(!error, 'Invalid CouchDb options', error && error.annotate());
        var config = Hoek.applyToDefaults(internals.defaults, options || {});

        var Nano;

        if (config.request) { // If custom request configuration is set
            // Add connection url to request config
            config.request.url = config.url;
            Nano = require('nano')(config.request);
        } else { // Otherwise use simple configuration
            Nano = require('nano')(config.url);
        }

        var db = Nano.use(config.db);

        /**
         * Update a document
         * Will create the document if it doesn't exist
github mac- / ratify / lib / RequestValidator.js View on Github external
var RequestValidator = function(plugin, options) {
	options = options || {};
	var configuredErrorReporters = Hoek.applyToDefaults(errorReporters, options.errorReporters || {});
	var routeSchemaManager = new RouteSchemaManager({ pluginName: options.pluginName, log: options.log }),
		log = options.log || function(){},

		onRequest = function(request, reply) {
			// hand routes for this server to schema manager so it can compile the schemas for each route
			// this method will not attempt to compile them more than once, so this is safe to call on every request
			try {
				var connectionsWithTable = request.server.table();

				connectionsWithTable.forEach(function(cwt){
					routeSchemaManager.initializeRoutes(cwt.info.uri, cwt.table);
				});
			}
			catch (error){
				log('error', 'Unable to compile and validate schemas', error);
				return reply(error);
github hapijs / inert / test / file.js View on Github external
const provisionServer = async (options, etagsCacheMaxSize) => {

            const defaults = { compression: { minBytes: 1 }, plugins: { inert: { etagsCacheMaxSize } } };
            const server = new Hapi.Server(Hoek.applyToDefaults(defaults, options || {}));
            await server.register(Inert);
            return server;
        };
github nakardo / good-slack / lib / index.js View on Github external
constructor(config) {

        config = config || {};

        Hoek.assert(typeof config.url === 'string', 'url must be a string');

        super({ objectMode: true });
        this._config = Hoek.applyToDefaults(internals.defaults, config);
    }
github boillodmanuel / rest-from-zero-to-hero / server / data / collection.js View on Github external
Collection.prototype.toHal = function(rep, done) {
    var uri = new URI(rep.self);
    var prev = Math.max(0, this.offset - this.limit);
    var next = Math.min(this.total, this.offset + this.limit);

    var query = uri.search(true);

    if (this.offset > 0) {
        rep.link('prev', uri.search(hoek.applyToDefaults(query, { offset: prev, limit: this.limit })).toString());
    }
    if (this.offset + this.size < this.total) {
        rep.link('next', uri.search(hoek.applyToDefaults(query, { offset: next, limit: this.limit })).toString());
    }
    done();
};
github krakenjs / levee / lib / breaker.js View on Github external
function Breaker(impl, options) {
    Events.EventEmitter.call(this);

    Assert.equal(typeof impl, 'object', 'The command implementation must be an object.');
    Assert.equal(typeof impl.execute, 'function', 'The command implementation must have a method named `execute`.');

    this.settings = Hoek.applyToDefaults(Defaults.Breaker, options || {});
    this.fallback = undefined;

    this._impl = impl;
    this._state = Breaker.State.CLOSE;
    this._numFailures = 0;
    this._pendingClose = false;
    this._resetTimer = undefined;

    this.on('open', this._startTimer);
}
github genediazjr / disinfect / lib / index.js View on Github external
server.ext('onPostAuth', (request, reply) => {

            if (request.route.settings.plugins.disinfect === false) {
                return reply.continue;
            }

            if (request.payload || Object.keys(request.params).length || Object.keys(request.query).length) {

                request.route.settings.plugins._disinfect = Hoek.applyToDefaults(serverSettings, request.route.settings.plugins.disinfect || {});

                request.query = internals.disinfect(request.query, request.route.settings.plugins._disinfect, 'disinfectQuery', 'querySanitizer');
                request.params = internals.disinfect(request.params, request.route.settings.plugins._disinfect, 'disinfectParams', 'paramsSanitizer');
                request.payload = internals.disinfect(request.payload, request.route.settings.plugins._disinfect, 'disinfectPayload', 'payloadSanitizer');
            }

            return reply.continue;
        });
    },
github sibartlett / hapi-io / lib / index.js View on Github external
exports.register = function(server, options, next) {

  options = Hoek.applyToDefaults(internals.defaults, options);

  var s = options.connectionLabel ?
          server.select(options.connectionLabel) : server;

  if (!s) {
    return next('hapi-io - no server');
  }

  if (!s.connections.length) {
    return next('hapi-io - no connection');
  }

  if (s.connections.length !== 1) {
    return next('hapi-io - multiple connections');
  }