Skip to content

Commit c6e4fac

Browse files
style: remove "use strict" directive from modules and tidy comments
Removing "use strict" directive since ES6 modules will always be in strict mode. Also, webpack and other build tools will automatically add the directive during compilation. Remove and tidy some comments and fix broken links.
1 parent d49e982 commit c6e4fac

File tree

5 files changed

+24
-61
lines changed

5 files changed

+24
-61
lines changed

index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
'use strict';
2-
3-
/**
4-
* Module dependencies.
5-
*/
61
var domToReact = require('./lib/dom-to-react');
72
var htmlToDOM = require('html-dom-parser');
83

lib/attributes-to-props.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
'use strict';
2-
3-
/**
4-
* Module dependencies.
5-
*/
6-
var utilities = require('./utilities');
1+
var DOMProperty = require('react-dom-core/lib/DOMProperty');
72
var propertyConfig = require('./property-config');
83
var styleToObject = require('style-to-object');
4+
var utilities = require('./utilities');
5+
96
var config = propertyConfig.config;
107
var isCustomAttribute = propertyConfig.HTMLDOMPropertyConfig.isCustomAttribute;
11-
12-
var DOMProperty = require('react-dom-core/lib/DOMProperty');
138
DOMProperty.injection.injectDOMPropertyConfig(propertyConfig.HTMLDOMPropertyConfig);
149

1510
/**
16-
* Make attributes compatible with React props.
11+
* Makes attributes compatible with React props.
1712
*
1813
* @param {Object} attributes - The attributes.
1914
* @return {Object} - The props.
@@ -56,21 +51,19 @@ function attributesToProps(attributes) {
5651
if (attributes.style != null) {
5752
props.style = cssToJs(attributes.style);
5853
}
59-
6054
return props;
6155
}
6256

6357
/**
64-
* Convert CSS style string to JS style object.
58+
* Converts CSS style string to JS style object.
6559
*
6660
* @param {String} style - The CSS style.
6761
* @return {Object} - The JS style object.
6862
*/
6963
function cssToJs(style) {
7064
if (typeof style !== 'string') {
71-
throw new Error('`cssToJs`: first argument must be a string. ');
65+
throw new TypeError('First argument must be a string.');
7266
}
73-
7467
var styleObj = {};
7568

7669
styleToObject(style, function(propName, propValue) {
@@ -79,11 +72,7 @@ function cssToJs(style) {
7972
styleObj[utilities.camelCase(propName)] = propValue;
8073
}
8174
});
82-
8375
return styleObj;
8476
}
8577

86-
/**
87-
* Export attributes to props helper.
88-
*/
8978
module.exports = attributesToProps;

lib/dom-to-react.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
'use strict';
2-
3-
/**
4-
* Module dependencies.
5-
*/
61
var React = require('react');
72
var attributesToProps = require('./attributes-to-props');
83

94
/**
10-
* Convert DOM nodes to React elements.
5+
* Converts DOM nodes to React elements.
116
*
127
* @param {Array} nodes - The DOM nodes.
138
* @param {Object} [options] - The additional options.
@@ -63,7 +58,7 @@ function domToReact(nodes, options) {
6358

6459
} else if (node.type === 'tag') {
6560
// setting textarea value in children is an antipattern in React
66-
// https://facebook.github.io/react/docs/forms.html#why-textarea-value
61+
// https://reactjs.org/docs/forms.html#the-textarea-tag
6762
if (node.name === 'textarea' && node.children[0]) {
6863
props.defaultValue = node.children[0].data;
6964

@@ -88,14 +83,7 @@ function domToReact(nodes, options) {
8883
);
8984
}
9085

91-
if (result.length === 1) {
92-
return result[0];
93-
} else {
94-
return result;
95-
}
86+
return result.length === 1 ? result[0] : result;
9687
}
9788

98-
/**
99-
* Export DOM to React parser.
100-
*/
10189
module.exports = domToReact;

lib/property-config.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
'use strict';
2-
3-
/**
4-
* Module dependencies.
5-
*/
6-
var utilities = require('./utilities');
7-
8-
// HTML and SVG DOM Property Configs
91
var HTMLDOMPropertyConfig = require('react-dom-core/lib/HTMLDOMPropertyConfig');
102
var SVGDOMPropertyConfig = require('react-dom-core/lib/SVGDOMPropertyConfig');
3+
var utilities = require('./utilities');
114

125
var config = {
136
html: {},
@@ -18,7 +11,8 @@ var propertyName;
1811

1912
/**
2013
* HTML DOM property config.
21-
* https://github.com/facebook/react/blob/master/src/renderers/dom/shared/HTMLDOMPropertyConfig.js
14+
*
15+
* https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/HTMLDOMPropertyConfig.js
2216
*/
2317

2418
// first map out the HTML attribute names
@@ -36,7 +30,8 @@ for (propertyName in HTMLDOMPropertyConfig.Properties) {
3630

3731
/**
3832
* SVG DOM property config.
39-
* https://github.com/facebook/react/blob/master/src/renderers/dom/shared/SVGDOMPropertyConfig.js
33+
*
34+
* https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/SVGDOMPropertyConfig.js
4035
*/
4136

4237
// first map out the SVG attribute names
@@ -52,9 +47,6 @@ for (propertyName in SVGDOMPropertyConfig.Properties) {
5247
config.html[propertyName] = propertyName;
5348
}
5449

55-
/**
56-
* Export property configs.
57-
*/
5850
module.exports = {
5951
config: config,
6052
HTMLDOMPropertyConfig: HTMLDOMPropertyConfig,

lib/utilities.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
'use strict';
2-
3-
var _hyphenPattern = /-(.)/g;
1+
var hyphenPatternRegex = /-([a-z])/g;
42

53
/**
6-
* Convert a string to camel case.
4+
* Converts a string to camelCase.
75
*
86
* @param {String} string - The string.
97
* @return {String}
108
*/
119
function camelCase(string) {
12-
if (typeof string !== 'string') { // null is an object
10+
if (typeof string !== 'string') {
1311
throw new TypeError('First argument must be a string');
1412
}
15-
if(string.indexOf('-') < 0) {
13+
14+
// no hyphen found
15+
if (string.indexOf('-') === -1) {
1616
return string;
1717
}
18-
return string.toLowerCase().replace(_hyphenPattern, function(_, character) {
18+
19+
// convert to camelCase
20+
return string.toLowerCase().replace(hyphenPatternRegex, function(_, character) {
1921
return character.toUpperCase();
2022
});
2123
}
@@ -28,7 +30,7 @@ function camelCase(string) {
2830
* @return {Object} - The inverted object.
2931
*/
3032
function invertObject(obj, override) {
31-
if (typeof obj !== 'object' || !obj) { // null is an object
33+
if (!obj || typeof obj !== 'object') {
3234
throw new TypeError('First argument must be an object');
3335
}
3436

@@ -57,9 +59,6 @@ function invertObject(obj, override) {
5759
return result;
5860
}
5961

60-
/**
61-
* Export utilties.
62-
*/
6362
module.exports = {
6463
camelCase: camelCase,
6564
invertObject: invertObject

0 commit comments

Comments
 (0)