How to use utilities - 10 common examples

To help you get started, we’ve selected a few utilities 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 geddy / model / test / unit / create_user.js View on Github external
, 'test no password confirmation': function () {
    var p = utils.mixin({}, _params),
        user;
    p.confirmPassword = 'fdsa';
    var user = User.create(p);
    // Error message should be customized
    assert.ok(typeof user.errors.password != 'undefined');
  }
github Azure / pcs-remote-monitoring-webui / src / components / shared / forms / formGroup.js View on Github external
render() {
    // Attach the formGroupId to allow automatic focus when a label is clicked
    const childrenWithProps = React.Children.map(this.props.children,
      child => {
        if (React.isValidElement(child) && isFunc(child.type)) {
          return React.cloneElement(child, { formGroupId: this.formGroupId });
        }
        return child;
      }
    );
    return <div>{childrenWithProps}</div>;
  }
}
github geddy / model / lib / adapters / sql / mysql.js View on Github external
this.name = 'mysql';
  this.type = 'sql';
  this.config = _baseConfig;
  this.client = null;
  this.generator = generator.getGeneratorForAdapter(this);

  utils.mixin(this.config, opts);

  this.init.apply(this, arguments);
};

Adapter.prototype = new BaseAdapter();
Adapter.prototype.constructor = Adapter;

utils.mixin(Adapter.prototype, new (function () {

  this.COLUMN_NAME_DELIMITER = '`';

  // Pseudo-private -- utility and for testing only
  this._getClient = function () {
    return mysql.createConnection(this.config);
  };

  this._handleDisconnect = function (callback) {
      var self = this;
      setTimeout(function() {
        self.client = self._getClient();
        self.connect(callback);
      }, Math.pow(3, reconnectAttempts) * 1000);
      reconnectAttempts++;
  };
github geddy / model / lib / adapters / level / index.js View on Github external
var Adapter = function (options) {
  var opts = options || {}
    , config;

  this.name = 'level';
  this.config = this.loadConfig(_baseConfig, opts);
  this.client = null;
  this.db = null;

  this.init.apply(this, arguments);
};

Adapter.prototype = new BaseAdapter();
Adapter.prototype.constructor = Adapter;

utils.mixin(Adapter.prototype, new (function () {

  this._initLevel = function (config) {
    var db
      , sublevel;

    db = level(config.db, {keyEncoding: 'utf8', valueEncoding: 'json'});

    if (config.sublevel) {
      // Load sublevel, and set db
      sublevel = utils.file.requireLocal('level-sublevel');
      db = sublevel(db);
      db = db.sublevel(config.sublevel);
    }

    this.db = db;
  };
github mde / ejs / gen / build / build.js View on Github external
window.geddy = {}

// require model
geddy.model = require('model');

// mix utilities into geddy
var utilities = require('utilities');
utilities.mixin(geddy, utilities);

// require socket.io-client
geddy.io = require('socket.io-client');
geddy.socket = geddy.io.connect('/');

geddy.io.listenForModelEvents = function (model) {
  var events = [
    'save'
  , 'update'
  , 'remove'
  ];

  for (var e in events) {
    (function (event) {
      geddy.socket.on(model.modelName + ':' + event, function (data) {
        var instance;
github mde / ejs / lib / geddy.js View on Github external
var geddy = global.geddy || {}
  , EventEmitter = require('events').EventEmitter
  , utils = require('utilities')
  , pkg = require('../package');

// Set the One True Geddy Global
global.geddy = geddy;

utils.enhance(geddy, new EventEmitter());

utils.mixin(geddy, {version: pkg.version});
utils.mixin(geddy, utils);
utils.mixin(geddy, new (function () {
  var _started = false
    , _master
    , _worker

  this.start = function (options) {
    var opts = options || {}
      , App
      , app
      , worker
      , config = require('./config')
      , c = config.readConfig(opts);

    geddy.config = c;

    App = require('./app').App;
github geddy / model / lib / adapters / sql / base.js View on Github external
query._sqlMetadata = this._getSqlMetadata(query);
        sql = this._createSelectStatementWithConditions(query);

        processor = new EventedQueryProcessor(query, cb);
        setTimeout(function () {
          processor.process(self[fetch](sql));
        }, 0);
        return processor;
      }
    }

  };
})());

// Mix in basic conversion methods
utils.mixin(Adapter.prototype, converter);

// Mix in query transformer methods
utils.mixin(Adapter.prototype, sqlTransformer);

EventedQueryProcessor = function (query, callback) {
  this._source = null;
  this._allItems = [];
  this._allItemsHash = {};
  this._lastMainModel = null;
  this._rowEventName = query.model.getAdapter().name == 'mysql' ?
      'result' : 'row';
  this.models = {};
  this.setQuery(query);
  this.callback = callback;
};
github mde / ejs / lib / server.js View on Github external
var _readConfig = function () {
        var opts = this.opts
          , dir = process.cwd()
          , baseConfig = require(dir + '/config/environment.js')
          , envConfig;

        this.config.environment = opts.environment || this.config.environment;
        envConfig = require(dir + '/config/' + this.config.environment + '.js');

        // Start with a blank slate, mix everything in
        utils.mixin(this.config, baseConfig);
        utils.mixin(this.config, envConfig);
        utils.mixin(this.config, opts);
        if (this.config.workers &lt; 2) {
          this.config.rotateWorkers = false;
        }
      }
  /**
github geddy / model / test / unit / create_user.js View on Github external
, 'setting default values': function () {
    var p = utils.mixin({}, _params),
        user;
    delete p.firstName;
    user = User.create(p);
    assert.equal('Zerp', user.firstName);
  }
github mde / ejs / lib / geddy.js View on Github external
app.init(_worker.config, function () {
        geddy.emit('initialized');
        utils.mixin(geddy, app);
        _worker.startServer(function () {
          geddy.emit('started');
        });
      });
    });

utilities

A classic collection of JavaScript utilities

Apache-2.0
Latest version published 2 years ago

Package Health Score

30 / 100
Full package analysis

Popular utilities functions