Skip to content

Commit

Permalink
Drive out a fresh impl of initialize-names
Browse files Browse the repository at this point in the history
Turns out most of the logic was pretty dumb and it's new behavior so I
just axed most of it
  • Loading branch information
searls committed Jun 24, 2017
1 parent c0e8b21 commit 37ccdc8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/imitate/initialize-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import _ from '../wrap/lodash'

export default (original, names) => {
if (names != null) return names
if (_.isArray(original) || _.isArguments(original)) {
return []
} else if (_.isFunction(original)) {
if (_.isFunction(original) && original.name) {
return [original.name]
} else {
let name = _.get(original, 'name') || _.invoke(original, 'toString') || ''
if (name === ({}).toString()) {
name = ''
}
return [name]
return []
}
}
23 changes: 23 additions & 0 deletions test/unit/imitate/initialize-names.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import subject from '../../../src/imitate/initialize-names'

module.exports = {
'passed a non-null names': () => {
assert.equal(subject(null, 'foo'), 'foo')
},
'an array type': () => {
assert.deepEqual(subject(['lol']), [])
},
'an arguments type': () => {
let args = (function () { return arguments })(1,2,3)
assert.deepEqual(subject(args), [])
},
'an anon function': () => {
assert.deepEqual(subject(function () {}), [])
},
'a named function': () => {
assert.deepEqual(subject(function blah () {}), ['blah'])
},
'a plain object': () => {
assert.deepEqual(subject({}), [])
}
}

0 comments on commit 37ccdc8

Please sign in to comment.