Skip to content

Add function glyphDiff for emoji and higher UTF8 character support #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/diff/glyph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Diff from './base';

export const glyphDiff = new Diff();
glyphDiff.tokenize = function(value) {
return [...value];
};
glyphDiff.join = function(value) {
return value.join('');
};
glyphDiff.removeEmpty = function(value) {
return value.filter((str) => str !== '');
};
export function diffGlyph(oldStr, newStr, options) {
return glyphDiff.diff(oldStr, newStr, options);
}
23 changes: 23 additions & 0 deletions test/diff/glyph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {diffGlyph} from '../../lib/diff/glyph';
import {convertChangesToXML} from '../../lib/convert/xml';

import {expect} from 'chai';

describe('diff/glyph', function() {
describe('#diffGlyph', function() {
describe('extended unicode characters', function() {
it('are treated as single characters when inserted', function() {
const diffResult = diffGlyph('New 🐴.', 'New 🐴🐴MoreData.', {removeEmpty: true});
expect(convertChangesToXML(diffResult)).to.equal('New 🐴<ins>🐴MoreData</ins>.');
});
it('are treated as single characters when deleted', function() {
const diffResult = diffGlyph('New 🐴🐴.', 'New 🐴.', {removeEmpty: true});
expect(convertChangesToXML(diffResult)).to.equal('New 🐴<del>🐴</del>.');
});
it('are treated as single characters when equal', function() {
const diffResult = diffGlyph('New 🐴.', 'New 🐴.', {removeEmpty: true});
expect(convertChangesToXML(diffResult)).to.equal('New 🐴.');
});
});
});
});