How to use the lazy.js function in lazy

To help you get started, we’ve selected a few lazy 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 vinz243 / cassette / src / server / models / Model.js View on Github external
let opts = Lazy(query).pick([
        'limit', 'offset', 'sort', 'direction'
      ]).value();

      if (!opts.limit || opts.limit > 500 || opts.limit < 1) {
        opts.limit = 500;
      }

      let sort = {};
      sort[opts.sort || 'name'] = opts.direction ?
        (opts.direction == 'asc' ? 1 : -1) : 1;

      let res = (await db.cfind(q).sort(sort).limit(opts.limit)
        .skip(opts.skip || 0).exec()).map(d => new model(d));

      res.query = Lazy(q).merge(opts).value();
      return res;
    }
    // for (let i in this.fields.filter(t => t.type == 'oneToOne')) {
github bnjjj / my-infra / app / services / ovh-request / ovh-request.service.ts View on Github external
.map(timestamp => {
        let reqBody = null;
        let headers = {};

        if (typeof(config.body) === 'object' && Object.keys(config.body).length > 0) {
          if (config.method === 'PUT' || config.method === 'POST') {
            // Escape unicode
            reqBody = JSON.stringify(config.body).replace(/[\u0080-\uFFFF]/g, function(m) {
              return '\\u' + ('0000' + m.charCodeAt(0).toString(16)).slice(-4);
            });
            headers['Content-Length'] = reqBody.length;
          } else {
            url += ('?' + querystring.stringify(_(config.body).filter((elm) => elm != null).value()));
            config.body = {};
          }
        }

        headers = Object.assign({}, {
          'X-Ovh-Consumer': this.opts.consumerKey,
          'X-Ovh-Signature': this.getHashedSignature(config.method || 'GET', this.urlRoot + url, Object.keys(config.body).length ? config.body : null, timestamp),
          'X-Ovh-Timestamp': timestamp,
          'X-Ovh-Application': this.opts.appKey
        }, headers);

        if (config.method === 'POST' || config.method === 'PUT') {
          headers['Content-Type'] = 'application/json';
        }

        return { headers: new Headers(headers) };
github orbitdb / orbit-db / src / list / OrbitList.js View on Github external
    let indices = Lazy(item.next).map((next) => Lazy(this._items).map((f) => f.hash).indexOf(next)) // Find the item's parent's indices
    const index = indices.length > 0 ? Math.max(indices.max() + 1, 0) : 0; // find the largest index (latest parent)
github rockstat / chwriter / src / clickhouse / sync.ts View on Github external
}
      const schemaCols = Object.assign(
        {},
        customCols
      );
      // don't handle abstract tables
      if (_options.abstract) continue;
      // creating table
      if (!exists) {
        const query = showCreateTable(table, schemaCols, _options);
        this.log.info(`Creating table ${table}: ${query}`);
        await this.client.execute(query);
      }
      // calculating difference and apply changes
      else {
        const currTableKeys = Lazy(currTable).keys();
        const appendCols = Lazy(schemaCols)
          .keys()
          .without(currTableKeys.toArray())
          .toArray();
        if (appendCols.length > 0) {
          this.log.info({
            new_cols: appendCols.join(', ')
          }, `Altering table ${table}`);
          const query = showAlterTable(
            table,
            Lazy(schemaCols)
              .pick(appendCols)
              .toObject(),
            _options
          );
          await this.client.execute(query);
github orbitdb / ipfs-log / lib / log.js View on Github external
_insert(node) {
    let indices = Lazy(node.next).map((next) => Lazy(this._items).map((f) => f.hash).indexOf(next)) // Find the item's parent's indices
    const index = indices.toArray().length > 0 ? Math.max(indices.max() + 1, 0) : 0; // find the largest index (latest parent)
    this._items.splice(index, 0, node);
    return node;
  }
github rockstat / chwriter / src / clickhouse / sync.ts View on Github external
await this.client.execute(query);
      }
      // calculating difference and apply changes
      else {
        const currTableKeys = Lazy(currTable).keys();
        const appendCols = Lazy(schemaCols)
          .keys()
          .without(currTableKeys.toArray())
          .toArray();
        if (appendCols.length > 0) {
          this.log.info({
            new_cols: appendCols.join(', ')
          }, `Altering table ${table}`);
          const query = showAlterTable(
            table,
            Lazy(schemaCols)
              .pick(appendCols)
              .toObject(),
            _options
          );
          await this.client.execute(query);
        }
      }
    }
    // rediscover db structure
    await this.discover();
    this.log.info('Schema sync done');
  }
github slap-editor / slap / lib / ui / HelpDialog.js View on Github external
var paths = {};
  traverse(self.slap.options).forEach(function (binding) {
    if (this.path.indexOf('bindings') !== -1) {
      var keyNumber = Number(this.key);
      if (Array.isArray(binding)) binding = binding.join(", ");
      else if (Array.isArray(this.parent) || !this.isLeaf || !this.key || keyNumber === keyNumber) return;

      var path = this.path.slice(0, -1).join('.');
      if (!(path in paths)) paths[path] = [];
      paths[path].push(this.key + ": " + binding);
    }
  });
  self.helpContent
    .readOnly(true)
    .text("Keybindings:\n" + _(paths).pairs()
      .sortBy(function (pair) { return (pair[0].match(/\./g) || []).length; })
      .map(function (pair) {
        return "\n[" + pair[0] + "]\n" + pair[1].join("\n");
      })
      .join("\n")
    , false);

  self.okButton = new Button({
    parent: self,
    content: "Okay",
    bottom: 1,
    right: 1
  });
}
HelpDialog.prototype.__proto__ = BaseDialog.prototype;
github bnjjj / my-infra / app / pages / login / login.service.ts View on Github external
(resp) => {
          let tmpDiv = document.createElement('div');
          tmpDiv.innerHTML = resp.text();

          let inputs = tmpDiv.getElementsByTagName('input');
          let inputSms = _(inputs).find((elt) => elt.id === 'codeSMS');

          if (inputSms == null || inputSms.length === 0) {
            localStorage.removeItem('connected');
            localStorage.setItem('connected', 'true');

            return true;
          } else {
            return false;
          }
        }
      );
github orbitdb / orbit-db / src / list / OrbitList.js View on Github external
        const isReferenced = (list, item) => Lazy(list).reverse().find((f) => f === item) !== undefined;
        let result = [];
github slap-editor / slap / lib / slap.js View on Github external
self.remove(self.form);
      self.form = null;
      self.editor.focus();
      self.editor.bottom = 0;
    }
    if (prompts) {
      self.editor.bottom += prompts.length;
      self.form = new blessed.Form({
        parent: self,
        height: prompts.length,
        left: 0,
        right: 0,
        bottom: 0
      });

      var labelWidth = _(prompts).pluck('length').max() + 3;
      var label = new blessed.Box({
        parent: self.form,
        tags: true,
        content: prompts.map(function (prompt) {
          return markup(
            (' ' + prompt + ':' + _.repeat(' ', labelWidth).join('')).slice(0, labelWidth),
          self.options.style.prompt || self.options.style.main);
        }).join('\n'),
        top: 0,
        left: 0,
        width: labelWidth,
        bottom: 0
      });

      function done (submit) {
        self.prompt(false).done();

lazy

Lazy lists for node

MIT
Latest version published 12 years ago

Package Health Score

67 / 100
Full package analysis