Browse Source

[expect] Minor fix, added utils

0.7.0-breaking-rewrite
Muthu Kumar 6 years ago
parent
commit
8f4fa925a0
  1. 6
      src/lib/expect.js
  2. 28
      src/util/index.js

6
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);
},
});

28
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 },
};

Loading…
Cancel
Save