Skip to content

Commit e335520

Browse files
committed
deadcode elimination
1 parent 2a8c9d6 commit e335520

File tree

3 files changed

+2
-60
lines changed

3 files changed

+2
-60
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
"debug": "^2.2.0",
1111
"generic-names": "^1.0.0-beta",
1212
"icss-replace-symbols": "^1.0.2",
13-
"lodash.assign": "^3.2.0",
1413
"lodash.foreach": "^3.0.3",
1514
"lodash.identity": "^3.0.0",
1615
"lodash.isarray": "^3.0.4",
1716
"lodash.isfunction": "^3.0.6",
18-
"lodash.isstring": "^3.0.1",
19-
"lodash.pick": "^3.1.0"
17+
"lodash.isstring": "^3.0.1"
2018
},
2119
"devDependencies": {
2220
"babel": "^5.8.20",

src/utility.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,13 @@
11
import isArray from 'lodash.isarray';
22
import isFunction from 'lodash.isfunction';
33
import isString from 'lodash.isstring';
4-
import { format } from 'util';
54

65
const check = {
76
'array': isArray,
87
'function': isFunction,
98
'string': isString,
109
};
1110

12-
/**
13-
* @param {string} prop
14-
* @param {string[]} aliases
15-
* @param {string} type
16-
* @param {object} source
17-
* @return {*}
18-
*/
19-
export function get(prop, aliases, type, source) {
20-
if (source[prop]) {
21-
if (isArray(type)) {
22-
if (type.some(tp => is(tp, source[prop]))) {
23-
return source[prop];
24-
}
25-
26-
throw new Error(format('should specify %s for %s', type.join('|'), prop));
27-
}
28-
29-
if (!is(type, source[prop])) {
30-
throw new Error(format('should specify %s for %s', type, prop));
31-
}
32-
33-
return source[prop];
34-
}
35-
36-
if (!isArray(aliases)) {
37-
return null;
38-
}
39-
40-
let deprecatedProp;
41-
const match = aliases.some(alias => Boolean(source[(deprecatedProp = alias)]));
42-
43-
if (match) {
44-
if (!is(type, source[deprecatedProp])) {
45-
throw new Error(format('should specify %s for %s', type, deprecatedProp));
46-
}
47-
48-
// deprecated message
49-
return source[deprecatedProp];
50-
}
51-
52-
return null;
53-
}
54-
5511
/**
5612
* @param {string} type
5713
* @param {*} value

test/utility.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
import { ok, equal, throws } from 'assert';
2-
import { get, is, removeQuotes } from '../src/utility';
2+
import { is, removeQuotes } from '../src/utility';
33

44
describe('utility', () => {
5-
describe('get()', () => {
6-
it('should return value for an existing property', () => equal(get('a', null, 'string', {a: 'val'}), 'val'));
7-
8-
it('should return value for an existing alias', () => equal(get('a', ['b'], 'string', {b: 'val'}), 'val'));
9-
10-
it('should return null for a non-existing property', () => equal(get('a', null, 'array', {}), null));
11-
12-
it('should throw an error for the specified key with wrong type of value', () => {
13-
throws(() => get('a', null, 'string', {a: 5}));
14-
});
15-
});
16-
175
describe('is()', () => {
186
it('should return true for an array', () => ok(is('array', [])));
197

0 commit comments

Comments
 (0)