scto
String Compare To Operations (CRDT Operation model)
This package is similar to jsdiff, but generates CRDT-friendly operations. Useful for compare strings to OP data-transfer model. x30 faster then diff-match-patch and x625 faster for strings compare than jsdiff!
Install
yarn add scto
Example
Text compare:
import { stringDiffToOps, applyOps } from 'scto'
const origin = 'Yet so far hath discretion fought'
const modifyed = 'Yet get far discretion fought!'
const operations = stringDiffToOps(origin, modifyed)
const applyed = applyOps(origin, operations)
console.log(applyed === modifyed)
Array compare:
import { collateDiffToOps, applyOps } from 'scto'
const origin = ['foo', 'bar', 'baz']
const modifyed = ['abc', 'foo', 'baz']
const operations = collateDiffToOps(origin, modifyed)
const applyed = applyOps(origin, operations)
Possible operations:
Replace:
export interface Replace {
type: 'replace'
offset: number
shift: number
data: Collate
}
Drop:
export interface Drop {
type: 'drop'
offset: number
shift: number
}
Insert:
export interface Insert {
type: 'insert'
offset: number
data: Collate
}