diff --git a/src/lib/expect.js b/src/lib/expect.js index d1f2aa3..2c418a7 100644 --- a/src/lib/expect.js +++ b/src/lib/expect.js @@ -45,13 +45,13 @@ const expect = (thing, args) => get: function (obj, prop) { const toCheck = args ? thing(...args) : thing; if (prop.slice(0, 3) === 'not') - return check => + return (...check) => negateP( expects[ lowerCaseFirstLetter(prop.slice(3)) - ](toCheck)(check) + ](toCheck)(...check) ); - return check => expects[prop](toCheck)(check); + return (...check) => expects[prop](toCheck)(...check); }, }); diff --git a/src/util/index.js b/src/util/index.js index f76d690..91cb292 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -35,11 +35,17 @@ module.exports = { path => path.reduce((result, segment) => result && result[segment], obj), + /* Picks a key from an object */ + pick : key => obj => obj[key], + /* Pipe a value or promise through any number of unary functions */ pipe: (...fns) => arg => fns.reduce((acc, fn) => liftPromise(fn, acc), arg), + /* Reduces an array */ + reduce : (fn, def) => arr => arr.reduce(fn, def), + /* Flattens an array of arrays to an array */ flatten : arrData => [].concat.apply([], arrData), @@ -92,4 +98,26 @@ module.exports = { /* Fetches last element from list */ last : arr => arr[arr.length - 1], + /* Uppercases first letter of word */ + upperCaseFirstLetter : word => + word[0].toUpperCase() + + word.slice(1), + + /* Lowercases first letter of word */ + lowerCaseFirstLetter : word => + word[0].toLowerCase() + + word.slice(1), + + /* Creates an array or pushes to an existing one */ + arrayOrPush : (obj, key, item) => + Array.isArray(obj[key]) + ? obj[key].push(item) + : obj[key] = [item], + + /* Assigns to key or creates a new object */ + assignToObject : (obj, path) => (key, value) => + isObject(obj[path]) + ? obj[path][key] = value + : obj[path] = { [key]: value }, + };