Skip to content

Commit 43c6775

Browse files
Merge pull request #157 from remarkablemark/build/devDependencies
build: upgrade devDependencies
2 parents 598f9eb + 91fb693 commit 43c6775

13 files changed

+73
-63
lines changed

.eslintrc renamed to .eslintrc.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
},
1313
"plugins": ["prettier"],
1414
"rules": {
15+
"no-debugger": "error",
16+
"no-console": "error",
1517
"prettier/prettier": "error"
1618
}
1719
}

.huskyrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

.huskyrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"hooks": {
3+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
4+
"pre-commit": "npm run lint:dts && npm run test:coverage && lint-staged"
5+
}
6+
}

.lintstagedrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.lintstagedrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"*.js": "npm run lint:fix",
3+
"*.{html,json,md,yml}": "prettier --write"
4+
}

.prettierrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.prettierrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"arrowParens": "avoid",
3+
"trailingComma": "none",
4+
"singleQuote": true
5+
}

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ var domParserOptions = { decodeEntities: true, lowerCaseAttributeNames: false };
77
/**
88
* Converts HTML string to React elements.
99
*
10-
* @param {String} html - The HTML string to parse to React.
11-
* @param {Object} [options] - The parser options.
12-
* @param {Function} [options.replace] - The replace method.
13-
* @return {ReactElement|Array|String} - When parsed with HTML string, returns React elements; otherwise, returns string or empty array.
10+
* @param {String} html - The HTML string to parse to React.
11+
* @param {Object} [options] - The parser options.
12+
* @param {Function} [options.replace] - The replace method.
13+
* @return {JSX.Element|JSX.Element[]|String} - Returns React element(s), string, or empty array.
1414
*/
1515
function HTMLReactParser(html, options) {
1616
if (typeof html !== 'string') {
@@ -22,5 +22,6 @@ function HTMLReactParser(html, options) {
2222
HTMLReactParser.domToReact = domToReact;
2323
HTMLReactParser.htmlToDOM = htmlToDOM;
2424

25+
// support CommonJS and ES Modules
2526
module.exports = HTMLReactParser;
2627
module.exports.default = HTMLReactParser;

lib/attributes-to-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function cssToJs(style) {
7777
var styleObject = {};
7878

7979
if (style) {
80-
styleToObject(style, function(property, value) {
80+
styleToObject(style, function (property, value) {
8181
// skip CSS comment
8282
if (property && value) {
8383
styleObject[camelCase(property)] = value;

lib/utilities.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function camelCase(string) {
2121
// convert to camelCase
2222
return string
2323
.toLowerCase()
24-
.replace(hyphenPatternRegex, function(_, character) {
24+
.replace(hyphenPatternRegex, function (_, character) {
2525
return character.toUpperCase();
2626
});
2727
}

package.json

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
"main": "index.js",
77
"scripts": {
88
"benchmark": "node benchmark",
9-
"build": "npm run clean && npm run build:min && npm run build:unmin",
10-
"build:min": "cross-env NODE_ENV=production rollup --config --file dist/html-react-parser.min.js --sourcemap",
11-
"build:unmin": "cross-env NODE_ENV=development rollup --config --file dist/html-react-parser.js",
9+
"build": "rollup --config",
1210
"clean": "rimraf dist",
1311
"lint": "eslint --ignore-path .gitignore --ignore-pattern /examples/ .",
1412
"lint:dts": "dtslint .",
1513
"lint:fix": "npm run lint -- --fix",
16-
"prepublishOnly": "npm run lint && npm run lint:dts && npm test && npm run build",
14+
"prepublishOnly": "npm run lint && npm run lint:dts && npm test && npm run clean && npm run build",
1715
"release": "standard-version --no-verify",
1816
"test": "mocha",
1917
"test:coverage": "nyc npm test",
@@ -40,28 +38,28 @@
4038
"style-to-object": "0.3.0"
4139
},
4240
"devDependencies": {
43-
"@commitlint/cli": "^8.2.0",
44-
"@commitlint/config-conventional": "^8.2.0",
45-
"@types/react": "^16.9.11",
41+
"@commitlint/cli": "^8.3.5",
42+
"@commitlint/config-conventional": "^8.3.4",
43+
"@types/react": "^16.9.35",
4644
"benchmark": "^2.1.4",
47-
"cross-env": "^6.0.3",
48-
"dtslint": "^2.0.0",
49-
"eslint": "^6.6.0",
50-
"eslint-plugin-prettier": "^3.1.1",
51-
"husky": "^3.0.9",
52-
"lint-staged": "^9.4.2",
53-
"mocha": "^6.2.2",
54-
"nyc": "^14.1.1",
55-
"preact": "^10.0.4",
56-
"prettier": "^1.19.1",
45+
"dtslint": "^3.6.4",
46+
"eslint": "^7.1.0",
47+
"eslint-plugin-prettier": "^3.1.3",
48+
"husky": "^4.2.5",
49+
"lint-staged": "^10.2.6",
50+
"mocha": "^7.2.0",
51+
"nyc": "^15.0.1",
52+
"preact": "^10.4.4",
53+
"prettier": "^2.0.5",
5754
"react": "^16",
5855
"react-dom": "^16",
59-
"rimraf": "^3.0.0",
60-
"rollup": "^1.26.3",
56+
"rimraf": "^3.0.2",
57+
"rollup": "^1.32.1",
6158
"rollup-plugin-commonjs": "^10.1.0",
6259
"rollup-plugin-node-resolve": "^5.2.0",
63-
"rollup-plugin-uglify": "^6.0.3",
64-
"standard-version": "^6"
60+
"rollup-plugin-uglify": "^6.0.4",
61+
"standard-version": "^6",
62+
"typescript": "^3.9.3"
6563
},
6664
"peerDependencies": {
6765
"react": "^0.14 || ^15 || ^16"

rollup.config.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@ import commonjs from 'rollup-plugin-commonjs';
22
import resolve from 'rollup-plugin-node-resolve';
33
import { uglify } from 'rollup-plugin-uglify';
44

5-
const config = {
5+
/**
6+
* Build rollup config for development (default) or production (minify = true).
7+
*
8+
* @param {Boolean} [minify=false]
9+
* @return {Object}
10+
*/
11+
const getConfig = (minify = false) => ({
612
external: ['react'],
713
input: 'index.js',
814
output: {
15+
file: `dist/html-react-parser${minify ? '.min' : ''}.js`,
916
format: 'umd',
1017
globals: {
1118
react: 'React'
1219
},
13-
name: 'HTMLReactParser'
20+
name: 'HTMLReactParser',
21+
sourcemap: true
1422
},
15-
plugins: [commonjs(), resolve({ browser: true })]
16-
};
23+
plugins: [commonjs(), resolve({ browser: true }), minify && uglify()]
24+
});
1725

18-
if (process.env.NODE_ENV === 'production') {
19-
config.plugins.push(uglify());
20-
}
21-
22-
export default config;
26+
export default [getConfig(), getConfig(true)];

test/html-to-react.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
const assert = require('assert');
22
const React = require('react');
3-
const parse = require('../');
3+
const parse = require('..');
44
const { data, render } = require('./helpers/');
55

66
describe('html-to-react', () => {
7+
describe('exports', () => {
8+
it('has default ES Module', () => {
9+
assert.strictEqual(parse.default, parse);
10+
});
11+
12+
it('has domToReact', () => {
13+
assert.strictEqual(parse.domToReact, require('../lib/dom-to-react'));
14+
});
15+
16+
it('contains htmlToDOM', () => {
17+
assert.strictEqual(parse.htmlToDOM, require('html-dom-parser'));
18+
});
19+
});
20+
721
describe('parser', () => {
822
[undefined, null, {}, [], 42].forEach(value => {
923
it(`throws an error if first argument is ${value}`, () => {
@@ -13,10 +27,6 @@ describe('html-to-react', () => {
1327
});
1428
});
1529

16-
it('has default ES Module defined', () => {
17-
assert.strictEqual(parse.default, parse);
18-
});
19-
2030
it('returns string if it cannot be parsed as HTML', () => {
2131
assert.strictEqual(parse('foo'), 'foo');
2232
});
@@ -77,7 +87,7 @@ describe('html-to-react', () => {
7787

7888
describe('options', () => {
7989
describe('replace', () => {
80-
it('overrides the element if replace is valid', () => {
90+
it('overrides the element if a valid React element is returned', () => {
8191
const html = data.html.complex;
8292
const reactElement = parse(html, {
8393
replace: node => {
@@ -92,7 +102,7 @@ describe('html-to-react', () => {
92102
);
93103
});
94104

95-
it('does not override the element if replace is invalid', () => {
105+
it('does not override the element if an invalid React element is returned', () => {
96106
const html = data.html.complex;
97107
const reactElement = parse(html, {
98108
replace: node => {
@@ -115,9 +125,3 @@ describe('html-to-react', () => {
115125
});
116126
});
117127
});
118-
119-
describe('dom-to-react', () => {
120-
it('exports domToReact', () => {
121-
assert.strictEqual(parse.domToReact, require('../lib/dom-to-react'));
122-
});
123-
});

0 commit comments

Comments
 (0)