How to use the underscore.defaults function in underscore

To help you get started, we’ve selected a few underscore 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 translate / pootle / pootle / static / js / reports / app.js View on Github external
init(opts) {
    _.defaults(this, opts);

    /* Compile templates */
    const showSummary = (!PTL.reports.freeUserReport &&
                         (PTL.reports.ownReport || PTL.reports.adminReport));
    this.tmpl = {
      results: _.template($('#language_user_activity').html()),
      summary: showSummary ? _.template($('#summary').html()) : '',
      paid_tasks: showSummary ? _.template($('#paid-tasks').html()) : '',
    };

    $(window).resize(() => {
      if (PTL.reports.data !== undefined &&
          PTL.reports.data.daily !== undefined &&
          PTL.reports.data.daily.nonempty) {
        PTL.reports.drawChart();
      }
github Reportr / dashboard / lib / models / user.js View on Github external
userSchema.methods.setModel = function(data, options) {
    var that = this;
    var deferred = Q.defer();

    // Options
    options = _.defaults(options || {}, {
        'update': true
    });
    
    // Check data
    if (!data || !data.eventName) {
        deferred.reject(new Error("Need 'eventName' to define a model"));
    } else {
        data.eventNamespace = data.eventNamespace || 'main';
        data.modelId = this.id.toString()+"/"+data.eventNamespace+"/"+data.eventName;
        data.name = data.name || data.eventNamespace+"/"+data.eventName;
        data.userId = this.id.toString();
        data.icon = data.icon || "";
        data.description = data.description || "";

        var next = function(err, model) {
            if (err) return deferred.reject(err);
github walmartlabs / lumbar / lib / plugins / mixin.js View on Github external
var value = module[field],
      mixinValue = library.attributes[field];

  if (!value) {
    return;
  }

  if (value === mixinValue) {
    // Clone any direct copy entries from a mixin
    if (_.isArray(value)) {
      module[field] = context.libraries.mapFiles(value, library, mixinConfig);
    } else {
      module[field] = _.clone(value);
    }
  } else if (!_.isArray(value)) {
    _.defaults(value, mixinValue);
  } else if (mixinValue) {
    mixinValue = context.libraries.mapFiles(mixinValue, library, mixinConfig);

    var mixinFirstLocal = firstLocal(mixinValue),
        moduleFirstLocal = firstLocal(value);

    if (mixinFirstLocal) {
      value.unshift.apply(value, mixinValue.slice(0, mixinFirstLocal));
    }
    if (mixinFirstLocal < mixinValue.length) {
      var locals = mixinValue.slice(mixinFirstLocal);
      locals.unshift(mixinFirstLocal + moduleFirstLocal, 0);
      value.splice.apply(value, locals);
    }
  }
}
github promises-aplus / promises-tests / lib / programmaticRunner.js View on Github external
module.exports = function (adapter, mochaOpts, cb) {
    if (typeof mochaOpts === "function") {
        cb = mochaOpts;
        mochaOpts = {};
    }
    if (typeof cb !== "function") {
        cb = function () { };
    }

    normalizeAdapter(adapter);
    mochaOpts = _.defaults(mochaOpts, { timeout: 200, slow: Infinity });

    fs.readdir(testsDir, function (err, testFileNames) {
        if (err) {
            cb(err);
            return;
        }

        var mocha = new Mocha(mochaOpts);
        testFileNames.forEach(function (testFileName) {
            if (path.extname(testFileName) === ".js") {
                var testFilePath = path.resolve(testsDir, testFileName);
                mocha.addFile(testFilePath);
            }
        });

        global.adapter = adapter;
github tomgco / node-dropbox-sdk / lib / dropbox-client.js View on Github external
var get = function(url, options, cb) {
		options.headers = options.headers || {};
		_.defaults(options.headers, defaultHeader);
		var req = request.defaults(options);
		req.get(url, function(err, res, resBody) {
			cb(res.statusCode, resBody);
		});
	};
github oesmith / ralio / lib / ralio.js View on Github external
Ralio.prototype.headers =  function (headers) {
  return _.defaults(headers || {}, {
    "X-RallyIntegrationLibrary": "Node.js Native",
    "X-RallyIntegrationName": package.name,
    "X-RallyIntegrationVendor": package.repository.url,
    "X-RallyIntegrationVersion": package.version,
    "User-Agent": "Node.JS (request:" + package.dependencies.request + ")"
  });
}
github oroinc / platform / src / Oro / Bundle / EmailBundle / Resources / public / js / app / views / email-variable-view.js View on Github external
initialize: function(options) {
            this.options = _.defaults(options || {}, this.options);

            this.template = _.template($(this.options.templateSelector).html());
            this.systemTemplate = _.template(
                $(this._getSectionSelector(this.options.sectionTemplateSelector, this.sections.system)).html()
            );
            this.entityTemplate = _.template(
                $(this._getSectionSelector(this.options.sectionTemplateSelector, this.sections.entity)).html()
            );

            this.listenTo(this.model, 'change:entity', this._renderEntityVariables);

            this.fields = $(this.options.fieldsSelectors.join(','));
            this.fields.on('blur', _.bind(this._updateElementsMetaData, this));

            this.lastElement = $(this.options.fieldsSelectors[this.options.defaultFieldIndex]);
        },
github oroinc / platform / src / Oro / Bundle / UIBundle / Resources / public / js / app / views / scrolling-overlay-view.js View on Github external
initialize: function(options) {
            _.extend(this, _.defaults(
                _.pick(options, ['buttonScrollClassName', '$scrollingContent', 'scrollStep']), this));

            this.$scrollingContent = $(this.$scrollingContent);

            if (!this.$scrollingContent.length) {
                throw new Error('Required option `$scrollingContent` is missing in `ScrollingOverlayView`');
            }

            ScrollingOverlayView.__super__.initialize.call(this, options);
        },
github HULKs / HULKsCodeRelease / tools / ofa / src / ofa / client / map.js View on Github external
Map.prototype.init = function (config) {

    //super class
    DebugDisplay.prototype.init.call(this, config);
    //event handlers
    this.onUpdate = _.bind(this.onUpdate, this);

    //config
    this.config = _.defaults(config || {}, Map.defaultConfig);

    //graphics
    this.selector = new FieldSelector(this.wrapper)
    this.selector.onChange(_.bind(this.updateFieldSize, this));

    this.canvas = document.createElement('canvas');
    this.canvas.width = this.config.width;
    var aspectRatio = (2 * field.border + field.width) / (2 * field.border + field.length);
    this.canvas.height = aspectRatio * this.config.width;
    this.wrapper.appendChild(this.canvas);

    this.ctx = this.canvas.getContext('2d');

    this.buf = new Array(this.config.bufferSize);

    this.subscribe(config.keys, config.mappingFct);
github praekeltfoundation / jspot / lib / api.js View on Github external
jspot.extract = function(opts) {
    _.defaults(opts.headers, {});

    var extracts = opts.source.reduce(function(extracts, filename) {
        var src = fs.readFileSync(path.resolve(filename));

        return extracts.concat(extract(src.toString(), {
            keyword: opts.keyword,
            filename: filename
        }));
    }, []);

    var pots = jspot.pot(extracts, {
        headers: opts.headers
    });

    _(pots).each(function(pot, domain) {
        fs.writeFileSync(