Skip to content

Commit 248678d

Browse files
Merge pull request #1103 from remarkablemark/chore/utilities
chore(utilities): remove unused function `invertObject`
2 parents ff88296 + 7cc8df7 commit 248678d

File tree

2 files changed

+0
-99
lines changed

2 files changed

+0
-99
lines changed

Diff for: lib/utilities.js

-36
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,6 @@
11
var React = require('react');
22
var styleToJS = require('style-to-js').default;
33

4-
/**
5-
* Swap key with value in an object.
6-
*
7-
* @param {object} obj - The object.
8-
* @param {Function} [override] - The override method.
9-
* @returns - The inverted object.
10-
*/
11-
function invertObject(obj, override) {
12-
if (!obj || typeof obj !== 'object') {
13-
throw new TypeError('First argument must be an object');
14-
}
15-
16-
var isOverridePresent = typeof override === 'function';
17-
var overrides = {};
18-
var result = {};
19-
20-
for (var key in obj) {
21-
var value = obj[key];
22-
23-
if (isOverridePresent) {
24-
overrides = override(key, value);
25-
if (overrides && overrides.length === 2) {
26-
result[overrides[0]] = overrides[1];
27-
continue;
28-
}
29-
}
30-
31-
if (typeof value === 'string') {
32-
result[value] = key;
33-
}
34-
}
35-
36-
return result;
37-
}
38-
394
var RESERVED_SVG_MATHML_ELEMENTS = new Set([
405
'annotation-xml',
416
'color-profile',
@@ -133,7 +98,6 @@ function returnFirstArg(arg) {
13398
module.exports = {
13499
PRESERVE_CUSTOM_ATTRIBUTES: PRESERVE_CUSTOM_ATTRIBUTES,
135100
ELEMENTS_WITH_NO_TEXT_CHILDREN: ELEMENTS_WITH_NO_TEXT_CHILDREN,
136-
invertObject: invertObject,
137101
isCustomComponent: isCustomComponent,
138102
setStyleProp: setStyleProp,
139103
canTextBeChildOfNode: canTextBeChildOfNode,

Diff for: test/utilities.test.js

-63
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,11 @@ const React = require('react');
22
const {
33
PRESERVE_CUSTOM_ATTRIBUTES,
44
ELEMENTS_WITH_NO_TEXT_CHILDREN,
5-
invertObject,
65
isCustomComponent,
76
setStyleProp,
87
canTextBeChildOfNode
98
} = require('../lib/utilities');
109

11-
describe('invertObject', () => {
12-
it.each([undefined, null, '', 'test', 0, 1, true, false, () => {}])(
13-
'throws error for value: %p',
14-
(value) => {
15-
expect(() => {
16-
invertObject(value);
17-
}).toThrow(TypeError);
18-
}
19-
);
20-
21-
it('swaps key with value', () => {
22-
expect(
23-
invertObject({
24-
foo: 'bar',
25-
baz: 'qux'
26-
})
27-
).toEqual({
28-
bar: 'foo',
29-
qux: 'baz'
30-
});
31-
});
32-
33-
it('swaps key with value if value is string', () => {
34-
expect(
35-
invertObject({
36-
$: 'dollar',
37-
_: 'underscore',
38-
num: 1,
39-
u: undefined,
40-
n: null
41-
})
42-
).toEqual({
43-
dollar: '$',
44-
underscore: '_'
45-
});
46-
});
47-
48-
describe('options', () => {
49-
it('applies override if provided', () => {
50-
expect(
51-
invertObject({ foo: 'bar', baz: 'qux' }, (key) => {
52-
if (key === 'foo') {
53-
return ['key', 'value'];
54-
}
55-
})
56-
).toEqual({ key: 'value', qux: 'baz' });
57-
});
58-
59-
it('does not apply override if invalid', () => {
60-
expect(
61-
invertObject({ foo: 'bar', baz: 'qux' }, (key) => {
62-
if (key === 'foo') {
63-
return ['key'];
64-
} else if (key === 'baz') {
65-
return { key: 'value' };
66-
}
67-
})
68-
).toEqual({ bar: 'foo', qux: 'baz' });
69-
});
70-
});
71-
});
72-
7310
describe('isCustomComponent', () => {
7411
it('returns true if the tag contains a hyphen and is not in the whitelist', () => {
7512
expect(isCustomComponent('my-custom-element')).toBe(true);

0 commit comments

Comments
 (0)