Skip to content

Commit ba69f71

Browse files
balloobeddywashere
authored andcommitted
build(omit): Remove lodash.omit (reactstrap#478)
* Remove lodash.omit * Lint
1 parent d1448e0 commit ba69f71

File tree

10 files changed

+62
-15
lines changed

10 files changed

+62
-15
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
"classnames": "^2.2.3",
9090
"lodash.isfunction": "^3.0.8",
9191
"lodash.isobject": "^3.0.2",
92-
"lodash.omit": "^4.4.1",
9392
"lodash.tonumber": "^4.0.3",
9493
"prop-types": "^15.5.8",
9594
"reactstrap-tether": "1.3.4"

src/Collapse.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
4-
import omit from 'lodash.omit';
5-
import { mapToCssModules } from './utils';
4+
import { mapToCssModules, omit } from './utils';
65

76
const SHOW = 'SHOW';
87
const SHOWN = 'SHOWN';

src/Dropdown.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import React from 'react';
55
import PropTypes from 'prop-types';
66
import ReactDOM from 'react-dom';
77
import classNames from 'classnames';
8-
import omit from 'lodash.omit';
9-
import { mapToCssModules } from './utils';
8+
import { mapToCssModules, omit } from './utils';
109
import TetherContent from './TetherContent';
1110
import DropdownMenu from './DropdownMenu';
1211

src/DropdownItem.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import omit from 'lodash.omit';
43
import classNames from 'classnames';
5-
import { mapToCssModules } from './utils';
4+
import { mapToCssModules, omit } from './utils';
65

76
const propTypes = {
87
children: PropTypes.node,

src/Fade.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
4-
import omit from 'lodash.omit';
5-
import { mapToCssModules } from './utils';
4+
import { mapToCssModules, omit } from './utils';
65

76
const propTypes = {
87
baseClass: PropTypes.string,

src/Popover.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
4-
import omit from 'lodash.omit';
54
import TetherContent from './TetherContent';
6-
import { getTetherAttachments, mapToCssModules, tetherAttachements } from './utils';
5+
import { getTetherAttachments, mapToCssModules, omit, tetherAttachements } from './utils';
76

87
const propTypes = {
98
placement: PropTypes.oneOf(tetherAttachements),

src/TabContent.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
4-
import omit from 'lodash.omit';
5-
import { mapToCssModules } from './utils';
4+
import { mapToCssModules, omit } from './utils';
65

76
const propTypes = {
87
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),

src/Tooltip.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
4-
import omit from 'lodash.omit';
54
import TetherContent from './TetherContent';
6-
import { getTetherAttachments, tetherAttachements, mapToCssModules } from './utils';
5+
import { getTetherAttachments, mapToCssModules, omit, tetherAttachements } from './utils';
76

87
const propTypes = {
98
placement: PropTypes.oneOf(tetherAttachements),

src/__tests__/utils.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,48 @@ describe('Utils', () => {
154154
});
155155
});
156156

157+
describe('omit', () => {
158+
it('should omit keys', () => {
159+
const input = {
160+
hello: 'world',
161+
speed: 'fast',
162+
size: 'small'
163+
};
164+
expect(Utils.omit(input, ['hello'])).toEqual({ speed: 'fast', size: 'small' });
165+
});
166+
167+
it('should not alter source object', () => {
168+
const input = {
169+
hello: 'world',
170+
speed: 'fast',
171+
size: 'small'
172+
};
173+
expect(Utils.omit(input, ['hello'])).toEqual({ speed: 'fast', size: 'small' });
174+
expect(input).toEqual({
175+
hello: 'world',
176+
speed: 'fast',
177+
size: 'small'
178+
});
179+
});
180+
181+
it('should ignore non-existing keys', () => {
182+
const input = {
183+
hello: 'world',
184+
speed: 'fast',
185+
size: 'small'
186+
};
187+
expect(Utils.omit(input, ['non-existing', 'hello'])).toEqual({ speed: 'fast', size: 'small' });
188+
});
189+
190+
it('should return a new object', () => {
191+
const input = {
192+
hello: 'world'
193+
};
194+
// toBe tests equality using `===` and so will test if it's not the same object.
195+
expect(Utils.omit(input, [])).not.toBe(input);
196+
});
197+
});
198+
157199
// TODO
158200
// describe('getScrollbarWidth', () => {
159201
// // jsdom workaround https://github.com/tmpvar/jsdom/issues/135#issuecomment-68191941

src/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,16 @@ export function mapToCssModules(className, cssModule) {
154154
if (!cssModule) return className;
155155
return className.split(' ').map(c => cssModule[c] || c).join(' ');
156156
}
157+
158+
/**
159+
* Returns a new object with the key/value pairs from `obj` that are not in the array `omitKeys`.
160+
*/
161+
export function omit(obj, omitKeys) {
162+
const result = {};
163+
Object.keys(obj).forEach(key => {
164+
if (omitKeys.indexOf(key) === -1) {
165+
result[key] = obj[key];
166+
}
167+
});
168+
return result;
169+
}

0 commit comments

Comments
 (0)