changesets
Advanced tools
Comparing version 0.1.3 to 0.2.0
Astropad, IonWriter, Papyrus, Parchment, Vellum, Parabaik, Slate | ||
MoonSlate, IonSlate | ||
MoonSlate, IonSlate, IonPaper, NightWriter, WarpEdit | ||
@@ -5,0 +5,0 @@ http://googledocs.blogspot.de/2010/09/whats-different-about-new-google-docs_23.html |
exports.text = require('./text/index') | ||
exports.Operation = require('./Operation') | ||
exports.Operation = require('./Operation') | ||
if('undefined' != typeof window) window.changesets = exports |
@@ -148,3 +148,4 @@ /*! | ||
return this.map(function(op) { | ||
return op.__proto__.constructor.name+' '+op.pos+':'+op.text | ||
if(op.__proto__) return op.__proto__.constructor.name+' '+op.pos+':'+op.text | ||
return (op instanceof Insert? 'Insert' : 'Delete')+' '+op.pos+':'+op.text | ||
}) | ||
@@ -180,3 +181,3 @@ } | ||
var packed = this.map(function(op) { | ||
var text = base64_encode(op.text) | ||
var text = op.text.replace('%', '%25').replace(':', '%3A') | ||
, pos = (op.pos).toString(36) | ||
@@ -205,3 +206,3 @@ , accessory = (op.accessory).toString(36) | ||
Changeset.unpack = function(packed) { | ||
var matches = packed.match(/(\+|-)\w+?:[^:\+-]+?:\w+?/g) | ||
var matches = packed.match(/(\+|-)\w+?:[^:]+?:\w+?/g) | ||
if(!matches) throw new Error('Cannot unpack invalid serialized changeset string') | ||
@@ -214,5 +215,5 @@ | ||
var pos = parseInt(props[0], 36) | ||
, text = base64_decode(props[1]) | ||
, text = url_decode(props[1]) | ||
, accessory = parseInt(props[2], 36) | ||
if(type == '-') return cs.push(new Delete(props[0], text, props[2])) | ||
if(type == '-') return cs.push(new Delete(pos, text, accessory)) | ||
if(type == '+') return cs.push(new Insert(pos, text, accessory)) | ||
@@ -224,12 +225,5 @@ }) | ||
function base64_encode(text) { | ||
if('undefined' != typeof window) return btoa(text) | ||
if('undefined' != typeof process) return (new Buffer(text)).toString('base64').replace(/=+/, '') | ||
throw new Error('No base64 implementation available!') | ||
} | ||
function base64_decode(base64) { | ||
if('undefined' != typeof window) return atob(base64) | ||
if('undefined' != typeof process) return (new Buffer(base64, 'base64')).toString() | ||
throw new Error('No base64 implementation available!') | ||
function url_decode(text) { | ||
if('undefined' != typeof window) return decodeURIComponent(text) | ||
return require('querystring').unescape(text) | ||
} |
@@ -36,2 +36,4 @@ /*! | ||
exports.Changeset = Changeset | ||
exports.Insert = Insert | ||
exports.Delete = Delete | ||
@@ -38,0 +40,0 @@ /** |
{ | ||
"name": "changesets", | ||
"version": "0.1.3", | ||
"description": "A Changeset library incorporating an operational transformation (OT) algorithm.", | ||
"version": "0.2.0", | ||
"description": "A Changeset library incorporating an operational transformation (OT) algorithm -- for node and the browser!", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
@@ -5,2 +5,4 @@ | ||
[](https://travis-ci.org/marcelklehr/node-changesets) | ||
*changesets* allows you to easily create changesets and apply them on all sites of a distributed system using Operational Transformation. It was built with the following requirements in mind: | ||
@@ -20,9 +22,14 @@ | ||
In your code, `require('changesets')` | ||
## Usage | ||
``` | ||
In node, simply require `'changesets'` | ||
```js | ||
var cs = require('changesets') | ||
``` | ||
In the browser, you need to load the package as a browserified javascript file... | ||
``` | ||
<script type="text/javascript" src="node_modules/changesets/client-side.js"></script> | ||
``` | ||
... in order to be able to use the global `changesets` variable | ||
### Constructing and applying changesets | ||
@@ -130,4 +137,5 @@ Construct a changeset between two texts: | ||
* Simplify anyundo (large numbers of changesets have to be transformed against each other and an undo changseset) | ||
* Browsers can run out of memory when en-/decoding large texts in base64, ie. on paste -- it's not ideal | ||
# License | ||
MIT |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
153342
15
3910
138
8
1