Git Product home page Git Product logo

herm-js's Introduction

CircleCI Coverage Status js-airbnb-style

Herm document system

NPM

This module allow you to create a "git like" sync system for documents in JS with automatic conflict resolution. With this module, you can edit multiple instances of the same document and merge them in a queue, the module will solve the conflict by itself.

Installation

You can either use it via NPM (for Node or bundled modules)

npm install herm-js-document

or via ES6 modules

<script type="module">
    import HermDoc from '//unpkg.com/herm-js-document';
    let doc = new HermDoc();
</script>

Usage

For plain text :

let doc = new HermDoc();
doc.push(0, "Hello");

let doc2 = doc.duplicate();

doc.push(6, " world");
doc2.push(6, " !");

console.log("doc1 : ", doc.display()); // doc1 :  Hello world
console.log("doc2 : ", doc2.display()); // doc2 :  Hello !

doc = doc.merge(doc2); // first merge 
console.log("doc(first merge) : ", doc.display()); // doc(first merge) :  Hello world !

doc2.push(7, "?");
console.log("doc2(updated) : ", doc2.display()); // doc2(updated) : Hello ?!

doc = doc.merge(doc2); // no duplicates, even with outdated documents

console.log("doc(merged with outdated) : ", doc.display()); // doc(merged with outdated) :  Hello world ?!

doc.deleteRange(0, 6);

console.log("doc(delete)  : ", doc.display()); // doc(merged with outdated) : world ?!

For JSON :

let docJson = new HermJsonDoc();
docJson.key = "123";
console.log(docJson.display()) // {key: "123"}

let docJson2 = docJson.duplicate();
docJson2.key = "5";
docJson2.key2 = "7";

docJson = docJson.merge(docJson2);

console.log(docJson.display()) // {key: "5", key2: "7"}

herm-js's People

Contributors

azukaar avatar streamich avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.