Skip to content

Commit 3e2482b

Browse files
authored
Merge pull request #1 from mblink/to-typescript
Convert to modern TypeScript
2 parents 4b48f9d + f462bdf commit 3e2482b

23 files changed

+4739
-2107
lines changed

.eslintrc.cjs

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
module.exports = {
2+
env: {
3+
es6: true,
4+
node: true,
5+
},
6+
extends: [
7+
"eslint:recommended",
8+
],
9+
parser: "@typescript-eslint/parser",
10+
parserOptions: {
11+
project: [
12+
"tsconfig.json",
13+
],
14+
tsconfigRootDir: __dirname,
15+
},
16+
plugins: [
17+
"@typescript-eslint",
18+
],
19+
reportUnusedDisableDirectives: true,
20+
rules: {
21+
"@typescript-eslint/adjacent-overload-signatures": "warn",
22+
"@typescript-eslint/array-type": [
23+
"warn",
24+
{
25+
default: "array-simple",
26+
readonly: "generic"
27+
},
28+
],
29+
"@typescript-eslint/ban-ts-comment": "warn",
30+
"@typescript-eslint/ban-types": [
31+
"warn",
32+
{
33+
"types": {
34+
"{}": false,
35+
},
36+
extendDefaults: true,
37+
}
38+
],
39+
"@typescript-eslint/consistent-type-assertions": "off", // *
40+
"@typescript-eslint/consistent-type-definitions": "off",
41+
"@typescript-eslint/dot-notation": "warn",
42+
"@typescript-eslint/explicit-member-accessibility": [
43+
"warn",
44+
{
45+
accessibility: "no-public",
46+
},
47+
],
48+
"@typescript-eslint/explicit-module-boundary-types": "off",
49+
"@typescript-eslint/indent": "off",
50+
"@typescript-eslint/interface-name-prefix": "off",
51+
"@typescript-eslint/member-delimiter-style": [
52+
"warn",
53+
{
54+
multiline: {
55+
delimiter: "semi",
56+
requireLast: true,
57+
},
58+
singleline: {
59+
delimiter: "comma",
60+
requireLast: false,
61+
},
62+
},
63+
],
64+
"@typescript-eslint/no-empty-function": "warn",
65+
"@typescript-eslint/no-empty-interface": "warn",
66+
"@typescript-eslint/no-explicit-any": "off", // we might want this on
67+
"@typescript-eslint/no-floating-promises": "off",
68+
"@typescript-eslint/no-implied-eval": "warn",
69+
"@typescript-eslint/no-inferrable-types": "off", // *
70+
"@typescript-eslint/no-misused-new": "warn",
71+
"@typescript-eslint/no-misused-promises": "warn",
72+
"@typescript-eslint/no-namespace": "warn",
73+
"@typescript-eslint/no-parameter-properties": "off",
74+
"@typescript-eslint/no-redeclare": "warn",
75+
"@typescript-eslint/no-require-imports": "warn",
76+
"@typescript-eslint/no-shadow": [
77+
"warn",
78+
{
79+
ignoreTypeValueShadow: true,
80+
}
81+
],
82+
"@typescript-eslint/no-this-alias": "warn",
83+
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off", // * was error
84+
"@typescript-eslint/no-unnecessary-type-arguments": "warn",
85+
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
86+
"@typescript-eslint/no-unsafe-assignment": "warn",
87+
"@typescript-eslint/no-unsafe-call": "warn",
88+
"@typescript-eslint/no-unsafe-member-access": "off", // Would be nice to be able to turn on
89+
"@typescript-eslint/no-unsafe-return": "off", // Would be nice to be able to turn on
90+
"@typescript-eslint/no-unused-expressions": [
91+
"warn",
92+
{
93+
"allowShortCircuit": true,
94+
"allowTernary": true,
95+
"allowTaggedTemplates": true
96+
}
97+
],
98+
"@typescript-eslint/no-unused-vars": "warn",
99+
"@typescript-eslint/no-use-before-define": "off",
100+
"@typescript-eslint/no-var-requires": "warn",
101+
"@typescript-eslint/prefer-for-of": "warn",
102+
"@typescript-eslint/prefer-function-type": "warn",
103+
"@typescript-eslint/prefer-namespace-keyword": "warn",
104+
"@typescript-eslint/prefer-readonly": "warn",
105+
"@typescript-eslint/prefer-regexp-exec": "warn",
106+
"@typescript-eslint/restrict-template-expressions": "off",
107+
"@typescript-eslint/restrict-plus-operands": "warn",
108+
"@typescript-eslint/semi": ["warn"],
109+
"@typescript-eslint/strict-boolean-expressions": "off", // *
110+
"@typescript-eslint/triple-slash-reference": [
111+
"warn",
112+
{
113+
path: "always",
114+
types: "prefer-import",
115+
lib: "always",
116+
},
117+
],
118+
"@typescript-eslint/typedef": [
119+
"warn",
120+
{
121+
"parameter": true,
122+
"propertyDeclaration": true,
123+
}
124+
],
125+
"@typescript-eslint/unbound-method": "off", // *
126+
"@typescript-eslint/unified-signatures": "warn",
127+
"arrow-parens": ["off", "always"],
128+
"camelcase": "warn",
129+
"comma-dangle": "off",
130+
"comma-spacing": "warn",
131+
"complexity": "off",
132+
"constructor-super": "warn",
133+
"eol-last": "off",
134+
"eqeqeq": ["warn", "smart"],
135+
"guard-for-in": "warn",
136+
"id-blacklist": [
137+
"warn",
138+
"any",
139+
"Number",
140+
"number",
141+
"String",
142+
"string",
143+
"Boolean",
144+
"boolean",
145+
"Undefined",
146+
"undefined",
147+
],
148+
"id-match": "warn",
149+
"import/order": "off",
150+
"max-classes-per-file": "off",
151+
"max-len": "off",
152+
"new-parens": "warn",
153+
"no-bitwise": "warn",
154+
"no-caller": "warn",
155+
"no-cond-assign": "warn",
156+
"no-console": "warn",
157+
"no-debugger": "warn",
158+
"no-duplicate-imports": "warn",
159+
"no-empty": "warn",
160+
"no-eval": "warn",
161+
"no-extra-bind": "warn",
162+
"no-extra-boolean-cast": "warn",
163+
"no-case-declarations": "warn",
164+
"no-constant-condition": "warn",
165+
"no-fallthrough": "off", // Handled by tsconfig option
166+
"no-invalid-this": "off", // * was warn
167+
"no-irregular-whitespace": "warn",
168+
"no-multiple-empty-lines": "off",
169+
"no-new-wrappers": "warn",
170+
"no-prototype-builtins": "warn",
171+
"no-redeclare": "off", // Handled by @typescript-eslint/no-redeclare
172+
"no-shadow": "off", // Handled by @typescript-eslint/no-shadow
173+
"no-throw-literal": "warn",
174+
"no-trailing-spaces": "warn",
175+
"no-undef-init": "warn",
176+
"no-underscore-dangle": "off", // * was warn
177+
"no-unexpected-multiline": "warn",
178+
"no-unused-expressions": "off", // Disabled because of @typescript-eslint/no-unused-expressions
179+
"no-unsafe-finally": "warn",
180+
"no-unsafe-optional-chaining": "warn",
181+
"no-unused-labels": "warn",
182+
"no-unused-vars": "off", // Disabled because of @typescript-eslint/no-unused-vars
183+
"no-useless-escape": "warn",
184+
"no-var": "warn",
185+
"no-void": ["warn", { "allowAsStatement": true }],
186+
"object-shorthand": "off",
187+
"one-var": ["off", "never"],
188+
"prefer-arrow/prefer-arrow-functions": "off",
189+
"prefer-const": "warn",
190+
"quotes": ["warn", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
191+
"quote-props": "off",
192+
"radix": "off",
193+
"sort-imports": "warn",
194+
"spaced-comment": ["warn", "always", { "exceptions": ["*-"], "markers": ["/"] }],
195+
"use-isnan": "warn",
196+
"valid-typeof": ["warn", { "requireStringLiterals": true }]
197+
}
198+
};
199+
200+

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on: push
4+
5+
jobs:
6+
run-linters:
7+
name: Run CI
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Check out Git repository
12+
uses: actions/checkout@v2
13+
14+
- name: Set up Node.js
15+
uses: actions/setup-node@v2
16+
with:
17+
node-version: 14
18+
19+
- name: Install Node.js dependencies
20+
run: npm ci
21+
22+
- name : Run test
23+
run: npm run test
24+
25+
- name: Run linter
26+
run: npm run lint

README.md

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Diff and markup HTML with `<ins>` and `<del>` tags.
77

88
Quote from the original source of this fork:
99

10-
*`htmldiff.js` is a JavaScript port of [https://github.com/myobie/htmldiff](https://github.com/myobie/htmldiff) by
11-
[Keanu Lee](http://keanulee.com) at [Inkling](https://www.inkling.com/).*
10+
*`htmldiff.js` is a TypeScript port of [https://github.com/myobie/htmldiff](https://github.com/myobie/htmldiff) by
11+
[Keanu Lee](http://keanulee.com) at [Inkling](https://www.inkling.com/) via [htmldiff.js](https://github.com/nataliesantiago/htmldiff.js).*
1212

1313
**htmldiff.js** is based on [this fork](https://github.com/inkling/htmldiff.js) and adds a few things:
1414

@@ -31,21 +31,9 @@ The module can be used as module in Node.js, with RequireJS, or even just as a s
3131

3232
## API
3333

34-
The module exports a single default function:
34+
The exports can be found in [`dist/htmldiff.d.ts`](https://github.com/mblink/htmldiff.js/blob/master/dist/htmldiff.d.ts)
3535

36-
JavaScript:
37-
38-
````javascript
39-
diff(before, after, className, dataPrefix, atomicTags);
40-
````
41-
42-
TypeScript:
43-
44-
````javascript
45-
function diff(before: string, after: string, className?: string | null, dataPrefix?: string | null, atomicTags?: string | null): string;
46-
````
47-
48-
### Parameters
36+
### Diff Parameters
4937

5038
- `before` (string) is the original HTML text.
5139
- `after` (string) is the HTML text after the changes have been applied.
@@ -70,14 +58,6 @@ of these three parameters it will be ignored:
7058

7159
### Example
7260

73-
JavaScript:
74-
75-
```javascript
76-
diff = require('node-htmldiff');
77-
78-
console.log(diff('<p>This is some text</p>', '<p>That is some more text</p>', 'myClass'));
79-
```
80-
8161
TypeScript:
8262

8363
```javascript
@@ -86,50 +66,17 @@ TypeScript:
8666
console.log(diff("<p>This is some text</p>", "<p>That is some more text</p>", "myClass"));
8767
```
8868

89-
Please note that `diff` is only an arbitrary name; since the module exports only one default
90-
function you can use whatever name you like, e. g., `diffHTML`.
91-
9269
Result:
9370

9471
```html
9572
<p><del data-operation-index="1" class="myClass">This</del><ins data-operation-index="1" class="myClass">That</ins> is some<ins data-operation-index="3" class="myClass"> more</ins> text.</p>
9673
```
9774

98-
99-
## Command line interface
100-
101-
```bash
102-
htmldiff beforeFile afterFile diffedFile [-c className] [-p dataPrefix] [-t atomicTags]
103-
```
104-
105-
Parameters:
106-
107-
- `beforeFile` An HTML input file in its original form.
108-
109-
- `afterFile` An HTML input file, based on `beforeFile` but with changes.
110-
111-
- `diffedFile` Name of the diffed HTML output file. All differences between
112-
`beforeFile` and `afterFile` will be surrounded with `<ins>` and `<del>`
113-
tags. If diffedFile is `-` (minus) the result will be written with
114-
`console.log()` to stdout.
115-
116-
Options:
117-
118-
`-c className`, `-p dataPrefix` and `-t atomicTags` are all optional. For a
119-
description please see API documentation above.
120-
121-
12275
## Development
123-
124-
After cloning the repository run `npm i` or `npm install` to install the necessary
125-
dependencies. A run of `npm run make` creates the JavaScript output file.
126-
`npm run lint` checks the TypeScript sources with TSLint. `npm test` runs all the
127-
tests from the `test` directory. `npm run testsample` diffs the HTML sample files
128-
from the directory `sample` and logs the result to the console.
129-
130-
The command line interface of htmldiff is developed in TypeScript so you have to run
131-
`npm run make` once to create the JavaScript output file.
132-
76+
* `npm install` to install dependencies
77+
* `npm run lint` to ESLint the TypeScript
78+
* `npm run make` to compile the TypeScript
79+
* `npm run test` to run the tests
13380

13481
## Credits
13582

0 commit comments

Comments
 (0)