Skip to content

Commit 73ceb4a

Browse files
committed
Added TypeScript definition file, updated README.md and LICENSE.
1 parent 8b77721 commit 73ceb4a

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
The MIT License (MIT)
2+
13
Copyright (c) 2012 The Network Inc. and contributors
24

35
Permission is hereby granted, free of charge, to any person obtaining a copy of

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# htmldiff.js
2-
### HTML Diffing in JavaScript
2+
## HTML Diffing in JavaScript
33

44
[![Build Status](https://travis-ci.org/inkling/htmldiff.js.svg?branch=master)](https://travis-ci.org/inkling/htmldiff.js)
55

@@ -9,20 +9,36 @@
99
This is diffing that understands HTML. Best suited for cases when you
1010
want to show a diff of user-generated HTML (like from a wysiwyg editor).
1111

12-
##Usage
12+
## Usage (JavaScript)
1313
You use it like this:
1414

1515
```javascript
16-
1716
diff = require('htmldiff.js');
1817
console.log(diff('<p>this is some text</p>', '<p>this is some more text</p>'));
1918
```
19+
2020
And you get:
2121

2222
```html
2323
<p>this is some <ins>more </ins>text</p>
2424
```
25-
##Module
25+
26+
## Usage (TypeScript)
27+
28+
```typescript
29+
import diff = require("htmldiff");
30+
console.log(diff("<p>this is some text</p>", "<p>this is some more text</p>"));
31+
```
32+
33+
`diff` is just an arbitry name for the exported default module function, you can use
34+
any other name you like, e. g.:
35+
36+
```typescript
37+
import diffHTML = require("htmldiff");
38+
console.log(diffHTML("<p>this is some text</p>", "<p>this is some more text</p>"));
39+
```
40+
41+
## Module
2642

2743
It should be multi-module aware. ie. it should work as a node.js module
2844
or an AMD (RequireJS) module, or even just as a script tag.

js/htmldiff.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Compares two pieces of HTML content and returns the combined content with differences
3+
* wrapped in <ins> and <del> tags.
4+
*
5+
* @param {string} before The HTML content before the changes.
6+
* @param {string} after The HTML content after the changes.
7+
* @param {string} className (Optional) The class attribute to include in <ins> and <del> tags.
8+
* @param {string} dataPrefix (Optional) The data prefix to use for data attributes. The
9+
* operation index data attribute will be named `data-${dataPrefix-}operation-index`.
10+
*
11+
* @return {string} The combined HTML content with differences wrapped in <ins> and <del> tags.
12+
*/
13+
declare function diff(before: string, after: string, className?: string, dataPrefix?: string): string;
14+
export = diff;

0 commit comments

Comments
 (0)