How to use the applyToDefaults function from hoek

Find comprehensive JavaScript hoek.applyToDefaults code examples handpicked from public code repositorys.

97
98
99
100
101
102
103
104
105
106

exports.methods.push({
    name: 'github.styleGuide',
    method: function () {

        const options = Hoek.applyToDefaults(internals.requestOptions, {
            headers: { accept: 'application/vnd.github.3.html' }
        });

        return Utils.download('https://api.github.com/repos/hapijs/assets/contents/Style.md', options);
fork icon276
star icon0
watch icon2

+ 3 other calls in file

114
115
116
117
118
119
120
121
122
```javascript

var defaults = {host: "localhost", port: 8000};
var options = {port: 8080};

var config = Hoek.applyToDefaults(defaults, options); // results in {host: "localhost", port: 8080};
```

### unique(array, key)
fork icon170
star icon1
watch icon33

+ 3 other calls in file

159
160
161
162
163
164
165
166
167
            else {
                credentials.refreshToken = 'refresh_token';
                credentials.expiresIn = 3600;
            }

            return h.authenticated({ credentials: Hoek.applyToDefaults(credentials, result) });
        }
    };
};
fork icon210
star icon0
watch icon2

168
169
170
171
172
173
174
175
176
        name: 'example'
    };

var options = { server: { port: 8080 } };

var config = Hoek.applyToDefaults(defaults, options); // results in { server: { port: 8080 }, name: 'example' }
```

### unique(array, key)
fork icon170
star icon0
watch icon14

+ 11 other calls in file

166
167
168
169
170
171
172
173
174
175
```javascript

var defaults = { host: "localhost", port: 8000 };
var options = { host: null, port: 8080 };

var config = Hoek.applyToDefaults(defaults, options, true); // results in { host: null, port: 8080 }
```

### applyToDefaultsWithShallow(defaults, options, keys)
keys is an array of key names to shallow copy
fork icon170
star icon0
watch icon6

+ 5 other calls in file

30
31
32
33
34
35
36
37
38

static async sendEmail(options, template, context) {

    const content = await this.renderTemplate(template, context);

    options = Hoek.applyToDefaults(options, {
        from: Config.get('/system/fromAddress'),
        markdown: content
    });
fork icon161
star icon0
watch icon2

52
53
54
55
56
57
58
59
60
61
}, xoptions);

options.handler = handler;

if (Utils.canCarry(method)) {
    options.payload = options.payload ? Hoek.applyToDefaults({ allow: operation.consumes || api.consumes }, options.payload) : { allow: operation.consumes || api.consumes };
}

if (Array.isArray(handler)) {
    options.pre = [];
fork icon75
star icon0
watch icon1

16
17
18
19
20
21
22
23
24
  Hoek.assert(
    this.constructor === Connection,
    'Redis cache client must be instantiated using new'
  )

  this.settings = Hoek.applyToDefaults(internals.defaults, options)
  this.client = null
  return this
}
fork icon62
star icon49
watch icon28

38
39
40
41
42
43
44
45
46
```javascript
const Hoek = require('hoek');

const default = {url : "www.github.com", port : "8000", debug : true};

const config = Hoek.applyToDefaults(default, {port : "3000", admin : true});

// In this case, config would be { url: 'www.github.com', port: '3000', debug: true, admin: true }
```
fork icon4
star icon32
watch icon5

16
17
18
19
20
21
22
23
24
25
                }
        }
};

exports.register = function (server, options, next) {
        internals = Hoek.applyToDefaults(internals, options);
        server.dependency(['bedwetter', 'dogwater'], internals.after);

        next();
};
fork icon4
star icon23
watch icon3

175
176
177
178
179
180
181
182
183
184
                else {
                    credentials.refreshToken = 'refresh_token';
                    credentials.expiresIn = 3600;
                }

                return reply.continue({ credentials: Hoek.applyToDefaults(credentials, result) });
            });
        }
    };
};
fork icon210
star icon0
watch icon2

11
12
13
14
15
16
17
18
19
20
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;
fork icon33
star icon0
watch icon3

195
196
197
198
199
200
201
202
203
204

        if (err) {
            throw err;
        }

        self.settings = Utils.applyToDefaults(internals.defaults, options);
    });
}

Nsquishy.prototype.squish = function (next) {
fork icon0
star icon2
watch icon2

52
53
54
55
56
57
58
59
60
61

Joi.assert(handles, schemas.DataRetrievalRouter_register_handles);
Joi.assert(retriever, schemas.DataRetrievalRouter_register_retriever);
options = options || {};
Joi.assert(options, schemas.DataRetrievalRouter_register_options);
options = Hoek.applyToDefaults(defaults.DataRetrievalRouter_register_options, options);

if (handles instanceof Array) {
    handles.forEach((source) => this._register(source, retriever, options));
}
fork icon4
star icon0
watch icon1

90
91
92
93
94
95
96
97
98
99
  sneeze.join({ isbase: sneeze_opts.isbase })
}


exports.register = function(server, pluginOptions) {
  internals.defaults = Hoek.applyToDefaults(internals.defaults, pluginOptions)

  server.decorate('handler', 'wo', internals.handler)

  server.decorate('toolkit', 'wo', function(options) {
fork icon2
star icon11
watch icon4

22
23
24
25
26
27
28
29
30
31
const ddos = function (params) {

    if (!params)
        params = {};

    params = Hoek.applyToDefaults(defaultParams, params);

    if ((params.burst !== undefined) && (params.limit === undefined)) {
        params.limit = params.burst * 4;
    }
fork icon1
star icon0
watch icon0

96
97
98
99
100
101
102
103
104
105

utils.getCurrentSettings = function (settings, serverSettings) {
  if (serverSettings == null) {
    return settings
  } else {
    var currentSettings = Hoek.applyToDefaults(settings, serverSettings)
    currentSettings.tags = _.union(utils.getTags(settings), utils.getTags(serverSettings))
    return currentSettings
  }
}
fork icon38
star icon0
watch icon0

98
99
100
101
102
103
104
105
106
107

utils.getCurrentSettings = function (settings, serverSettings) {
  if (serverSettings == null) {
    return settings
  } else {
    const currentSettings = Hoek.applyToDefaults(settings, serverSettings)
    currentSettings.tags = _.union(utils.getTags(settings), utils.getTags(serverSettings))
    return currentSettings
  }
}
fork icon38
star icon0
watch icon51

274
275
276
277
278
279
280
281
282
283

    this._type = extension.name;

    if (extension.language) {
        this._settings = this._settings || { language: {} };
        this._settings.language = Hoek.applyToDefaults(this._settings.language, {
            [extension.name]: extension.language
        });
    }
}
fork icon0
star icon1
watch icon0

41
42
43
44
45
46
47
48
49
50
51
52
53


internals.stringify = function (object, options) {


    internals.seen = [];
    internals.path = [];
    internals.settings = Hoek.applyToDefaults(internals.defaults, options || {});
    return internals.travel(object, '');
};



fork icon0
star icon0
watch icon1

+ 83 other calls in file