Comparing version 0.0.1 to 0.0.2
@@ -14,5 +14,24 @@ // gen-pasta.js | ||
function combine (returned, added) { | ||
Object.keys(added).forEach(function (key) { | ||
returned[key] = added[key] | ||
}) | ||
return returned | ||
} | ||
function last(item) { | ||
var num = false | ||
if (typeof item === 'number') return +item.toString().split('').pop() | ||
if (typeof item === 'string') return item.split('').pop() | ||
if (Array.isArray(item)) return item.pop() | ||
if (typeof item === 'object') return Object.keys(item).pop() | ||
return item | ||
} | ||
return { log: log | ||
, l: log | ||
, last:last | ||
, arrify: arrify | ||
, combine: combine | ||
} | ||
@@ -19,0 +38,0 @@ |
{ "name": "gen-pasta" | ||
, "version": "0.0.1" | ||
, "version": "0.0.2" | ||
, "author": "Nick Niemeir <nick.niemeir@gmail.com> (http://nrn.io)" | ||
@@ -4,0 +4,0 @@ , "main": "gen-pasta.js" |
@@ -5,3 +5,3 @@ var p = require('../gen-pasta')() | ||
test('General', function (t) { | ||
t.plan(2) | ||
t.plan(9) | ||
@@ -16,3 +16,19 @@ t.doesNotThrow(p.log, 'Log does not throw') | ||
) | ||
t.equal(p.last([1, 2, 3]), 3, 'Last element') | ||
t.equal(p.last({ c: 3, a: 1, b: 2}), 'b', 'Last key') | ||
t.equal(p.last('asdf'), 'f', 'Last character') | ||
t.equal(p.last(1234), 4, 'Last diget') | ||
var obj1 = { foo: 'bar'} | ||
var obj2 = { a: 42 } | ||
var combined = p.combine(obj1, obj2) | ||
t.equal(combined.a, 42, 'Combined') | ||
t.equal(combined, obj1, 'obj2 and combined reference the same obj') | ||
t.equal(obj2.foo, undefined, 'a stays the same') | ||
}) | ||
3349
54
15