How to use zoo-utils - 10 common examples

To help you get started, we’ve selected a few zoo-utils 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 jszoo / cat-mvc / mvc / mvcApp.js View on Github external
app.emit('init', app, eventArg);
            app._inited = true;
            return true;
        }
        catch (ex) {
            midError.write(res, ex);
        }
    };
};

var appGainer = function(set) {
    return new mvcApp(set);
};

// export
module.exports = utils.extend(appGainer, {
    utils: utils,
    caching: caching,
    //
    area: mvcArea.api,
    model: mvcModelMeta.api,
    controller: mvcController.api,
    //
    modelling: modelling,
    attributes: attributes,
    viewEngines: viewEngines,
    actionResults: actionResults,
    //
    gainApp: function(set) {
        return appGainer(set);
    },
    allApps: function() {
github jszoo / cat-mvc / mvc / attribute / handleErrorAttribute.js View on Github external
var handleErrorAttribute = module.exports = function(set) {
    if (utils.isBoolean(set)) {
        this.enabled = set;
    } else {
        utils.extend(this, set);
    }
};
github jszoo / cat-mvc / mvc / attribute / $sample-model-binder.js View on Github external
var sampleModelBinderAttribute = module.exports = function(set) {
    if (utils.isString(set)) {
        this.paramName = set;
    } else {
        utils.extend(this, set);
    }
    if (!this.paramName) {
        throw new Error('The "paramName" of sampleModelBinderAttribute is required');
    }
};
github jszoo / cat-mvc / mvc / attribute / validateInputAttribute.js View on Github external
var validateInputAttribute = module.exports = function(set) {
    if (utils.isBoolean(set)) {
        this.enableValidation = set;
    } else {
        utils.extend(this, set);
    }
};
github jszoo / cat-mvc / mvc / mvcModelBinderAttribute.js View on Github external
var mvcModelBinderAttribute = module.exports = function(set) {
    if (utils.isString(set)) {
        this.paramName = set;
    } else {
        utils.extend(this, set);
    }
    if (!this.paramName) {
        throw new Error('The "paramName" of mvcModelBinderAttribute is required');
    }
};
github jszoo / cat-mvc / mvc / mvcViewData.js View on Github external
var mvcViewData = module.exports = function(set) {
    utils.extend(this, set);
    if (!this.model) { this.model = {}; }
    this.modelState = new mvcModelState();
    mvcViewData.superclass.constructor.call(this, true);
};
github jszoo / cat-mvc / mvc / middleware / response.js View on Github external
clearCookie: function(name, options) {
        var opts = { expires: new Date(1), path: '/' };
        return this.cookie(name, '', options ? utils.extend(opts, options) : opts);
    },
github jszoo / cat-mvc / mvc / mvcModelBinder.js View on Github external
bindModel: function(controllerContext, bindingContext) {
        var metadata = this.modelMeta.inner();
        var rootNs = bindingContext.paramName;
        var paramsDict = bindingContext.paramsDict;
        var modelState = bindingContext.modelState;
        var modelling = controllerContext.app.modelling;
        var datas = controllerContext.requestDatas('lowerAll');
        //
        var metas = modelling.resolve(metadata);
        if (metas.has()) {
            var value = utils.readObj(datas, rootNs);
            return metas.exe(value, rootNs, function(err) {
                modelState.addModelError(rootNs, err);
            });
        } else {
            var clone = utils.extend(true, {}, metadata);
            var walk = function(obj, parentNs) {
                var t = utils.type(obj);
                var isArr = (t === 'array')
                var isObj = (t === 'object');
                if (!isArr && !isObj) { return; }
                //
                utils.each(obj, function(key, item) {
                    var partNs = isArr ? ('[' + key + ']') : ('.' + key.toLowerCase());
                    var currNs = parentNs + partNs;
                    //
                    var metas = modelling.resolve(item);
                    if (metas.has()) {
                        var fullNs = rootNs + currNs, stateNs = fullNs;
                        var value = utils.readObj(datas, fullNs);
                        //
                        if (!value && !parentNs) {
github jszoo / cat-mvc / mvc / mvcModelApi.js View on Github external
new: function(modelName) {
        var metadata = this.get(modelName);
        if (!metadata) { return; }
        //
        var modelling = this.httpContext.app.modelling;
        var metas = modelling.resolve(metadata);
        if (metas.has()) {
            return metas.parse(null, '', function(err) { });
        }
        //
        var clone = utils.extend(true, {}, metadata);
        var walk = function(obj) {
            var t = utils.type(obj);
            if (t === 'array' || t === 'object') {
                utils.each(obj, function(key, item) {
                    var metas = modelling.resolve(item);
                    if (metas.has()) {
                        obj[key] = metas.parse(null, '', function(err) { });
                    } else {
                        walk(item);
                    }
                });
            }
        };
        walk(clone);
        clone.__metadata = metadata;
        return clone;
github jszoo / cat-mvc / mvc / middleware / response.js View on Github external
cookie: function(name, value, options) {
        options = utils.extend({}, options);
        var signed = options.signed, secret = this.req._zoo.secret;
        //
        if (signed && !secret) {
            throw new Error('cookieParser("secret") required for signed cookies');
        }
        if (utils.isNumber(value)) {
            value = value.toString();
        } else if (utils.isObject(value)) {
            value = 'j:' + JSON.stringify(value);
        }
        if (signed) {
            value = 's:' + sign(value, secret);
        }
        if ('maxAge' in options) {
            options.expires = new Date(Date.now() + options.maxAge);
            options.maxAge /= 1000;

zoo-utils

Utility functions for all zoo members

MIT
Latest version published 10 years ago

Package Health Score

42 / 100
Full package analysis

Popular zoo-utils functions