simple-protocol-helpers
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -81,2 +81,16 @@ 'use strict'; | ||
var clean = function clean(s) { | ||
if (hasPayload(s)) { | ||
return { | ||
success: s.success, | ||
payload: s.payload | ||
}; | ||
} else if (hasError(s)) { | ||
return { | ||
success: s.success, | ||
error: s.error | ||
}; | ||
} | ||
}; | ||
module.exports = { | ||
@@ -94,4 +108,5 @@ getSuccesses: getSuccesses, | ||
isProtocol: isProtocol, | ||
errorToObject: errorToObject | ||
errorToObject: errorToObject, | ||
clean: clean | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -17,3 +17,4 @@ 'use strict'; | ||
failure = _require2.failure, | ||
isProtocol = _require2.isProtocol; | ||
isProtocol = _require2.isProtocol, | ||
clean = _require2.clean; | ||
@@ -236,3 +237,27 @@ describe('index.js', function () { | ||
}); | ||
describe('clean()', function () { | ||
it('should clean a success', function () { | ||
var s = success(1); | ||
s.meta = { foo: 'bar' }; | ||
var actual = clean(s); | ||
var expected = { | ||
success: true, | ||
payload: 1 | ||
}; | ||
deepEqual(actual, expected); | ||
}); | ||
it('should clean a failure', function () { | ||
var s = failure(1); | ||
s.meta = { foo: 'bar' }; | ||
var actual = clean(s); | ||
var expected = { | ||
success: false, | ||
error: 1 | ||
}; | ||
deepEqual(actual, expected); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=index.spec.js.map |
{ | ||
"name": "simple-protocol-helpers", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A small library for using simple protocol", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -51,2 +51,16 @@ const isSuccess = p => p.success === true | ||
const clean = (s) => { | ||
if (hasPayload(s)) { | ||
return { | ||
success: s.success, | ||
payload: s.payload | ||
} | ||
} else if (hasError(s)) { | ||
return { | ||
success: s.success, | ||
error: s.error | ||
} | ||
} | ||
} | ||
module.exports = { | ||
@@ -64,3 +78,4 @@ getSuccesses, | ||
isProtocol, | ||
errorToObject | ||
errorToObject, | ||
clean | ||
} |
@@ -13,3 +13,4 @@ const { deepEqual } = require('assert') | ||
failure, | ||
isProtocol | ||
isProtocol, | ||
clean | ||
} = require('./index') | ||
@@ -233,2 +234,26 @@ | ||
}) | ||
describe('clean()', () => { | ||
it('should clean a success', () => { | ||
const s = success(1) | ||
s.meta = { foo: 'bar' } | ||
const actual = clean(s) | ||
const expected = { | ||
success: true, | ||
payload: 1 | ||
} | ||
deepEqual(actual, expected) | ||
}) | ||
it('should clean a failure', () => { | ||
const s = failure(1) | ||
s.meta = { foo: 'bar' } | ||
const actual = clean(s) | ||
const expected = { | ||
success: false, | ||
error: 1 | ||
} | ||
deepEqual(actual, expected) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
37923
630