Comparing version 0.5.1 to 0.5.2
@@ -44,17 +44,31 @@ /*global define*/ | ||
//A toString function to provide a slightly more meaningful representation of values. | ||
const toString = x => | ||
//A small string representing a value, but not containing the whole value. | ||
const preview = x => | ||
typeof x === 'string' | ||
? JSON.stringify(x) | ||
: Array.isArray(x) | ||
? `[${x.map(toString).join(', ')}]` | ||
? `[Array ${x.length}]` | ||
: typeof x === 'function' | ||
? typeof x.name === 'string' | ||
? `[Function ${x.name}]` | ||
: '[Function]' | ||
: x && x.toString === Object.prototype.toString | ||
? `{${Object.keys(x).map(String).join(', ')}}` | ||
: String(x); | ||
//A show function to provide a slightly more meaningful representation of values. | ||
const show = x => | ||
typeof x === 'string' | ||
? preview(x) | ||
: Array.isArray(x) | ||
? `[${x.map(preview).join(', ')}]` | ||
: x && (typeof x.toString === 'function') | ||
? x.toString === Object.prototype.toString | ||
? `{${Object.keys(x).reduce((o, k) => o.concat(`${toString(k)}: ${toString(x[k])}`), []).join(', ')}}` | ||
? `{${Object.keys(x).reduce((o, k) => o.concat(`${preview(k)}: ${preview(x[k])}`), []).join(', ')}}` | ||
: x.toString() | ||
: String(x); | ||
: preview(x); | ||
function error$invalidArgument(it, at, expected, actual){ | ||
throw new TypeError( | ||
`${it} expects argument ${at} to ${expected}\n Actual: ${toString(actual)}` | ||
`${it} expects argument ${at} to ${expected}\n Actual: ${show(actual)}` | ||
); | ||
@@ -66,3 +80,3 @@ } | ||
`${it} was invoked outside the context of a Future. You might want to use` | ||
+ ` a dispatcher instead\n Called on: ${toString(actual)}` | ||
+ ` a dispatcher instead\n Called on: ${show(actual)}` | ||
) | ||
@@ -89,3 +103,3 @@ } | ||
'Future#chain expects the function its given to return a Future' | ||
+ `\n Actual: ${toString(m)}\n From calling: ${toString(f)}\n With: ${toString(x)}` | ||
+ `\n Actual: ${show(m)}\n From calling: ${show(f)}\n With: ${show(x)}` | ||
); | ||
@@ -102,3 +116,3 @@ } | ||
'Future.chainRej expects the function its given to return a Future' | ||
+ `\n Actual: ${toString(m)}\n From calling: ${toString(f)}\n With: ${toString(x)}` | ||
+ `\n Actual: ${show(m)}\n From calling: ${show(f)}\n With: ${show(x)}` | ||
); | ||
@@ -120,3 +134,3 @@ } | ||
if(!isFunction(f)) throw new TypeError( | ||
`Future#ap can only b used on Future<Function> but was used on: ${toString(f)}` | ||
`Future#ap can only b used on Future<Function> but was used on: ${show(f)}` | ||
); | ||
@@ -150,4 +164,4 @@ } | ||
+ ' Please check your cached Future and make sure it does not call res or rej multiple times' | ||
+ '\n It was ' + (oldState === 2 ? 'rejected' : 'resolved') + ' with: ' + toString(oldValue) | ||
+ '\n It got ' + (newState === 2 ? 'rejected' : 'resolved') + ' with: ' + toString(newValue) | ||
+ '\n It was ' + (oldState === 2 ? 'rejected' : 'resolved') + ' with: ' + show(oldValue) | ||
+ '\n It got ' + (newState === 2 ? 'rejected' : 'resolved') + ' with: ' + show(newValue) | ||
); | ||
@@ -176,3 +190,3 @@ } | ||
'Future.parallel expects argument 1 to be an array of Futures.' | ||
+ ` The value at position ${i} in the array was not a Future.\n Actual: ${toString(m)}` | ||
+ ` The value at position ${i} in the array was not a Future.\n Actual: ${show(m)}` | ||
); | ||
@@ -262,3 +276,3 @@ } | ||
function Future$toString(){ | ||
return `Future(${toString(this._f)})`; | ||
return `Future(${show(this._f)})`; | ||
} | ||
@@ -290,3 +304,3 @@ | ||
throw new Error( | ||
`Future#value was called on a rejected Future\n Actual: Future.reject(${toString(e)})` | ||
`Future#value was called on a rejected Future\n Actual: Future.reject(${show(e)})` | ||
); | ||
@@ -293,0 +307,0 @@ }, |
{ | ||
"name": "fluture", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "A complete Fantasy Land compatible Future library", | ||
@@ -5,0 +5,0 @@ "main": "fluture.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27437
403