Skip to content

Commit 6673ce0

Browse files
author
Edward Drapkin
committed
remove lodash dependency
1 parent b611446 commit 6673ce0

File tree

9 files changed

+34
-30
lines changed

9 files changed

+34
-30
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
"license": "BSD-3-Clause",
2222
"dependencies": {
2323
"hoist-non-react-statics": "^1.0.5",
24-
"lodash": "^4.6.1",
2524
"object-unfreeze": "^1.0.2"
2625
},
2726
"devDependencies": {
2827
"babel-cli": "^6.10.1",
2928
"babel-plugin-add-module-exports": "^0.2.1",
30-
"babel-plugin-lodash": "^3.2.5",
3129
"babel-plugin-transform-proto-to-assign": "^6.9.0",
3230
"babel-preset-es2015": "^6.9.0",
3331
"babel-preset-react": "^6.11.1",

src/extendReactClass.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-disable react/prop-types */
22

33
import React from 'react';
4-
import _ from 'lodash';
54
import hoistNonReactStatics from 'hoist-non-react-statics';
65
import linkClass from './linkClass';
6+
import {isObject} from './utils';
77

88
/**
99
* @param {ReactClass} Component
@@ -14,15 +14,13 @@ import linkClass from './linkClass';
1414
export default (Component: Object, defaultStyles: Object, options: Object) => {
1515
const WrappedComponent = class extends Component {
1616
render () {
17-
let propsChanged,
17+
let propsChanged = false,
1818
styles;
1919

20-
propsChanged = false;
21-
2220
if (this.props.styles) {
2321
styles = this.props.styles;
24-
} else if (_.isObject(defaultStyles)) {
25-
this.props = _.assign({}, this.props, {
22+
} else if (isObject(defaultStyles)) {
23+
this.props = Object.assign({}, this.props, {
2624
styles: defaultStyles
2725
});
2826

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _ from 'lodash';
22
import extendReactClass from './extendReactClass';
33
import wrapStatelessFunction from './wrapStatelessFunction';
44
import makeConfiguration from './makeConfiguration';
5+
import {isFunction} from './utils';
56

67
/**
78
* @see https://github.com/gajus/react-css-modules#options
@@ -12,7 +13,7 @@ type TypeOptions = {};
1213
* Determines if the given object has the signature of a class that inherits React.Component.
1314
*/
1415
const isReactComponent = (maybeReactComponent: any): boolean => {
15-
return 'prototype' in maybeReactComponent && _.isFunction(maybeReactComponent.prototype.render);
16+
return 'prototype' in maybeReactComponent && isFunction(maybeReactComponent.prototype.render);
1617
};
1718

1819
/**
@@ -48,7 +49,7 @@ const decoratorConstructor = (defaultStyles: Object, options: TypeOptions): Func
4849
};
4950

5051
export default (...args) => {
51-
if (_.isFunction(args[0])) {
52+
if (isFunction(args[0])) {
5253
return functionConstructor(args[0], args[1], args[2]);
5354
} else {
5455
return decoratorConstructor(args[0], args[1]);

src/isIterable.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import _ from 'lodash';
1+
import {isFunction, isObject} from './utils';
22

3-
const ITERATOR_SYMBOL = typeof Symbol !== 'undefined' && _.isFunction(Symbol) && Symbol.iterator;
3+
const ITERATOR_SYMBOL = typeof Symbol !== 'undefined' && isFunction(Symbol) && Symbol.iterator;
44
const OLD_ITERATOR_SYMBOL = '@@iterator';
55

66
/**
@@ -10,7 +10,7 @@ const OLD_ITERATOR_SYMBOL = '@@iterator';
1010
export default (maybeIterable: any): boolean => {
1111
let iterator;
1212

13-
if (!_.isObject(maybeIterable)) {
13+
if (!isObject(maybeIterable)) {
1414
return false;
1515
}
1616

@@ -20,5 +20,5 @@ export default (maybeIterable: any): boolean => {
2020
iterator = maybeIterable[OLD_ITERATOR_SYMBOL];
2121
}
2222

23-
return _.isFunction(iterator);
23+
return isFunction(iterator);
2424
};

src/linkClass.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import _ from 'lodash';
21
import React, {
32
ReactElement
43
} from 'react';
54
import objectUnfreeze from 'object-unfreeze';
65
import isIterable from './isIterable';
76
import parseStyleName from './parseStyleName';
87
import generateAppendClassName from './generateAppendClassName';
8+
import {isObject} from './utils';
99

1010
const linkElement = (element: ReactElement, styles: Object, configuration: Object): ReactElement => {
1111
let appendClassName,
@@ -26,7 +26,7 @@ const linkElement = (element: ReactElement, styles: Object, configuration: Objec
2626

2727
if (React.isValidElement(elementShallowCopy.props.children)) {
2828
elementShallowCopy.props.children = linkElement(React.Children.only(elementShallowCopy.props.children), styles, configuration);
29-
} else if (_.isArray(elementShallowCopy.props.children) || isIterable(elementShallowCopy.props.children)) {
29+
} else if (Array.isArray(elementShallowCopy.props.children) || isIterable(elementShallowCopy.props.children)) {
3030
elementShallowCopy.props.children = React.Children.map(elementShallowCopy.props.children, (node) => {
3131
if (React.isValidElement(node)) {
3232
return linkElement(node, styles, configuration);
@@ -65,7 +65,7 @@ const linkElement = (element: ReactElement, styles: Object, configuration: Objec
6565
*/
6666
export default (element: ReactElement, styles = {}, configuration = {}): ReactElement => {
6767
// @see https://github.com/gajus/react-css-modules/pull/30
68-
if (!_.isObject(element)) {
68+
if (!isObject(element)) {
6969
return element;
7070
}
7171

src/makeConfiguration.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import _ from 'lodash';
2-
31
/**
42
* @typedef CSSModules~Options
53
* @see {@link https://github.com/gajus/react-css-modules#options}
@@ -17,12 +15,14 @@ export default (userConfiguration = {}) => {
1715
errorWhenNotFound: true
1816
};
1917

20-
_.forEach(userConfiguration, (value, name) => {
21-
if (_.isUndefined(configuration[name])) {
18+
Object.keys(userConfiguration).forEach(name => {
19+
const value = userConfiguration[name];
20+
21+
if (!(name in configuration)) {
2222
throw new Error('Unknown configuration property "' + name + '".');
2323
}
2424

25-
if (!_.isBoolean(value)) {
25+
if (value !== true && value !== false) {
2626
throw new Error('"' + name + '" property value must be a boolean.');
2727
}
2828

src/parseStyleName.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import _ from 'lodash';
2-
31
const styleNameIndex = {};
42

53
export default (styleNamePropertyValue: string, allowMultiple: boolean): Array<string> => {
@@ -8,8 +6,7 @@ export default (styleNamePropertyValue: string, allowMultiple: boolean): Array<s
86
if (styleNameIndex[styleNamePropertyValue]) {
97
styleNames = styleNameIndex[styleNamePropertyValue];
108
} else {
11-
styleNames = _.trim(styleNamePropertyValue).split(' ');
12-
styleNames = _.filter(styleNames);
9+
styleNames = styleNamePropertyValue.trim().split(' ').filter(e => !!e);
1310

1411
styleNameIndex[styleNamePropertyValue] = styleNames;
1512
}

src/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function isObject(obj) {
2+
return obj === Object(obj);
3+
}
4+
5+
export function isFunction(func) {
6+
return (
7+
Object.prototype.toString.call(func) === '[object Function]'
8+
|| Object.prototype.toString.call(func) === '[object GeneratorFunction]'
9+
);
10+
}

src/wrapStatelessFunction.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable react/prop-types */
22

3-
import _ from 'lodash';
43
import React from 'react';
54
import linkClass from './linkClass';
5+
import {isObject} from './utils';
66

77
/**
88
* @see https://facebook.github.io/react/blog/2015/09/10/react-v0.14-rc1.html#stateless-function-components
@@ -15,8 +15,8 @@ export default (Component: Function, defaultStyles: Object, options: Object): Fu
1515
if (props.styles) {
1616
useProps = props;
1717
styles = props.styles;
18-
} else if (_.isObject(defaultStyles)) {
19-
useProps = _.assign({}, props, {
18+
} else if (isObject(defaultStyles)) {
19+
useProps = Object.assign({}, props, {
2020
styles: defaultStyles
2121
});
2222

@@ -35,7 +35,7 @@ export default (Component: Function, defaultStyles: Object, options: Object): Fu
3535
return React.createElement('noscript');
3636
};
3737

38-
_.assign(WrappedComponent, Component);
38+
Object.assign(WrappedComponent, Component);
3939

4040
return WrappedComponent;
4141
};

0 commit comments

Comments
 (0)