How to use the hoek.inherits 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 arangodb / arangodb / js / node / node_modules / joi / lib / number.js View on Github external
// Declare internals

var internals = {};


internals.Number = function () {

    Any.call(this);
    this._type = 'number';
    this._invalids.add(Infinity);
    this._invalids.add(-Infinity);
};

Hoek.inherits(internals.Number, Any);

internals.compare = function (type, compare) {

    return function (limit) {

        var isRef = Ref.isRef(limit);
        var isNumber = typeof limit === 'number' && !isNaN(limit);

        Hoek.assert(isNumber || isRef, 'limit must be a number or reference');

        return this._test(type, limit, function (value, state, options) {

            var compareTo;
            if (isRef) {
                compareTo = limit(state.parent, options);
github arangodb / arangodb / js / node / node_modules / joi / lib / object.js View on Github external
// Declare internals

var internals = {};


internals.Object = function () {

    Any.call(this);
    this._type = 'object';
    this._inner.children = null;
    this._inner.renames = [];
    this._inner.dependencies = [];
    this._inner.patterns = [];
};

Hoek.inherits(internals.Object, Any);


internals.Object.prototype._base = function (value, state, options) {

    var item, key, localState, result;
    var target = value;
    var errors = [];
    var finish = function () {

        return {
            value: target,
            errors: errors.length ? errors : null
        };
    };

    if (typeof value === 'string' &&
github hapijs / hapi / lib / connection.js View on Github external
this.info = {
        created: now,
        started: 0,
        host: this.settings.host || Os.hostname() || 'localhost',
        port: this.settings.port,
        protocol: this.type === 'tcp' ? (this.settings.tls ? 'https' : 'http') : this.type,
        id: Os.hostname() + ':' + process.pid + ':' + now.toString(36)
    };

    this.info.uri = (this.settings.uri || (this.info.protocol + ':' + (this.type === 'tcp' ? '//' + this.info.host + (this.info.port ? ':' + this.info.port : '') : this.info.port)));

    this.on('route', Cors.options);
};

Hoek.inherits(internals.Connection, Podium);


internals.Connection._events = [
    { name: 'route', spread: true },
    { name: 'request-internal', spread: true, tags: true },
    { name: 'request', spread: true, tags: true },
    { name: 'request-error', spread: true },
    'response',
    'tail'
];



internals.Connection.prototype._init = function () {

    // Setup listener
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / good-squeeze / lib / squeeze.js View on Github external
options = options || {};
    options.objectMode = true;

    if (!(this instanceof internals.Squeeze)) {
        return new internals.Squeeze(events, options);
    }

    Stream.Transform.call(this, options);
    this._good = {
        subscription: internals.Squeeze.subscription(events)
    };
};


Hoek.inherits(internals.Squeeze, Stream.Transform);


internals.Squeeze.prototype._transform = function (data, enc, next) {

    if (internals.Squeeze.filter(this._good.subscription, data)) {
        this.push(data);
    }
    next(null);
};


// events hash of events and tags
internals.Squeeze.subscription = function (events) {

    // Because we are attaching unrestricted keys from the user to result
    // we want to null the prototype to prevent issues with "hasOwnPropery" or
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / hapi / lib / response.js View on Github external
return (this.request.method !== 'head' && this.statusCode !== 304 && this.statusCode !== 204);
};


internals.Response.Payload = internals.Payload = function (payload, options) {

    Stream.Readable.call(this);
    this._data = payload;
    this._prefix = null;
    this._suffix = null;
    this._sizeOffset = 0;
    this._encoding = options.encoding;
};

Hoek.inherits(internals.Payload, Stream.Readable);


internals.Payload.prototype._read = function (/* size */) {

    if (this._prefix) {
        this.push(this._prefix, this._encoding);
    }

    if (this._data) {
        this.push(this._data, this._encoding);
    }

    if (this._suffix) {
        this.push(this._suffix, this._encoding);
    }
github hapijs / hapi / lib / response / payload.js View on Github external
// Declare internals

var internals = {};


exports = module.exports = internals.Payload = function (payload, options) {

    Stream.Readable.call(this);
    this._data = (payload === undefined ? null : payload);
    this._prefix = null;
    this._suffix = null;
    this._sizeOffset = 0;
    this._encoding = options.encoding;
};

Hoek.inherits(internals.Payload, Stream.Readable);


internals.Payload.prototype._read = function (/* size */) {

    if (this._prefix) {
        this.push(this._prefix, this._encoding);
    }

    if (this._data) {
        this.push(this._data, this._encoding);
    }

    if (this._suffix) {
        this.push(this._suffix, this._encoding);
    }
github hapijs / hapi / test / request.js View on Github external
var handler = function (request, reply) {

                var TestStream = function () {

                    Stream.Readable.call(this);
                };

                Hoek.inherits(TestStream, Stream.Readable);

                TestStream.prototype._read = function (size) {

                    if (this.isDone) {
                        return;
                    }
                    this.isDone = true;

                    this.push('success');
                    this.emit('data', 'success');
                };

                var stream = new TestStream();
                return reply(stream);
            };
github arangodb / arangodb / js / node / node_modules / joi / lib / array.js View on Github external
--arr.length;
};


internals.Array = function () {

    Any.call(this);
    this._type = 'array';
    this._inner.items = [];
    this._inner.inclusions = [];
    this._inner.exclusions = [];
    this._inner.requireds = [];
    this._flags.sparse = false;
};

Hoek.inherits(internals.Array, Any);


internals.Array.prototype._base = function (value, state, options) {

    var result = {
        value: value
    };

    if (typeof value === 'string' &&
        options.convert) {

        try {
            var converted = JSON.parse(value);
            if (Array.isArray(converted)) {
                result.value = converted;
            }
github arangodb / arangodb / js / node / node_modules / joi / lib / date.js View on Github external
var isoString = internals.isoDate.toString();

    return function (date) {

        return date && (date.toString() === isoString);
    };
})();

internals.Date = function () {

    Any.call(this);
    this._type = 'date';
};

Hoek.inherits(internals.Date, Any);


internals.Date.prototype._base = function (value, state, options) {

    var result = {
        value: (options.convert && internals.toDate(value, this._flags.format)) || value
    };

    if (result.value instanceof Date && !isNaN(result.value.getTime())) {
        result.errors = null;
    }
    else {
        result.errors = Errors.create(internals.isIsoDate(this._flags.format) ? 'date.isoDate' : 'date.base', null, state, options);
    }

    return result;
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / good-squeeze / lib / safe-json.js View on Github external
if (!(this instanceof internals.SafeJson)) {
        return new internals.SafeJson(options, transformOptions);
    }

    options = options || {};
    options.objectMode = true;
    transformOptions = transformOptions || {};

    Stream.Transform.call(this, options);

    var config = Hoek.applyToDefaults(internals.defaults, transformOptions);
    this._transformOptions = config;
};


Hoek.inherits(internals.SafeJson, Stream.Transform);


internals.SafeJson.prototype._transform = function (data, enc, next) {

    this.push(Stringify(data) + this._transformOptions.separator);
    next(null);
};