How to use the diff-match-patch function in diff-match-patch

To help you get started, we’ve selected a few diff-match-patch 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 imnapo / react-native-cn-richtext-editor / src / CNTextInput.js View on Github external
this.textLength = 0;
    this.upComingStype = null;
    this.androidSelectionJump = 0;

    this.AvoidAndroidIssueWhenPressSpace = 0;
    this.checkKeyPressAndroid = 0;

    this.avoidAndroidIssueWhenPressSpaceText = '';
    this.justToolAdded = false;
    this.state = {
      selectedTag: 'body',
      selection: { start: 0, end: 0 },
      avoidUpdateText: false,
    };

    this.dmp = new DiffMatchPatch();
    this.oldText = '';
    this.reCalculateTextOnUpate = false;
    // You can also use the following properties:
    DiffMatchPatch.DIFF_DELETE = -1;
    DiffMatchPatch.DIFF_INSERT = 1;
    DiffMatchPatch.DIFF_EQUAL = 0;
  }
github freedomexio / rocketx-condenser / src / app / redux / TransactionSaga.js View on Github external
permlink = s;
        }

        // ensure permlink conforms to STEEMIT_MAX_PERMLINK_LENGTH
        if (permlink.length > 255) {
            permlink = permlink.substring(0, 255);
        }
    } else {
        permlink = Math.floor(Date.now() / 1000).toString(36);
    }

    return permlink;
}

import diff_match_patch from 'diff-match-patch';
const dmp = new diff_match_patch();

export function createPatch(text1, text2) {
    if (!text1 && text1 === '') return undefined;
    const patches = dmp.patch_make(text1, text2);
    const patch = dmp.patch_toText(patches);
    return patch;
}

function* error_custom_json({ operation: { id, required_posting_auths } }) {
    if (id === 'follow') {
        const follower = required_posting_auths[0];
        yield put(
            globalActions.update({
                key: ['follow', 'getFollowingAsync', follower, 'loading'],
                updater: () => null,
            })
github busyorg / busy / src / client / vendor / steemitHelpers.js View on Github external
import base58 from 'bs58';
import getSlug from 'speakingurl';
import secureRandom from 'secure-random';
import diff_match_patch from 'diff-match-patch';
import steemAPI from '../steemAPI';
import formatter from '../helpers/steemitFormatter';
import _ from 'lodash';
import {
  HF21_TIME,
  DEFAULT_CURATION_REWARD_PERCENT,
  HF21_CURATION_REWARD_PERCENT,
} from '../helpers/constants';

const dmp = new diff_match_patch();
/**
 * This function is extracted from steemit.com source code and does the same tasks with some slight-
 * adjustments to meet our needs. Refer to the main one in case of future problems:
 * https://github.com/steemit/steemit.com/blob/edac65e307bffc23f763ed91cebcb4499223b356/app/redux/TransactionSaga.js#L340
 *
 */
export const createCommentPermlink = (parentAuthor, parentPermlink) => {
  let permlink;

  // comments: re-parentauthor-parentpermlink-time
  const timeStr = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '');
  const newParentPermlink = parentPermlink.replace(/(-\d{8}t\d{9}z)/g, '');
  permlink = `re-${parentAuthor}-${newParentPermlink}-${timeStr}`;

  if (permlink.length > 255) {
    // STEEMIT_MAX_PERMLINK_LENGTH
github WebMemex / webmemex-extension / src / page-storage / sameness.js View on Github external
function stringSimilarity(text1, text2) {
    const dmp = new DiffMatchPatch()
    dmp.Diff_Timeout = 0.1
    const diff = dmp.diff_main(text1, text2)
    dmp.diff_cleanupSemantic(diff)
    const distance = dmp.diff_levenshtein(diff)
    const maxDistance = Math.max(text1.length, text2.length)
    const similarity = 1 - distance / maxDistance
    return similarity
}
github localnerve / react-pwa-reference / src / application / client / sw / node_modules / sw / utils / customHelpers.js View on Github external
function nDiff (oldstr, newstr, threshold) {
  const dmp = new Dmp();
  const levenshteinMax = Math.max(oldstr.length, newstr.length);
  const diffs = dmp.diff_main(oldstr, newstr);
  const levenshtein = dmp.diff_levenshtein(diffs);

  return ((levenshtein / levenshteinMax) * 100.0) > threshold;
}
github otakustay / react-diff-view / src / tokenize / markEdits.js View on Github external
const diffText = (x, y) => {
    const dmp = new DiffMatchPatch();
    const diffs = dmp.diff_main(x, y);
    dmp.diff_cleanupSemantic(diffs);

    if (diffs.length <= 1) {
        return [[], []];
    }

    return groupDiffs(diffs);
};
github flashtag / development / app / Admin / resources / assets / js / components / posts / revisions / show.vue View on Github external
diff: function () {
                if (! this.revision) {
                    return '';
                }
                var differ = new DiffMatchPatch();
                var diffs = differ.diff_main(
                        this.revision.old_value || '',
                        this.revision.new_value || ''
                );
                differ.diff_cleanupSemantic(diffs);
                var diff = he.decode(differ.diff_prettyHtml(diffs));

                return this.replaceAll(diff, ['<br>', '¶'], '');
            }
github securingsincity / react-ace / src / diff.js View on Github external
diff() {
    const dmp = new DiffMatchPatch();
    const lhString = this.state.value[0];
    const rhString = this.state.value[1];

    if (lhString.length === 0 && rhString.length === 0) {
      return [];
    }

    const diff = dmp.diff_main(lhString, rhString);
    dmp.diff_cleanupSemantic(diff);

    const diffedLines = this.generateDiffedLines(diff);
    const codeEditorSettings = this.setCodeMarkers(diffedLines);
    return codeEditorSettings;
  }

diff-match-patch

npm package for https://github.com/google/diff-match-patch

Apache-2.0
Latest version published 4 years ago

Package Health Score

71 / 100
Full package analysis