Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rich-text

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rich-text - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

1

Gruntfile.js

@@ -6,3 +6,2 @@ var fs = require('fs');

var tests = [
'test/is.js',
'test/attributes.js',

@@ -9,0 +8,0 @@ 'test/op.js',

44

lib/delta.js
var diff = require('fast-diff');
var is = require('./is');
var equal = require('deep-equal');
var op = require('./op');

@@ -11,5 +11,5 @@

// Assume we are given a well formed ops
if (is.array(ops)) {
if (Array.isArray(ops)) {
this.ops = ops;
} else if (is.object(ops) && is.array(ops.ops)) {
} else if (ops != null && Array.isArray(ops.ops)) {
this.ops = ops.ops;

@@ -26,3 +26,3 @@ } else {

newOp.insert = text;
if (is.object(attributes) && Object.keys(attributes).length > 0) newOp.attributes = attributes;
if (typeof attributes === 'object' && Object.keys(attributes).length > 0) newOp.attributes = attributes;
return this.push(newOp);

@@ -39,3 +39,3 @@ };

var newOp = { retain: length };
if (is.object(attributes) && Object.keys(attributes).length > 0) newOp.attributes = attributes;
if (typeof attributes === 'object' && Object.keys(attributes).length > 0) newOp.attributes = attributes;
return this.push(newOp);

@@ -48,4 +48,4 @@ };

newOp = op.clone(newOp);
if (is.object(lastOp)) {
if (is.number(newOp['delete']) && is.number(lastOp['delete'])) {
if (typeof lastOp === 'object') {
if (typeof newOp['delete'] === 'number' && typeof lastOp['delete'] === 'number') {
this.ops[index - 1] = { 'delete': lastOp['delete'] + newOp['delete'] };

@@ -56,6 +56,6 @@ return this;

// always prefer to insert first
if (is.number(lastOp['delete']) && newOp.insert != null) {
if (typeof lastOp['delete'] === 'number' && newOp.insert != null) {
index -= 1;
lastOp = this.ops[index - 1];
if (!is.object(lastOp)) {
if (typeof lastOp !== 'object') {
this.ops.unshift(newOp);

@@ -65,10 +65,10 @@ return this;

}
if (is.equal(newOp.attributes, lastOp.attributes)) {
if (is.string(newOp.insert) && is.string(lastOp.insert)) {
if (equal(newOp.attributes, lastOp.attributes)) {
if (typeof newOp.insert === 'string' && typeof lastOp.insert === 'string') {
this.ops[index - 1] = { insert: lastOp.insert + newOp.insert };
if (is.object(newOp.attributes)) this.ops[index - 1].attributes = newOp.attributes
if (typeof newOp.attributes === 'object') this.ops[index - 1].attributes = newOp.attributes
return this;
} else if (is.number(newOp.retain) && is.number(lastOp.retain)) {
} else if (typeof newOp.retain === 'number' && typeof lastOp.retain === 'number') {
this.ops[index - 1] = { retain: lastOp.retain + newOp.retain };
if (is.object(newOp.attributes)) this.ops[index - 1].attributes = newOp.attributes
if (typeof newOp.attributes === 'object') this.ops[index - 1].attributes = newOp.attributes
return this;

@@ -102,3 +102,3 @@ }

start = start || 0;
if (!is.number(end)) end = Infinity;
if (typeof end !== 'number') end = Infinity;
var delta = new Delta();

@@ -134,5 +134,5 @@ var iter = op.iterator(this.ops);

var otherOp = otherIter.next(length);
if (is.number(otherOp.retain)) {
if (typeof otherOp.retain === 'number') {
var newOp = {};
if (is.number(thisOp.retain)) {
if (typeof thisOp.retain === 'number') {
newOp.retain = length;

@@ -143,3 +143,3 @@ } else {

// Preserve null when composing with a retain, otherwise remove it for inserts
var attributes = op.attributes.compose(thisOp.attributes, otherOp.attributes, is.number(thisOp.retain));
var attributes = op.attributes.compose(thisOp.attributes, otherOp.attributes, typeof thisOp.retain === 'number');
if (attributes) newOp.attributes = attributes;

@@ -149,3 +149,3 @@ delta.push(newOp);

// Insert + delete cancels out
} else if (is.number(otherOp['delete']) && is.number(thisOp.retain)) {
} else if (typeof otherOp['delete'] === 'number' && typeof thisOp.retain === 'number') {
delta.push(otherOp);

@@ -175,3 +175,3 @@ }

if (op.insert != null) {
return is.string(op.insert) ? op.insert : NULL_CHARACTER;
return typeof op.insert === 'string' ? op.insert : NULL_CHARACTER;
}

@@ -203,3 +203,3 @@ var prep = (ops === other.ops) ? 'on' : 'with';

var otherOp = otherIter.next(opLength);
if (is.equal(thisOp.insert, otherOp.insert)) {
if (equal(thisOp.insert, otherOp.insert)) {
delta.retain(opLength, op.attributes.diff(thisOp.attributes, otherOp.attributes));

@@ -219,3 +219,3 @@ } else {

priority = !!priority;
if (is.number(other)) {
if (typeof other === 'number') {
return this.transformPosition(other, priority);

@@ -222,0 +222,0 @@ }

@@ -1,8 +0,5 @@

var is = require('./is');
var lib = {
attributes: {
clone: function (attributes, keepNull) {
if (!is.object(attributes)) return {};
if (typeof attributes !== 'object') return {};
return Object.keys(attributes).reduce(function (memo, key) {

@@ -17,4 +14,4 @@ if (attributes[key] !== undefined && (attributes[key] !== null || keepNull)) {

compose: function (a, b, keepNull) {
if (!is.object(a)) a = {};
if (!is.object(b)) b = {};
if (typeof a !== 'object') a = {};
if (typeof b !== 'object') b = {};
var attributes = this.clone(b, keepNull);

@@ -30,4 +27,4 @@ for (var key in a) {

diff: function(a, b) {
if (!is.object(a)) a = {};
if (!is.object(b)) b = {};
if (typeof a !== 'object') a = {};
if (typeof b !== 'object') b = {};
var attributes = Object.keys(a).concat(Object.keys(b)).reduce(function (attributes, key) {

@@ -43,4 +40,4 @@ if (a[key] !== b[key]) {

transform: function (a, b, priority) {
if (!is.object(a)) return b;
if (!is.object(b)) return undefined;
if (typeof a !== 'object') return b;
if (typeof b !== 'object') return undefined;
if (!priority) return b; // b simply overwrites us without priority

@@ -57,3 +54,3 @@ var attributes = Object.keys(b).reduce(function (attributes, key) {

var newOp = this.attributes.clone(op);
if (is.object(newOp.attributes)) {
if (typeof newOp.attributes === 'object') {
newOp.attributes = this.attributes.clone(newOp.attributes, true);

@@ -69,8 +66,8 @@ }

length: function (op) {
if (is.number(op['delete'])) {
if (typeof op['delete'] === 'number') {
return op['delete'];
} else if (is.number(op.retain)) {
} else if (typeof op.retain === 'number') {
return op.retain;
} else {
return is.string(op.insert) ? op.insert.length : 1;
return typeof op.insert === 'string' ? op.insert.length : 1;
}

@@ -104,3 +101,3 @@ }

}
if (is.number(nextOp['delete'])) {
if (typeof nextOp['delete'] === 'number') {
return { 'delete': length };

@@ -112,5 +109,5 @@ } else {

}
if (is.number(nextOp.retain)) {
if (typeof nextOp.retain === 'number') {
retOp.retain = length;
} else if (is.string(nextOp.insert)) {
} else if (typeof nextOp.insert === 'string') {
retOp.insert = nextOp.insert.substr(offset, length);

@@ -139,5 +136,5 @@ } else {

if (this.ops[this.index]) {
if (is.number(this.ops[this.index]['delete'])) {
if (typeof this.ops[this.index]['delete'] === 'number') {
return 'delete';
} else if (is.number(this.ops[this.index].retain)) {
} else if (typeof this.ops[this.index].retain === 'number') {
return 'retain';

@@ -144,0 +141,0 @@ } else {

{
"name": "rich-text",
"version": "2.1.0",
"version": "2.1.1",
"description": "Format for representing rich text documents and changes.",

@@ -9,12 +9,13 @@ "author": "Jason Chen <jhchen7@gmail.com>",

"dependencies": {
"fast-diff": "~1.0.1"
"deep-equal": "^1.0.1",
"fast-diff": "^1.0.1"
},
"devDependencies": {
"chai": "~2.3.0",
"coveralls": "~2.11.2",
"chai": "^3.5.0",
"coveralls": "^2.11.6",
"grunt": "~0.4.5",
"istanbul": "~0.3.14",
"lodash": "~3.9.3",
"mocha": "~2.2.5",
"ot-fuzzer": "~1.0.0"
"istanbul": "~0.4.2",
"lodash": "^4.0.1",
"mocha": "^2.4.4",
"ot-fuzzer": "^1.0.0"
},

@@ -21,0 +22,0 @@ "engines": {

@@ -59,5 +59,6 @@ # Rich Text [![Build Status](https://travis-ci.org/ottypes/rich-text.svg?branch=master)](http://travis-ci.org/ottypes/rich-text) [![Coverage Status](https://img.shields.io/coveralls/ottypes/rich-text.svg)](https://coveralls.io/r/ottypes/rich-text)

- [`transform`](#transform)
- [`transformPosition`](#transformposition)
#### [Documents](#documents-1)
- [`concat`](#concat)
- [`diff`](#diff)

@@ -110,3 +111,3 @@

Retain operations have a Number `retain` key defined representing the number of characters to keep (other libraries might use the name keep or skip). An optional `attributes` key can be defined with an Object to describe formatting changes to the character range. A value of null in the `attributes` Object represents removal of that key.
Retain operations have a Number `retain` key defined representing the number of characters to keep (other libraries might use the name keep or skip). An optional `attributes` key can be defined with an Object to describe formatting changes to the character range. A value of `null` in the `attributes` Object represents removal of that key.

@@ -113,0 +114,0 @@ *Note: It is not necessary to retain the last characters of a document as this is implied.*

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc