Skip to content

Commit

Permalink
Doug says we need a space after function
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Sep 2, 2014
1 parent 4220d2d commit 561dbe9
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 120 deletions.
6 changes: 3 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function(grunt) {
module.exports = function (grunt) {
// Define to control testing order
var tests = [
'test/is.js',
Expand All @@ -7,15 +7,15 @@ module.exports = function(grunt) {
'test/delta/compose.js'
];

grunt.registerTask('coverage', function() {
grunt.registerTask('coverage', function () {
grunt.util.spawn({
cmd: './node_modules/.bin/istanbul',
args: ['cover', './node_modules/.bin/_mocha'].concat(tests).concat(['--dir', '.coverage']),
opts: { stdio: 'inherit' }
}, this.async());
});

grunt.registerTask('test', function() {
grunt.registerTask('test', function () {
grunt.util.spawn({
cmd: './node_modules/.bin/mocha',
args: tests,
Expand Down
16 changes: 8 additions & 8 deletions lib/delta.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var is = require('./is');
var op = require('./op');


var Delta = function(ops) {
var Delta = function (ops) {
this.ops = [];
if (is.array(ops)) {
ops.forEach((function(nextOp) {
ops.forEach((function (nextOp) {
if (is.string(nextOp)) {
this.insert(nextOp);
} else if (is.number(nextOp)) {
Expand All @@ -25,7 +25,7 @@ var Delta = function(ops) {
};


Delta.prototype.insert = function(text, formats) {
Delta.prototype.insert = function (text, formats) {
var newOp = {};
if (is.object(text) && !is.object(formats)) {
formats = text;
Expand All @@ -40,19 +40,19 @@ Delta.prototype.insert = function(text, formats) {
return this._push(newOp);
};

Delta.prototype.delete = function(length) {
Delta.prototype.delete = function (length) {
if (length === 0) return this;
return this._push({ delete: Math.abs(length) });
};

Delta.prototype.retain = function(length, formats) {
Delta.prototype.retain = function (length, formats) {
if (length === 0) return this;
var newOp = { retain: length };
if (is.object(formats)) newOp.formats = formats;
return this._push(newOp);
};

Delta.prototype._push = function(newOp) {
Delta.prototype._push = function (newOp) {
var lastOp = this.ops[this.ops.length - 1];
if (is.object(lastOp)) {
if (is.number(newOp.delete) && is.number(lastOp.delete)) {
Expand All @@ -75,7 +75,7 @@ Delta.prototype._push = function(newOp) {
};


Delta.prototype.compose = function(other) {
Delta.prototype.compose = function (other) {
var thisIter = op.iterator(this.ops);
var otherIter = op.iterator(other.ops);
this.ops = [];
Expand Down Expand Up @@ -110,7 +110,7 @@ Delta.prototype.compose = function(other) {
return this;
};

Delta.prototype.transform = function(other, priority) {
Delta.prototype.transform = function (other, priority) {

};

Expand Down
10 changes: 5 additions & 5 deletions lib/is.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
equal: function(a, b) {
equal: function (a, b) {
if (a === b) return true;
if (a == null && b == null) return true;
if (a == null || b == null) return false;
Expand All @@ -11,22 +11,22 @@ module.exports = {
return true;
},

array: function(value) {
array: function (value) {
return Array.isArray(value);
},

number: function(value) {
number: function (value) {
if (typeof value === 'number') return true;
if (typeof value === 'object' && Object.prototype.toString.call(value) === '[object Number]') return true;
return false;
},

object: function(value) {
object: function (value) {
if (!value) return false;
return (typeof value === 'function' || typeof value === 'object');
},

string: function(value) {
string: function (value) {
if (typeof value === 'string') return true;
if (typeof value === 'object' && Object.prototype.toString.call(value) === '[object String]') return true;
return false;
Expand Down
14 changes: 7 additions & 7 deletions lib/op.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var is = require('./is');


var lib = {
composeFormats: function(a, b) {
composeFormats: function (a, b) {
if (!is.object(a)) return b;
if (!is.object(b)) return a;
var newFormat = {};
Expand All @@ -20,11 +20,11 @@ var lib = {
return newFormat;
},

iterator: function(ops) {
iterator: function (ops) {
return new Iterator(ops);
},

length: function(op) {
length: function (op) {
if (is.number(op.delete)) {
return op.delete;
} else if (is.number(op.retain)) {
Expand All @@ -42,11 +42,11 @@ function Iterator(ops) {
this.offset = 0;
};

Iterator.prototype.hasNext = function() {
Iterator.prototype.hasNext = function () {
return this.peekLength() < Infinity;
};

Iterator.prototype.next = function(length) {
Iterator.prototype.next = function (length) {
if (!length) length = Infinity;
var nextOp = this.ops[this.index];
if (nextOp) {
Expand Down Expand Up @@ -78,7 +78,7 @@ Iterator.prototype.next = function(length) {
}
};

Iterator.prototype.peekLength = function() {
Iterator.prototype.peekLength = function () {
if (this.ops[this.index]) {
// Should never return 0 if our index is being managed correctly
return lib.length(this.ops[this.index]) - this.offset;
Expand All @@ -87,7 +87,7 @@ Iterator.prototype.peekLength = function() {
}
};

Iterator.prototype.peekType = function() {
Iterator.prototype.peekType = function () {
if (this.ops[this.index]) {
if (is.number(this.ops[this.index].delete)) {
return 'delete';
Expand Down
54 changes: 27 additions & 27 deletions test/delta/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var Delta = require('../../lib/delta');
var expect = require('chai').expect;


describe('constructor', function() {
describe('constructor', function () {
var ops = [
{ insert: 'abc' },
{ retain: 1, formats: { color: 'red' } },
Expand All @@ -11,14 +11,14 @@ describe('constructor', function() {
{ retain: 6 }
];

it('empty', function() {
it('empty', function () {
var delta = new Delta();
expect(delta).to.exist;
expect(delta.ops).to.exist;
expect(delta.ops.length).to.equal(0);
});

it('array of ops', function() {
it('array of ops', function () {
var delta = new Delta([
'abc',
{ retain: 1, formats: { color: 'red' } },
Expand All @@ -30,133 +30,133 @@ describe('constructor', function() {
expect(delta.ops).to.deep.equal(ops);
});

it('delta in object form', function() {
it('delta in object form', function () {
var delta = new Delta({ ops: ops });
expect(delta.ops).to.deep.equal(ops);
});

it('delta', function() {
it('delta', function () {
var original = new Delta(ops);
var delta = new Delta(original);
expect(delta.ops).to.deep.equal(original.ops);
expect(delta.ops).to.deep.equal(ops);
});
});

describe('insert', function() {
it('insert(text)', function() {
describe('insert', function () {
it('insert(text)', function () {
var delta = new Delta().insert('test');
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ insert: 'test' });
});

it('insert(embed)', function() {
it('insert(embed)', function () {
var obj = { url: 'http://quilljs.com', alt: 'Quill' };
var delta = new Delta().insert(obj);
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ formats: obj });
});

it('insert(text, attributes)', function() {
it('insert(text, attributes)', function () {
var delta = new Delta().insert('test', { bold: true });
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ insert: 'test', formats: { bold: true } });
});

it('insert(null, attributes)', function() {
it('insert(null, attributes)', function () {
var obj = { url: 'http://quilljs.com', alt: 'Quill' };
var delta = new Delta().insert(null, obj);
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ formats: obj });
});
});

describe('delete', function() {
it('delete(0)', function() {
describe('delete', function () {
it('delete(0)', function () {
var delta = new Delta().delete(0);
expect(delta.ops.length).to.equal(0);
});

it('delete(negative)', function() {
it('delete(negative)', function () {
var delta = new Delta().delete(-1);
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ delete: 1 });
});

it('delete(positive)', function() {
it('delete(positive)', function () {
var delta = new Delta().delete(1);
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ delete: 1 });
});
});

describe('retain', function() {
it('retain(0)', function() {
describe('retain', function () {
it('retain(0)', function () {
var delta = new Delta().retain(0);
expect(delta.ops.length).to.equal(0);
});

it('retain(length)', function() {
it('retain(length)', function () {
var delta = new Delta().retain(2);
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ retain: 2 });
});

it('retain(length, attributes)', function() {
it('retain(length, attributes)', function () {
var delta = new Delta().retain(1, { bold: true });
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ retain: 1, formats: { bold: true } });
});
});

describe('_push', function() {
it('_push(op) into empty', function() {
describe('_push', function () {
it('_push(op) into empty', function () {
var delta = new Delta();
delta._push({ insert: 'test' });
expect(delta.ops.length).to.equal(1);
});

it('_push(op) consecutive delete', function() {
it('_push(op) consecutive delete', function () {
var delta = new Delta().delete(-2);
delta._push({ delete: 3 });
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ delete: 5 });
});

it('_push(op) consecutive text', function() {
it('_push(op) consecutive text', function () {
var delta = new Delta().insert('a');
delta._push({ insert: 'b' });
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ insert: 'ab' });
});

it('_push(op) consecutive texts with matching attributes', function() {
it('_push(op) consecutive texts with matching attributes', function () {
var delta = new Delta().insert('a', { bold: true });
delta._push({ insert: 'b', formats: { bold: true } });
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ insert: 'ab', formats: { bold: true } });
});

it('_push(op) consecutive retains with matching attributes', function() {
it('_push(op) consecutive retains with matching attributes', function () {
var delta = new Delta().retain(1, { bold: true });
delta._push({ retain: 3, formats: { bold : true } });
expect(delta.ops.length).to.equal(1);
expect(delta.ops[0]).to.deep.equal({ retain: 4, formats: { bold: true } });
});

it('_push(op) consecutive texts with mismatched attributes', function() {
it('_push(op) consecutive texts with mismatched attributes', function () {
var delta = new Delta().insert('a', { bold: true });
delta._push({ insert: 'b' });
expect(delta.ops.length).to.equal(2);
});

it('_push(op) consecutive retains with mismatched attributes', function() {
it('_push(op) consecutive retains with mismatched attributes', function () {
var delta = new Delta().retain(1, { bold: true });
delta._push({ retain: 3 });
expect(delta.ops.length).to.equal(2);
});

it('_push(op) consecutive embeds with matching attributes', function() {
it('_push(op) consecutive embeds with matching attributes', function () {
var delta = new Delta().insert({ url: 'http://quilljs.com' });
delta._push({ formats: { url: 'http://quilljs.com' } });
expect(delta.ops.length).to.equal(2);
Expand Down
Loading

0 comments on commit 561dbe9

Please sign in to comment.