Skip to content

Commit

Permalink
Merge d1d0ca9 into 179b68e
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Jun 27, 2017
2 parents 179b68e + d1d0ca9 commit d348cf9
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 15 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -89,7 +89,6 @@
"classnames": "^2.2.3",
"lodash.isfunction": "^3.0.8",
"lodash.isobject": "^3.0.2",
"lodash.omit": "^4.4.1",
"lodash.tonumber": "^4.0.3",
"prop-types": "^15.5.8",
"reactstrap-tether": "1.3.4"
Expand Down
3 changes: 1 addition & 2 deletions src/Collapse.js
@@ -1,8 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import omit from 'lodash.omit';
import { mapToCssModules } from './utils';
import { mapToCssModules, omit } from './utils';

const SHOW = 'SHOW';
const SHOWN = 'SHOWN';
Expand Down
3 changes: 1 addition & 2 deletions src/Dropdown.js
Expand Up @@ -5,8 +5,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import classNames from 'classnames';
import omit from 'lodash.omit';
import { mapToCssModules } from './utils';
import { mapToCssModules, omit } from './utils';
import TetherContent from './TetherContent';
import DropdownMenu from './DropdownMenu';

Expand Down
3 changes: 1 addition & 2 deletions src/DropdownItem.js
@@ -1,8 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import omit from 'lodash.omit';
import classNames from 'classnames';
import { mapToCssModules } from './utils';
import { mapToCssModules, omit } from './utils';

const propTypes = {
children: PropTypes.node,
Expand Down
3 changes: 1 addition & 2 deletions src/Fade.js
@@ -1,8 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import omit from 'lodash.omit';
import { mapToCssModules } from './utils';
import { mapToCssModules, omit } from './utils';

const propTypes = {
baseClass: PropTypes.string,
Expand Down
3 changes: 1 addition & 2 deletions src/Popover.js
@@ -1,9 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import omit from 'lodash.omit';
import TetherContent from './TetherContent';
import { getTetherAttachments, mapToCssModules, tetherAttachements } from './utils';
import { getTetherAttachments, mapToCssModules, omit, tetherAttachements } from './utils';

const propTypes = {
placement: PropTypes.oneOf(tetherAttachements),
Expand Down
3 changes: 1 addition & 2 deletions src/TabContent.js
@@ -1,8 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import omit from 'lodash.omit';
import { mapToCssModules } from './utils';
import { mapToCssModules, omit } from './utils';

const propTypes = {
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
Expand Down
3 changes: 1 addition & 2 deletions src/Tooltip.js
@@ -1,9 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import omit from 'lodash.omit';
import TetherContent from './TetherContent';
import { getTetherAttachments, tetherAttachements, mapToCssModules } from './utils';
import { getTetherAttachments, mapToCssModules, omit, tetherAttachements } from './utils';

const propTypes = {
placement: PropTypes.oneOf(tetherAttachements),
Expand Down
42 changes: 42 additions & 0 deletions src/__tests__/utils.spec.js
Expand Up @@ -154,6 +154,48 @@ describe('Utils', () => {
});
});

describe('omit', () => {
it('should omit keys', () => {
const input = {
hello: 'world',
speed: 'fast',
size: 'small'
};
expect(Utils.omit(input, ['hello'])).toEqual({ speed: 'fast', size: 'small' });
});

it('should not alter source object', () => {
const input = {
hello: 'world',
speed: 'fast',
size: 'small'
};
expect(Utils.omit(input, ['hello'])).toEqual({ speed: 'fast', size: 'small' });
expect(input).toEqual({
hello: 'world',
speed: 'fast',
size: 'small'
});
});

it('should ignore non-existing keys', () => {
const input = {
hello: 'world',
speed: 'fast',
size: 'small'
};
expect(Utils.omit(input, ['non-existing', 'hello'])).toEqual({ speed: 'fast', size: 'small' });
});

it('should return a new object', () => {
const input = {
hello: 'world'
};
// toBe tests equality using `===` and so will test if it's not the same object.
expect(Utils.omit(input, [])).not.toBe(input);
});
});

// TODO
// describe('getScrollbarWidth', () => {
// // jsdom workaround https://github.com/tmpvar/jsdom/issues/135#issuecomment-68191941
Expand Down
13 changes: 13 additions & 0 deletions src/utils.js
Expand Up @@ -154,3 +154,16 @@ export function mapToCssModules(className, cssModule) {
if (!cssModule) return className;
return className.split(' ').map(c => cssModule[c] || c).join(' ');
}

/**
* Returns a new object with the key/value pairs from `obj` that are not in the array `omitKeys`.
*/
export function omit(obj, omitKeys) {
const result = {};
Object.keys(obj).forEach(key => {
if (omitKeys.indexOf(key) === -1) {
result[key] = obj[key];
}
});
return result;
}

0 comments on commit d348cf9

Please sign in to comment.