How to use clone - 10 common examples

To help you get started, we’ve selected a few clone 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 bminixhofer / permon / permon / frontend / browser / src / monitors.js View on Github external
export function setupMonitor(stat) {
  const {
    tag, maximum, minimum, color, history,
  } = stat;
  const tickPositions = [];
  const labelPositions = [];

  const contributorAxisOptions = clone(defaultContributorAxisOptions);
  contributorAxisOptions.axisLabel.interval = function interval(y) {
    return labelPositions.includes(y);
  };
  contributorAxisOptions.axisTick.interval = function interval(y) {
    return tickPositions.includes(y);
  };

  const chartContainer = document.getElementById(tag);
  const heading = document.createElement('h2');
  heading.textContent = stat.name;

  const chartElement = document.createElement('div');
  chartElement.classList.add('chart');

  // add title and chart to the container div
  // the container div has already been added via the index.html template
github bigchaindb / js-bigchaindb-driver / src / transaction.js View on Github external
static serializeTransactionIntoCanonicalString(transaction) {
        // BigchainDB signs fulfillments by serializing transactions into a
        // "canonical" format where
        const tx = clone(transaction)
        // TODO: set fulfillments to null
        // Sort the keys
        return stableStringify(tx, (a, b) => (a.key > b.key ? 1 : -1))
    }
github kristianmandrup / red-elements / packages / red-runtime / src / util / index.ts View on Github external
cloneMessage(msg: IHttpMessage): string {
    // Temporary fix for #97
    // TODO: remove this http-node-specific fix somehow
    var req = msg.req;
    var res = msg.res;
    delete msg.req;
    delete msg.res;
    var m = clone(msg);
    if (req) {
      m.req = req;
      msg.req = req;
    }
    if (res) {
      m.res = res;
      msg.res = res;
    }
    return m;
  }
github h2non / toxy / test / poisons / bandwidth.js View on Github external
test('bandwidth', function (done) {
    const opts = { bps: 1, threshold: 5 }
    const req = new http.IncomingMessage()
    const res = clone.clonePrototype(new http.OutgoingMessage())

    const buf = []
    var lastWrite = Date.now()

    Object.getPrototypeOf(res).write = function (buffer, encoding, next) {
      expect(buffer).to.have.length(opts.bps)
      expect(Date.now() - lastWrite).to.be.least(opts.threshold - 1)
      lastWrite = Date.now()
      buf.push(buffer)
      next()
    }

    Object.getPrototypeOf(res).end = function () {
      expect(buf).to.have.length(11)
      expect(buf.join('')).to.be.equal('Hello World')
      console.log('')
github h2non / toxy / test / poisons / slow-read.js View on Github external
test('read', function (done) {
    const threshold = 5
    const spy = sinon.spy()
    const init = Date.now()

    const res = new http.OutgoingMessage()
    const req = clone.clonePrototype(new http.IncomingMessage())
    req.method = 'POST'

    Object.getPrototypeOf(req).push = function (data) {
      spy(data)
      if (data === null) assert()
    }

    slowRead({ chunk: 1, threshold: threshold })(req, res, spy)

    req.push(new Buffer('Hello World'))
    req.push(null)

    function assert () {
      expect(Date.now() - init).to.be.at.least(threshold * 10)
      expect(spy.args).to.have.length(13)
      expect(spy.args.shift()[0]).to.be.undefined
github h2non / toxy / test / poisons / throttle.js View on Github external
test('small chunks', function (done) {
    const opts = { chunk: 1, threshold: 5 }
    const buf = []

    const req = new http.IncomingMessage()
    const res = clone.clonePrototype(new http.OutgoingMessage())

    var lastWrite = Date.now()
    Object.getPrototypeOf(res).write = function (buffer, encoding, next) {
      expect(buffer).to.have.length(opts.chunk)
      expect(Date.now() - lastWrite).to.be.at.least(opts.threshold - 1)
      lastWrite = Date.now()
      buf.push(buffer)
      next()
    }

    Object.getPrototypeOf(res).end = function () {
      expect(buf).to.have.length(11)
      expect(buf.join('')).to.be.equal('Hello World')
      done()
    }
github h2non / toxy / test / poisons / slow-close.js View on Github external
test('close', function (done) {
    const delay = 50
    const expected = { body: 'Hello', code: 200, headers: { server: 'rocky' } }
    const spy = sinon.spy()
    const init = Date.now()

    const res = clone.clonePrototype({})
    Object.getPrototypeOf(res).writeHead = spy
    Object.getPrototypeOf(res).end = function (body) {
      spy(body)
      end()
    }

    slowClose({ delay: delay })(null, res, spy)

    res.writeHead(200, { 'content-length': 100, server: 'rocky' })
    res.end(expected.body)

    function end (err) {
      expect(Date.now() - init).to.be.at.least(delay - 1)
      expect(spy.calledThrice).to.be.true
      expect(spy.args[1][0]).to.be.equal(expected.code)
      expect(spy.args[1][1]).to.be.deep.equal(expected.headers)
github h2non / toxy / test / poisons / slow-read.js View on Github external
test('premature close', function (done) {
    const threshold = 10
    const spy = sinon.spy()
    const init = Date.now()

    const res = new http.OutgoingMessage()
    const req = clone.clonePrototype(new http.IncomingMessage())
    req.method = 'POST'

    Object.getPrototypeOf(req).push = function (data) {
      spy(data)
      if (data === null) assert()
    }

    slowRead({ chunk: 1, threshold: threshold })(req, res, spy)

    req.emit('close')

    req.push(new Buffer('Hello World'))
    req.push(null)

    function assert () {
      expect(Date.now() - init).to.be.within(0, 5)
github oaeproject / Hilary / packages / oae-tenants / lib / internal / dao.networks.js View on Github external
_ensureCache(err => {
    if (err) {
      return callback(err);
    }

    return callback(null, clone(_cacheTenantAliasesByTenantNetworkId));
  });
};
github uptick / react-object-table / src / object-table.jsx View on Github external
getSelectedFirstVisibleRow(reverse) {
    var allRows = Clone(this.props.objects || []);
    if (reverse)
      allRows = allRows.reverse();

    for (var rowIndex = 0; rowIndex < allRows.length; rowIndex++) {
      var row = allRows[rowIndex];
      if (typeof this.state.selectedRows[row.id] != 'undefined')
        return row.id;
    }
    return null;
  }
  getSelectedFirstVisibleColumn(reverse) {

clone

deep cloning of objects and arrays

MIT
Latest version published 7 years ago

Package Health Score

70 / 100
Full package analysis