How to use the lodash.cloneDeep function in lodash

To help you get started, we’ve selected a few lodash 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 verdaccio / verdaccio / test / unit / modules / plugin / auth.spec.ts View on Github external
test('should skip empty array', () => {
        const config: Config = new AppConfig(_.cloneDeep(authPluginPassThrougConf));
        const auth: IAuth = new Auth(config);

        expect(auth).toBeDefined();

        const callback = jest.fn();
        const value = [ ];

        // @ts-ignore
        auth.authenticate(null, value, callback);
        expect(callback.mock.calls).toHaveLength(1);
        expect(callback.mock.calls[0][0]).toBeDefined();
        expect(callback.mock.calls[0][1]).toBeUndefined();
      });
github trufflesuite / ganache-core / lib / provider.js View on Github external
let intermediary = function(err, result) {
    // clone result so that we can mutate the response without worrying about
    // that messing up assumptions the calling logic might have about us
    // mutating things
    result = _.cloneDeep(result);
    let response;
    if (Array.isArray(result)) {
      response = [];
      for (let i = 0; i < result.length; i++) {
        response.push(self.reportErrorInResponse(payload[i], err, result[i]));
      }
    } else {
      response = self.reportErrorInResponse(payload, err, result);
    }

    if (self.options.verbose) {
      self.options.logger.log(
        " <   " +
          JSON.stringify(response, null, 2)
            .split("\n")
            .join("\n <   ")
github fairlearn / fairlearn / fairlearn / widget / js / src / fairlearnDashboard.tsx View on Github external
const promise = new Promise((resolve, reject) => {
            const request = _.cloneDeep(this.model.get('request'));
            const requestIndex = this.requestIndex;
            this.requestIndex++;
            // handle timeout (set to 3 minutes)
            const timeout = window.setTimeout(() => {
                if (this.promiseDict[requestIndex]){
                    this.promiseDict[requestIndex].reject(new DOMException('Timeout: took longer than 3 minutes to process', 'TimeoutError'));
                    delete this.promiseDict[requestIndex];
                }
            }, 180000);
            this.promiseDict[requestIndex] = {resolve, reject, timeout};

            request[requestIndex] = data;
            this.model.set('request', request);
            this.touch();

            if(this.refreshTimeout) {
github tarlepp / Taskboard / backend / api / models / Epic.js View on Github external
'use strict';

var _ = require('lodash');
var async = require('async');

/**
 * Epic.js
 *
 * @description :: TODO: You might write a short summary of how this model works and what it represents here.
 * @docs        :: http://sailsjs.org/#!documentation/models
 */
module.exports = _.merge(_.cloneDeep(require('../base/Model')), {
    attributes: {
        // Epic title
        title: {
            type:       'string',
            required:   true,
            minLength:  4
        },
        // Epic description
        description: {
            type:       'text',
            defaultsTo: ''
        },
        // Possible epic deadline date
        deadline: {
            type:       'date'
        },
github thomaschampagne / elevate / plugin / app / src / app / shared / services / activity / activity.service.spec.ts View on Github external
beforeEach((done: Function) => {

		TestBed.configureTestingModule({
			providers: [ActivityService, ActivityDao]
		});

		_TEST_SYNCED_ACTIVITIES_ = _.cloneDeep(TEST_SYNCED_ACTIVITIES);

		// Retrieve injected service
		activityService = TestBed.get(ActivityService);

		done();
	});
github fabric8-ui / fabric8-ui / src / app / profile / spaces / space.service.ts View on Github external
.then(response => {
        // Extract links from JSON API response.
        // and set the nextLink, if server indicates more resources
        // in paginated collection through a 'next' link.
        let links = response.json().links;
        if (links.hasOwnProperty('next')) {
          this.nextLink = links.next;
        } else {
          this.nextLink = null;
        }
        // Extract data from JSON API response, and assert to an array of spaces.
        let newSpaces: Space[] = response.json().data as Space[];
        let newItems = cloneDeep(newSpaces);
        // Update the existing spaces list with new data
        this.updateSpacesList(newItems);
        if (isAll) {
          return this.spaces;
        } else {
          return newSpaces;
        }
      })
      .catch(this.handleError);
github interpretml / interpret-community / visualization / dashboard / src / MLIDashboard / Controls / PerturbationExploration.tsx View on Github external
private fetchData(): void {
        if (this.state.abortController !== undefined) {
            this.state.abortController.abort();
        }
        // skip if there are any errors.
        if (this.state.featureErrors.some(val => val)) {
            return;
        }
        const data = _.cloneDeep(this.props.explanationContext.testDataset.dataset[this.props.datapointIndex]);
        for (var key of Object.keys(this.state.perturbedDictionary)) {
            const index = +key;
            if (this.state.perturbedDictionary[index] !== undefined) {
                data[index] = this.state.perturbedDictionary[index];
            }
        }
        const abortController = new AbortController();
        const promise = this.props.invokeModel([data], abortController.signal);
        this.setState({abortController, errorMessage: undefined}, async () => {
            try {
                const fetchedData = await promise;
                if (abortController.signal.aborted) {
                    return;
                }
                if (Array.isArray(fetchedData[0])) {
                    const predictionVector = fetchedData[0];
github ShiftNrg / shift / test / unit / logic / transaction.js View on Github external
it('should return error when second signature is invalid', function (done) {
			var vs = _.cloneDeep(validSender);
			vs.secondPublicKey = validKeypair.publicKey.toString('hex');
			vs.secondSignature = 1;

			var trsData = _.cloneDeep(validTransactionData);
			trsData.sender = vs;
			trsData.secondKeypair = validKeypair;
			createAndProcess(trsData, validSender, function (trs) {
				trs.signSignature = '7af5f0ee2c4d4c83d6980a46efe31befca41f7aa8cda5f7b4c2850e4942d923af058561a6a3312005ddee566244346bdbccf004bc8e2c84e653f9825c20be008';
				transaction.verify(trs, vs, function (err) {
					expect(err).to.equal('Failed to verify second signature');
					done();
				});
			});
		});
github webiny / webiny-js / webiny-app-cms / src / admin / views / pages / components / editor / PageContent.jsx View on Github external
beforeRemove: () => this.beforeRemoveWidget({ widget }),
            onRemoved: () => this.removeWidget({ widget }),
            moveDown: () => this.swapWidgets(index, index + 1)
        };

        if (widget.origin) {
            const wd = this.cms.getEditorWidget(widget.type, { origin: widget.origin });
            if (!wd) {
                return (
                    
                        Missing widget for type <strong>{widget.type}</strong>
                    
                );
            }
            if (!widget.data) {
                widget.data = _.cloneDeep(wd.data);
            }

            if (!widget.settings) {
                widget.settings = _.cloneDeep(wd.settings);
            }
        }

        return (
             this.onWidgetChange(widget, data)}
            /&gt;
        );
    }
github OpenNMS / opennms-js / src / rest / AxiosHTTP.ts View on Github external
const type = ret.headers.Accept;
    ret.transformResponse = [];
    if (type === 'application/json') {
      ret.responseType = 'json';
    } else if (type === 'text/plain') {
      ret.responseType = 'text';
    } else if (type === 'application/xml') {
      ret.responseType = 'text';
    } else {
      throw new OnmsError('Unhandled "Accept" header: ' + type);
    }

    ret.paramsSerializer = (params) => parseParams(params);

    if (allOptions.parameters) {
      ret.params = cloneDeep(allOptions.parameters);
    }

    if (allOptions.data) {
      ret.data = cloneDeep(allOptions.data);
    }

    return ret;
  }