How to use deep-equal - 10 common examples

To help you get started, we’ve selected a few deep-equal 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 fortunejs / fortune-json-api / lib / helpers.js View on Github external
`The filter "${filterType}" is not valid.`)
    }
  }

  // Attach include option.
  if (reservedKeys.include in query) {
    request.include = (Array.isArray(query[reservedKeys.include]) ?
      query[reservedKeys.include] :
      query[reservedKeys.include].split(','))
      .map(i => i.split('.').map(x => inflect(x)).slice(0, includeLimit))

    // Manually expand nested includes.
    for (const path of request.include)
      for (let i = path.length - 1; i > 0; i--) {
        const j = path.slice(0, i)
        if (!request.include.some(deepEqual.bind(null, j)))
          request.include.push(j)
      }
  }

  // Attach sort option.
  if (reservedKeys.sort in query)
    request.options.sort = (Array.isArray(query.sort) ?
      query.sort : query.sort.split(','))
      .reduce((sort, field) => {
        if (field.charAt(0) === '-') sort[inflect(field.slice(1))] = false
        else sort[inflect(field)] = true
        return sort
      }, {})

  // Attach offset option.
  if (pageOffset in query)
github fortunejs / fortune / lib / serializer / serializers / json_api / helpers.js View on Github external
value = castString.get(fields[field][keys.type])(value, options)
      request.options.match[field] = value
    }
  }

  // Attach include option.
  if (reservedKeys.include in query) {
    request.include = (Array.isArray(query[reservedKeys.include]) ?
      query[reservedKeys.include] : [ query[reservedKeys.include] ])
      .map(i => i.split('.').slice(0, includeLimit))

    // Manually expand nested includes.
    for (let path of request.include) {
      for (let i = path.length - 1; i > 0; i--) {
        const j = path.slice(0, i)
        if (!request.include.some(deepEqual.bind(null, j)))
          request.include.push(j)
      }
    }
  }

  // Attach sort option.
  if (reservedKeys.sort in query) {
    let sort = query.sort
    if (!Array.isArray(sort)) sort = [ sort ]

    request.options.sort = sort.reduce((sort, field) => {
      const firstChar = field.charAt(0)

      if (firstChar === '-') sort[field.slice(1)] = false
      else sort[field] = true
github pubkey / rxdb / dist / es / rx-query.js View on Github external
if (missedChangeEvents === null) {
      // changeEventBuffer is of bounds -> we must re-execute over the database
      mustReExec = true;
    } else {
      rxQuery._latestChangeEvent = rxQuery.collection._changeEventBuffer.counter;

      var runChangeEvents = rxQuery.collection._changeEventBuffer.reduceByLastOfDoc(missedChangeEvents);

      var changeResult = rxQuery._queryChangeDetector.runChangeDetection(runChangeEvents);

      if (!Array.isArray(changeResult) && changeResult) {
        // could not calculate the new results, execute must be done
        mustReExec = true;
      }

      if (Array.isArray(changeResult) && !deepEqual(changeResult, rxQuery._resultsData)) {
        // we got the new results, we do not have to re-execute, mustReExec stays false
        ret = true; // true because results changed

        rxQuery._setResultData(changeResult);
      }
    }
  } // oh no we have to re-execute the whole query over the database


  if (mustReExec) {
    // counter can change while _execOverDatabase() is running so we save it here
    var latestAfter = rxQuery.collection._changeEventBuffer.counter;
    return rxQuery._execOverDatabase().then(function (newResultData) {
      rxQuery._latestChangeEvent = latestAfter;

      if (!deepEqual(newResultData, rxQuery._resultsData)) {
github Autodesk / machine-collaboration-utility / react / App.js View on Github external
/* global APP_VAR, io */

import React from 'react';
import Dropzone from 'react-dropzone';
import request from 'superagent';
import _ from 'lodash';
import * as DeepEqual from 'deep-equal';
import Header from './modules/Header';

const equal = DeepEqual.default;

export default class App extends React.Component {
  constructor(props) {
    super(props);
    try {
      this.state = APP_VAR;
    } catch (ex) {
      this.state = props.params;
    }

    this.state.appColor = 210;
    this.state.bots = this.appendConductorPlayers(this.state.bots);
    this.state.dropzoneActive = false;

    this.openDropzone = this.openDropzone.bind(this);
    this.restart = this.restart.bind(this);
github unfoldingWord / translationCore / src / js / actions / SelectionsActions.js View on Github external
export const sameContext = (contextId1, contextId2) => {
  if (!!contextId1 && !!contextId2) {
    return isEqual(contextId1.reference, contextId2.reference)
      && (contextId1.groupId === contextId2.groupId)
      && (contextId1.occurrence === contextId2.occurrence);
  }
  return false;
};
github codecks-io / react-reform / src / index.jsx View on Github external
handleValidationResults(fieldName, results) {
    const {validationResults} = this.state;
    if (!deepEqual(validationResults[fieldName], results)) {
      validationResults[fieldName] = results;
      this.setState(validationResults);
    }
  }
github cozy / cozy-bar / src / lib / config.js View on Github external
async function updateApps (config) {
  const oldApps = config.apps.slice()

  await updateAppsItems(config)

  return !deepEqual(oldApps, config.apps)
}
github unfoldingWord / translationCore / src / js / actions / GroupsDataActions.js View on Github external
export const findGroupDataItem = (contextId, groupData) => {
  let index = -1;
  const isQuoteString = typeof contextId.quote === 'string';

  for (let i = groupData.length - 1; i >= 0; i--) {
    const grpContextId = groupData[i].contextId;

    if (isSameVerse(grpContextId, contextId) &&
      (grpContextId.occurrence === contextId.occurrence) &&
      (isQuoteString ? (grpContextId.quote === contextId.quote) :
        isEqual(grpContextId.quote, contextId.quote))) {
      index = i;
      break;
    }
  }
  return index;
};

deep-equal

node's assert.deepEqual algorithm

MIT
Latest version published 9 months ago

Package Health Score

77 / 100
Full package analysis