Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

return-style

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

return-style - npm Package Compare versions

Comparing version 0.11.0 to 0.11.2

14

CHANGELOG.md

@@ -5,2 +5,16 @@ # Changelog

### [0.11.2](https://github.com/BlackGlory/return-style/compare/v0.11.1...v0.11.2) (2021-01-04)
### Bug Fixes
* build ([4ce48ec](https://github.com/BlackGlory/return-style/commit/4ce48ecaaadef37e55f6338ec00e8bca7fe8ffca))
### [0.11.1](https://github.com/BlackGlory/return-style/compare/v0.11.0...v0.11.1) (2021-01-04)
### Features
* add PromiseLike interface for AsyncResult and AsyncOptional ([c74ce37](https://github.com/BlackGlory/return-style/commit/c74ce377aec5e738a1b9bdc98f43c1337868b85c))
## [0.11.0](https://github.com/BlackGlory/return-style/compare/v0.10.1...v0.11.0) (2021-01-04)

@@ -7,0 +21,0 @@

@@ -459,2 +459,6 @@ (function (global, factory) {

}
get then() {
const promise = __classPrivateFieldGet(this, _promise).then(x => Result.Ok(x), x => Result.Err(x));
return promise.then.bind(promise);
}
onOk(callback) {

@@ -650,2 +654,8 @@ (() => __awaiter(this, void 0, void 0, function* () {

}
get then() {
const promise = __classPrivateFieldGet(this, _promise$1).then(x => x === Nil
? Optional.None()
: Optional.Some(x));
return promise.then.bind(promise);
}
onSome(callback) {

@@ -652,0 +662,0 @@ (() => __awaiter(this, void 0, void 0, function* () {

2

dist/es2015/index.umd.min.js

@@ -16,3 +16,3 @@ !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).ReturnStyle={})}(this,(function(t){"use strict";

***************************************************************************** */
function r(t,r,n,e){return new(n||(n=Promise))((function(i,o){function u(t){try{c(e.next(t))}catch(t){o(t)}}function s(t){try{c(e.throw(t))}catch(t){o(t)}}function c(t){var r;t.done?i(t.value):(r=t.value,r instanceof n?r:new n((function(t){t(r)}))).then(u,s)}c((e=e.apply(t,r||[])).next())}))}function n(t){var r="function"==typeof Symbol&&Symbol.iterator,n=r&&t[r],e=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function e(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,e=t[Symbol.asyncIterator];return e?e.call(t):(t=n(t),r={},i("next"),i("throw"),i("return"),r[Symbol.asyncIterator]=function(){return this},r);function i(n){r[n]=t[n]&&function(r){return new Promise((function(e,i){(function(t,r,n,e){Promise.resolve(e).then((function(r){t({value:r,done:n})}),r)})(e,i,(r=t[n](r)).done,r.value)}))}}}function i(t,r){if(!r.has(t))throw new TypeError("attempted to get private field on non-instance");return r.get(t)}function o(t,r,n){if(!r.has(t))throw new TypeError("attempted to set private field on non-instance");return r.set(t,n),n}function u(t){return r(this,void 0,void 0,(function*(){try{return[!0,yield t]}catch(t){return[!1,void 0]}}))}function s(t){return r(this,void 0,void 0,(function*(){try{return yield t,[!1,void 0]}catch(t){return[!0,t]}}))}function c(t){return r(this,void 0,void 0,(function*(){try{return yield t,!0}catch(t){return!1}}))}function d(t){return r(this,void 0,void 0,(function*(){try{return yield t,!1}catch(t){return!0}}))}var f,a,h,l,v;class y{static Ok(t){return m.of(t)}static Err(t){return w.of(t)}}class m extends y{constructor(t){super(),f.set(this,void 0),o(this,f,t)}static of(t){return new m(t)}isOk(){return!0}isErr(){return!1}onOk(t){return t(i(this,f)),m.of(i(this,f))}onErr(){return m.of(i(this,f))}orElse(){return m.of(i(this,f))}map(t){return m.of(t(i(this,f)))}get(){return i(this,f)}}f=new WeakMap;class w extends y{constructor(t){super(),a.set(this,void 0),o(this,a,t)}static of(t){return new w(t)}isOk(){return!1}isErr(){return!0}onOk(){return w.of(i(this,a))}onErr(t){return t(i(this,a)),w.of(i(this,a))}orElse(t){return m.of(t)}map(){return w.of(i(this,a))}get(){throw i(this,a)}}a=new WeakMap;class p{constructor(t){h.set(this,void 0),o(this,h,t)}static Ok(t){return g.of(t)}static Err(t){return E.of(t)}onOk(t){return(()=>{r(this,void 0,void 0,(function*(){const[r,n]=yield u(i(this,h));r&&t(n)}))})(),new p(i(this,h))}onErr(t){return(()=>{r(this,void 0,void 0,(function*(){const[r,n]=yield s(i(this,h));r&&t(n)}))})(),new p(i(this,h))}isOk(){return r(this,void 0,void 0,(function*(){return yield c(i(this,h))}))}isErr(){return r(this,void 0,void 0,(function*(){return yield d(i(this,h))}))}orElse(t){return new p((()=>r(this,void 0,void 0,(function*(){try{return yield i(this,h)}catch(r){return t}})))())}map(t){return new p((()=>r(this,void 0,void 0,(function*(){const r=yield i(this,h);return t(r)})))())}get(){return r(this,void 0,void 0,(function*(){return yield i(this,h)}))}}h=new WeakMap;class g extends p{static of(t){return new g(t)}constructor(t){super(Promise.resolve(t))}}class E extends p{static of(t){return new E(t)}constructor(t){super(Promise.reject(t))}}class S{static Some(t){return P.of(t)}static None(){return b.of()}}class P extends S{constructor(t){super(),l.set(this,void 0),o(this,l,t)}static of(t){return new P(t)}isSome(){return!0}isNone(){return!1}onSome(t){return t(i(this,l)),P.of(i(this,l))}onNone(){return P.of(i(this,l))}orElse(){return P.of(i(this,l))}map(t){return P.of(t(i(this,l)))}filter(t){return t(i(this,l))?P.of(i(this,l)):b.of()}get(){return i(this,l)}}l=new WeakMap;class b extends S{static of(){return new b}constructor(){super()}isSome(){return!1}isNone(){return!0}onSome(){return b.of()}onNone(t){return t(),b.of()}orElse(t){return P.of(t)}map(){return b.of()}filter(){return b.of()}get(){throw new Error("Cannot get value from None")}}function x(t,r){const n=t();return r(n)?S.None():S.Some(n)}const O=Symbol();class k{constructor(t){v.set(this,void 0),o(this,v,t)}static Some(t){return N.of(t)}static None(){return R.of()}onSome(t){return(()=>{r(this,void 0,void 0,(function*(){const r=yield i(this,v);r!==O&&t(r)}))})(),new k(i(this,v))}onNone(t){return(()=>{r(this,void 0,void 0,(function*(){(yield i(this,v))===O&&t()}))})(),new k(i(this,v))}isSome(){return r(this,void 0,void 0,(function*(){return(yield i(this,v))!==O}))}isNone(){return r(this,void 0,void 0,(function*(){return(yield i(this,v))===O}))}orElse(t){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield i(this,v);return r===O?t:r})))())}map(t){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield i(this,v);return r===O?O:t(r)})))())}filter(t){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield i(this,v);return r===O?O:t(r)?r:O})))())}get(){return r(this,void 0,void 0,(function*(){const t=yield i(this,v);if(t===O)throw new Error("Cannot get value from None");return t}))}}v=new WeakMap;class R extends k{static of(){return new R}constructor(){super(Promise.resolve(O))}}class N extends k{static of(t){return new N(t)}constructor(t){super(Promise.resolve(t))}}function A(t,n){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield t;return n(r)?O:r})))())}t.getError=function(t){try{t()}catch(t){return t}},t.getErrorAsync=function(t){return r(this,void 0,void 0,(function*(){try{yield t()}catch(t){return t}}))},t.getErrorAsyncIterable=function(t){var n,i,o,u;return r(this,void 0,void 0,(function*(){try{try{for(n=e(t);!(i=yield n.next()).done;){i.value}}catch(t){o={error:t}}finally{try{i&&!i.done&&(u=n.return)&&(yield u.call(n))}finally{if(o)throw o.error}}}catch(t){return t}}))},t.getErrorPromise=function(t){return r(this,void 0,void 0,(function*(){try{yield t}catch(t){return t}}))},t.getErrorResult=function(t){try{return[void 0,t()]}catch(t){return[t,void 0]}},t.getErrorResultAsync=function(t){return r(this,void 0,void 0,(function*(){try{return[void 0,yield t()]}catch(t){return[t,void 0]}}))},t.getErrorResultPromise=function(t){return r(this,void 0,void 0,(function*(){try{return[void 0,yield t]}catch(t){return[t,void 0]}}))},t.getFailure=function(t){try{return t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailureAsync=function(t){return r(this,void 0,void 0,(function*(){try{return yield t(),[!1,void 0]}catch(t){return[!0,t]}}))},t.getFailurePromise=s,t.getResult=function(t){try{return t()}catch(t){return}},t.getResultAsync=function(t){return r(this,void 0,void 0,(function*(){try{return yield t()}catch(t){return}}))},t.getResultError=function(t){try{return[t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorAsync=function(t){return r(this,void 0,void 0,(function*(){try{return[yield t(),void 0]}catch(t){return[void 0,t]}}))},t.getResultErrorPromise=function(t){return r(this,void 0,void 0,(function*(){try{return[yield t,void 0]}catch(t){return[void 0,t]}}))},t.getResultPromise=function(t){return r(this,void 0,void 0,(function*(){try{return yield t}catch(t){return}}))},t.getSuccess=function(t){try{return[!0,t()]}catch(t){return[!1,void 0]}},t.getSuccessAsync=function(t){return r(this,void 0,void 0,(function*(){try{return[!0,yield t()]}catch(t){return[!1,void 0]}}))},t.getSuccessPromise=u,t.isFailure=function(t){try{return t(),!1}catch(t){return!0}},t.isFailureAsync=function(t){return r(this,void 0,void 0,(function*(){try{return yield t(),!1}catch(t){return!0}}))},t.isFailurePromise=d,t.isSuccess=function(t){try{return t(),!0}catch(t){return!1}},t.isSuccessAsync=function(t){return r(this,void 0,void 0,(function*(){try{return yield t(),!0}catch(t){return!1}}))},t.isSuccessPromise=c,t.toOptional=x,t.toOptionalPartial=function(t){return r=>x(r,t)},t.toOptionalPromise=A,t.toOptionalPromisePartial=function(t){return r=>A(r,t)},t.toResult=function(t){try{const r=t();return y.Ok(r)}catch(t){return y.Err(t)}},t.toResultAsync=function(t){try{const r=t();return new p(r)}catch(t){return p.Err(t)}},t.toResultPromise=function(t){return new p(t)},Object.defineProperty(t,"__esModule",{value:!0})}));
function r(t,r,n,e){return new(n||(n=Promise))((function(i,o){function u(t){try{c(e.next(t))}catch(t){o(t)}}function s(t){try{c(e.throw(t))}catch(t){o(t)}}function c(t){var r;t.done?i(t.value):(r=t.value,r instanceof n?r:new n((function(t){t(r)}))).then(u,s)}c((e=e.apply(t,r||[])).next())}))}function n(t){var r="function"==typeof Symbol&&Symbol.iterator,n=r&&t[r],e=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function e(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,e=t[Symbol.asyncIterator];return e?e.call(t):(t=n(t),r={},i("next"),i("throw"),i("return"),r[Symbol.asyncIterator]=function(){return this},r);function i(n){r[n]=t[n]&&function(r){return new Promise((function(e,i){(function(t,r,n,e){Promise.resolve(e).then((function(r){t({value:r,done:n})}),r)})(e,i,(r=t[n](r)).done,r.value)}))}}}function i(t,r){if(!r.has(t))throw new TypeError("attempted to get private field on non-instance");return r.get(t)}function o(t,r,n){if(!r.has(t))throw new TypeError("attempted to set private field on non-instance");return r.set(t,n),n}function u(t){return r(this,void 0,void 0,(function*(){try{return[!0,yield t]}catch(t){return[!1,void 0]}}))}function s(t){return r(this,void 0,void 0,(function*(){try{return yield t,[!1,void 0]}catch(t){return[!0,t]}}))}function c(t){return r(this,void 0,void 0,(function*(){try{return yield t,!0}catch(t){return!1}}))}function d(t){return r(this,void 0,void 0,(function*(){try{return yield t,!1}catch(t){return!0}}))}var f,h,a,l,v;class y{static Ok(t){return m.of(t)}static Err(t){return w.of(t)}}class m extends y{constructor(t){super(),f.set(this,void 0),o(this,f,t)}static of(t){return new m(t)}isOk(){return!0}isErr(){return!1}onOk(t){return t(i(this,f)),m.of(i(this,f))}onErr(){return m.of(i(this,f))}orElse(){return m.of(i(this,f))}map(t){return m.of(t(i(this,f)))}get(){return i(this,f)}}f=new WeakMap;class w extends y{constructor(t){super(),h.set(this,void 0),o(this,h,t)}static of(t){return new w(t)}isOk(){return!1}isErr(){return!0}onOk(){return w.of(i(this,h))}onErr(t){return t(i(this,h)),w.of(i(this,h))}orElse(t){return m.of(t)}map(){return w.of(i(this,h))}get(){throw i(this,h)}}h=new WeakMap;class p{constructor(t){a.set(this,void 0),o(this,a,t)}static Ok(t){return g.of(t)}static Err(t){return E.of(t)}get then(){const t=i(this,a).then(t=>y.Ok(t),t=>y.Err(t));return t.then.bind(t)}onOk(t){return(()=>{r(this,void 0,void 0,(function*(){const[r,n]=yield u(i(this,a));r&&t(n)}))})(),new p(i(this,a))}onErr(t){return(()=>{r(this,void 0,void 0,(function*(){const[r,n]=yield s(i(this,a));r&&t(n)}))})(),new p(i(this,a))}isOk(){return r(this,void 0,void 0,(function*(){return yield c(i(this,a))}))}isErr(){return r(this,void 0,void 0,(function*(){return yield d(i(this,a))}))}orElse(t){return new p((()=>r(this,void 0,void 0,(function*(){try{return yield i(this,a)}catch(r){return t}})))())}map(t){return new p((()=>r(this,void 0,void 0,(function*(){const r=yield i(this,a);return t(r)})))())}get(){return r(this,void 0,void 0,(function*(){return yield i(this,a)}))}}a=new WeakMap;class g extends p{static of(t){return new g(t)}constructor(t){super(Promise.resolve(t))}}class E extends p{static of(t){return new E(t)}constructor(t){super(Promise.reject(t))}}class S{static Some(t){return P.of(t)}static None(){return b.of()}}class P extends S{constructor(t){super(),l.set(this,void 0),o(this,l,t)}static of(t){return new P(t)}isSome(){return!0}isNone(){return!1}onSome(t){return t(i(this,l)),P.of(i(this,l))}onNone(){return P.of(i(this,l))}orElse(){return P.of(i(this,l))}map(t){return P.of(t(i(this,l)))}filter(t){return t(i(this,l))?P.of(i(this,l)):b.of()}get(){return i(this,l)}}l=new WeakMap;class b extends S{static of(){return new b}constructor(){super()}isSome(){return!1}isNone(){return!0}onSome(){return b.of()}onNone(t){return t(),b.of()}orElse(t){return P.of(t)}map(){return b.of()}filter(){return b.of()}get(){throw new Error("Cannot get value from None")}}function x(t,r){const n=t();return r(n)?S.None():S.Some(n)}const O=Symbol();class k{constructor(t){v.set(this,void 0),o(this,v,t)}static Some(t){return N.of(t)}static None(){return R.of()}get then(){const t=i(this,v).then(t=>t===O?S.None():S.Some(t));return t.then.bind(t)}onSome(t){return(()=>{r(this,void 0,void 0,(function*(){const r=yield i(this,v);r!==O&&t(r)}))})(),new k(i(this,v))}onNone(t){return(()=>{r(this,void 0,void 0,(function*(){(yield i(this,v))===O&&t()}))})(),new k(i(this,v))}isSome(){return r(this,void 0,void 0,(function*(){return(yield i(this,v))!==O}))}isNone(){return r(this,void 0,void 0,(function*(){return(yield i(this,v))===O}))}orElse(t){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield i(this,v);return r===O?t:r})))())}map(t){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield i(this,v);return r===O?O:t(r)})))())}filter(t){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield i(this,v);return r===O?O:t(r)?r:O})))())}get(){return r(this,void 0,void 0,(function*(){const t=yield i(this,v);if(t===O)throw new Error("Cannot get value from None");return t}))}}v=new WeakMap;class R extends k{static of(){return new R}constructor(){super(Promise.resolve(O))}}class N extends k{static of(t){return new N(t)}constructor(t){super(Promise.resolve(t))}}function A(t,n){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield t;return n(r)?O:r})))())}t.getError=function(t){try{t()}catch(t){return t}},t.getErrorAsync=function(t){return r(this,void 0,void 0,(function*(){try{yield t()}catch(t){return t}}))},t.getErrorAsyncIterable=function(t){var n,i,o,u;return r(this,void 0,void 0,(function*(){try{try{for(n=e(t);!(i=yield n.next()).done;){i.value}}catch(t){o={error:t}}finally{try{i&&!i.done&&(u=n.return)&&(yield u.call(n))}finally{if(o)throw o.error}}}catch(t){return t}}))},t.getErrorPromise=function(t){return r(this,void 0,void 0,(function*(){try{yield t}catch(t){return t}}))},t.getErrorResult=function(t){try{return[void 0,t()]}catch(t){return[t,void 0]}},t.getErrorResultAsync=function(t){return r(this,void 0,void 0,(function*(){try{return[void 0,yield t()]}catch(t){return[t,void 0]}}))},t.getErrorResultPromise=function(t){return r(this,void 0,void 0,(function*(){try{return[void 0,yield t]}catch(t){return[t,void 0]}}))},t.getFailure=function(t){try{return t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailureAsync=function(t){return r(this,void 0,void 0,(function*(){try{return yield t(),[!1,void 0]}catch(t){return[!0,t]}}))},t.getFailurePromise=s,t.getResult=function(t){try{return t()}catch(t){return}},t.getResultAsync=function(t){return r(this,void 0,void 0,(function*(){try{return yield t()}catch(t){return}}))},t.getResultError=function(t){try{return[t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorAsync=function(t){return r(this,void 0,void 0,(function*(){try{return[yield t(),void 0]}catch(t){return[void 0,t]}}))},t.getResultErrorPromise=function(t){return r(this,void 0,void 0,(function*(){try{return[yield t,void 0]}catch(t){return[void 0,t]}}))},t.getResultPromise=function(t){return r(this,void 0,void 0,(function*(){try{return yield t}catch(t){return}}))},t.getSuccess=function(t){try{return[!0,t()]}catch(t){return[!1,void 0]}},t.getSuccessAsync=function(t){return r(this,void 0,void 0,(function*(){try{return[!0,yield t()]}catch(t){return[!1,void 0]}}))},t.getSuccessPromise=u,t.isFailure=function(t){try{return t(),!1}catch(t){return!0}},t.isFailureAsync=function(t){return r(this,void 0,void 0,(function*(){try{return yield t(),!1}catch(t){return!0}}))},t.isFailurePromise=d,t.isSuccess=function(t){try{return t(),!0}catch(t){return!1}},t.isSuccessAsync=function(t){return r(this,void 0,void 0,(function*(){try{return yield t(),!0}catch(t){return!1}}))},t.isSuccessPromise=c,t.toOptional=x,t.toOptionalPartial=function(t){return r=>x(r,t)},t.toOptionalPromise=A,t.toOptionalPromisePartial=function(t){return r=>A(r,t)},t.toResult=function(t){try{const r=t();return y.Ok(r)}catch(t){return y.Err(t)}},t.toResultAsync=function(t){try{const r=t();return new p(r)}catch(t){return p.Err(t)}},t.toResultPromise=function(t){return new p(t)},Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.min.js.map

@@ -382,2 +382,6 @@ (function (global, factory) {

}
get then() {
const promise = __classPrivateFieldGet(this, _promise).then(x => Result.Ok(x), x => Result.Err(x));
return promise.then.bind(promise);
}
onOk(callback) {

@@ -567,2 +571,8 @@ (async () => {

}
get then() {
const promise = __classPrivateFieldGet(this, _promise$1).then(x => x === Nil
? Optional.None()
: Optional.Some(x));
return promise.then.bind(promise);
}
onSome(callback) {

@@ -569,0 +579,0 @@ (async () => {

@@ -16,3 +16,3 @@ !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).ReturnStyle={})}(this,(function(t){"use strict";async function r(t){try{return[!0,await t]}catch(t){return[!1,void 0]}}async function n(t){try{return await t,[!1,void 0]}catch(t){return[!0,t]}}async function e(t){try{return await t,!0}catch(t){return!1}}async function s(t){try{return await t,!1}catch(t){return!0}}

***************************************************************************** */
function o(t,r){if(!r.has(t))throw new TypeError("attempted to get private field on non-instance");return r.get(t)}function i(t,r,n){if(!r.has(t))throw new TypeError("attempted to set private field on non-instance");return r.set(t,n),n}var c,u,a,f,h;class y{static Ok(t){return w.of(t)}static Err(t){return l.of(t)}}class w extends y{constructor(t){super(),c.set(this,void 0),i(this,c,t)}static of(t){return new w(t)}isOk(){return!0}isErr(){return!1}onOk(t){return t(o(this,c)),w.of(o(this,c))}onErr(){return w.of(o(this,c))}orElse(){return w.of(o(this,c))}map(t){return w.of(t(o(this,c)))}get(){return o(this,c)}}c=new WeakMap;class l extends y{constructor(t){super(),u.set(this,void 0),i(this,u,t)}static of(t){return new l(t)}isOk(){return!1}isErr(){return!0}onOk(){return l.of(o(this,u))}onErr(t){return t(o(this,u)),l.of(o(this,u))}orElse(t){return w.of(t)}map(){return l.of(o(this,u))}get(){throw o(this,u)}}u=new WeakMap;class d{constructor(t){a.set(this,void 0),i(this,a,t)}static Ok(t){return m.of(t)}static Err(t){return p.of(t)}onOk(t){return(async()=>{const[n,e]=await r(o(this,a));n&&t(e)})(),new d(o(this,a))}onErr(t){return(async()=>{const[r,e]=await n(o(this,a));r&&t(e)})(),new d(o(this,a))}async isOk(){return await e(o(this,a))}async isErr(){return await s(o(this,a))}orElse(t){return new d((async()=>{try{return await o(this,a)}catch(r){return t}})())}map(t){return new d((async()=>{const r=await o(this,a);return t(r)})())}async get(){return await o(this,a)}}a=new WeakMap;class m extends d{static of(t){return new m(t)}constructor(t){super(Promise.resolve(t))}}class p extends d{static of(t){return new p(t)}constructor(t){super(Promise.reject(t))}}class v{static Some(t){return g.of(t)}static None(){return E.of()}}class g extends v{constructor(t){super(),f.set(this,void 0),i(this,f,t)}static of(t){return new g(t)}isSome(){return!0}isNone(){return!1}onSome(t){return t(o(this,f)),g.of(o(this,f))}onNone(){return g.of(o(this,f))}orElse(){return g.of(o(this,f))}map(t){return g.of(t(o(this,f)))}filter(t){return t(o(this,f))?g.of(o(this,f)):E.of()}get(){return o(this,f)}}f=new WeakMap;class E extends v{static of(){return new E}constructor(){super()}isSome(){return!1}isNone(){return!0}onSome(){return E.of()}onNone(t){return t(),E.of()}orElse(t){return g.of(t)}map(){return E.of()}filter(){return E.of()}get(){throw new Error("Cannot get value from None")}}function P(t,r){const n=t();return r(n)?v.None():v.Some(n)}const S=Symbol();class k{constructor(t){h.set(this,void 0),i(this,h,t)}static Some(t){return R.of(t)}static None(){return O.of()}onSome(t){return(async()=>{const r=await o(this,h);r!==S&&t(r)})(),new k(o(this,h))}onNone(t){return(async()=>{await o(this,h)===S&&t()})(),new k(o(this,h))}async isSome(){return await o(this,h)!==S}async isNone(){return await o(this,h)===S}orElse(t){return new k((async()=>{const r=await o(this,h);return r===S?t:r})())}map(t){return new k((async()=>{const r=await o(this,h);return r===S?S:t(r)})())}filter(t){return new k((async()=>{const r=await o(this,h);return r===S?S:t(r)?r:S})())}async get(){const t=await o(this,h);if(t===S)throw new Error("Cannot get value from None");return t}}h=new WeakMap;class O extends k{static of(){return new O}constructor(){super(Promise.resolve(S))}}class R extends k{static of(t){return new R(t)}constructor(t){super(Promise.resolve(t))}}function x(t,r){return new k((async()=>{const n=await t;return r(n)?S:n})())}t.getError=function(t){try{t()}catch(t){return t}},t.getErrorAsync=async function(t){try{await t()}catch(t){return t}},t.getErrorAsyncIterable=async function(t){try{for await(const r of t);}catch(t){return t}},t.getErrorPromise=async function(t){try{await t}catch(t){return t}},t.getErrorResult=function(t){try{return[void 0,t()]}catch(t){return[t,void 0]}},t.getErrorResultAsync=async function(t){try{return[void 0,await t()]}catch(t){return[t,void 0]}},t.getErrorResultPromise=async function(t){try{return[void 0,await t]}catch(t){return[t,void 0]}},t.getFailure=function(t){try{return t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailureAsync=async function(t){try{return await t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailurePromise=n,t.getResult=function(t){try{return t()}catch(t){return}},t.getResultAsync=async function(t){try{return await t()}catch(t){return}},t.getResultError=function(t){try{return[t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorAsync=async function(t){try{return[await t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorPromise=async function(t){try{return[await t,void 0]}catch(t){return[void 0,t]}},t.getResultPromise=async function(t){try{return await t}catch(t){return}},t.getSuccess=function(t){try{return[!0,t()]}catch(t){return[!1,void 0]}},t.getSuccessAsync=async function(t){try{return[!0,await t()]}catch(t){return[!1,void 0]}},t.getSuccessPromise=r,t.isFailure=function(t){try{return t(),!1}catch(t){return!0}},t.isFailureAsync=async function(t){try{return await t(),!1}catch(t){return!0}},t.isFailurePromise=s,t.isSuccess=function(t){try{return t(),!0}catch(t){return!1}},t.isSuccessAsync=async function(t){try{return await t(),!0}catch(t){return!1}},t.isSuccessPromise=e,t.toOptional=P,t.toOptionalPartial=function(t){return r=>P(r,t)},t.toOptionalPromise=x,t.toOptionalPromisePartial=function(t){return r=>x(r,t)},t.toResult=function(t){try{const r=t();return y.Ok(r)}catch(t){return y.Err(t)}},t.toResultAsync=function(t){try{const r=t();return new d(r)}catch(t){return d.Err(t)}},t.toResultPromise=function(t){return new d(t)},Object.defineProperty(t,"__esModule",{value:!0})}));
function o(t,r){if(!r.has(t))throw new TypeError("attempted to get private field on non-instance");return r.get(t)}function i(t,r,n){if(!r.has(t))throw new TypeError("attempted to set private field on non-instance");return r.set(t,n),n}var c,u,a,f,h;class y{static Ok(t){return w.of(t)}static Err(t){return l.of(t)}}class w extends y{constructor(t){super(),c.set(this,void 0),i(this,c,t)}static of(t){return new w(t)}isOk(){return!0}isErr(){return!1}onOk(t){return t(o(this,c)),w.of(o(this,c))}onErr(){return w.of(o(this,c))}orElse(){return w.of(o(this,c))}map(t){return w.of(t(o(this,c)))}get(){return o(this,c)}}c=new WeakMap;class l extends y{constructor(t){super(),u.set(this,void 0),i(this,u,t)}static of(t){return new l(t)}isOk(){return!1}isErr(){return!0}onOk(){return l.of(o(this,u))}onErr(t){return t(o(this,u)),l.of(o(this,u))}orElse(t){return w.of(t)}map(){return l.of(o(this,u))}get(){throw o(this,u)}}u=new WeakMap;class d{constructor(t){a.set(this,void 0),i(this,a,t)}static Ok(t){return m.of(t)}static Err(t){return p.of(t)}get then(){const t=o(this,a).then(t=>y.Ok(t),t=>y.Err(t));return t.then.bind(t)}onOk(t){return(async()=>{const[n,e]=await r(o(this,a));n&&t(e)})(),new d(o(this,a))}onErr(t){return(async()=>{const[r,e]=await n(o(this,a));r&&t(e)})(),new d(o(this,a))}async isOk(){return await e(o(this,a))}async isErr(){return await s(o(this,a))}orElse(t){return new d((async()=>{try{return await o(this,a)}catch(r){return t}})())}map(t){return new d((async()=>{const r=await o(this,a);return t(r)})())}async get(){return await o(this,a)}}a=new WeakMap;class m extends d{static of(t){return new m(t)}constructor(t){super(Promise.resolve(t))}}class p extends d{static of(t){return new p(t)}constructor(t){super(Promise.reject(t))}}class g{static Some(t){return v.of(t)}static None(){return E.of()}}class v extends g{constructor(t){super(),f.set(this,void 0),i(this,f,t)}static of(t){return new v(t)}isSome(){return!0}isNone(){return!1}onSome(t){return t(o(this,f)),v.of(o(this,f))}onNone(){return v.of(o(this,f))}orElse(){return v.of(o(this,f))}map(t){return v.of(t(o(this,f)))}filter(t){return t(o(this,f))?v.of(o(this,f)):E.of()}get(){return o(this,f)}}f=new WeakMap;class E extends g{static of(){return new E}constructor(){super()}isSome(){return!1}isNone(){return!0}onSome(){return E.of()}onNone(t){return t(),E.of()}orElse(t){return v.of(t)}map(){return E.of()}filter(){return E.of()}get(){throw new Error("Cannot get value from None")}}function P(t,r){const n=t();return r(n)?g.None():g.Some(n)}const S=Symbol();class k{constructor(t){h.set(this,void 0),i(this,h,t)}static Some(t){return R.of(t)}static None(){return O.of()}get then(){const t=o(this,h).then(t=>t===S?g.None():g.Some(t));return t.then.bind(t)}onSome(t){return(async()=>{const r=await o(this,h);r!==S&&t(r)})(),new k(o(this,h))}onNone(t){return(async()=>{await o(this,h)===S&&t()})(),new k(o(this,h))}async isSome(){return await o(this,h)!==S}async isNone(){return await o(this,h)===S}orElse(t){return new k((async()=>{const r=await o(this,h);return r===S?t:r})())}map(t){return new k((async()=>{const r=await o(this,h);return r===S?S:t(r)})())}filter(t){return new k((async()=>{const r=await o(this,h);return r===S?S:t(r)?r:S})())}async get(){const t=await o(this,h);if(t===S)throw new Error("Cannot get value from None");return t}}h=new WeakMap;class O extends k{static of(){return new O}constructor(){super(Promise.resolve(S))}}class R extends k{static of(t){return new R(t)}constructor(t){super(Promise.resolve(t))}}function N(t,r){return new k((async()=>{const n=await t;return r(n)?S:n})())}t.getError=function(t){try{t()}catch(t){return t}},t.getErrorAsync=async function(t){try{await t()}catch(t){return t}},t.getErrorAsyncIterable=async function(t){try{for await(const r of t);}catch(t){return t}},t.getErrorPromise=async function(t){try{await t}catch(t){return t}},t.getErrorResult=function(t){try{return[void 0,t()]}catch(t){return[t,void 0]}},t.getErrorResultAsync=async function(t){try{return[void 0,await t()]}catch(t){return[t,void 0]}},t.getErrorResultPromise=async function(t){try{return[void 0,await t]}catch(t){return[t,void 0]}},t.getFailure=function(t){try{return t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailureAsync=async function(t){try{return await t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailurePromise=n,t.getResult=function(t){try{return t()}catch(t){return}},t.getResultAsync=async function(t){try{return await t()}catch(t){return}},t.getResultError=function(t){try{return[t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorAsync=async function(t){try{return[await t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorPromise=async function(t){try{return[await t,void 0]}catch(t){return[void 0,t]}},t.getResultPromise=async function(t){try{return await t}catch(t){return}},t.getSuccess=function(t){try{return[!0,t()]}catch(t){return[!1,void 0]}},t.getSuccessAsync=async function(t){try{return[!0,await t()]}catch(t){return[!1,void 0]}},t.getSuccessPromise=r,t.isFailure=function(t){try{return t(),!1}catch(t){return!0}},t.isFailureAsync=async function(t){try{return await t(),!1}catch(t){return!0}},t.isFailurePromise=s,t.isSuccess=function(t){try{return t(),!0}catch(t){return!1}},t.isSuccessAsync=async function(t){try{return await t(),!0}catch(t){return!1}},t.isSuccessPromise=e,t.toOptional=P,t.toOptionalPartial=function(t){return r=>P(r,t)},t.toOptionalPromise=N,t.toOptionalPromisePartial=function(t){return r=>N(r,t)},t.toResult=function(t){try{const r=t();return y.Ok(r)}catch(t){return y.Err(t)}},t.toResultAsync=function(t){try{const r=t();return new d(r)}catch(t){return d.Err(t)}},t.toResultPromise=function(t){return new d(t)},Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.min.js.map

@@ -0,3 +1,4 @@

import { IOptional } from './optional';
export declare const Nil: unique symbol;
export interface IAsyncOptional<T> {
export interface IAsyncOptional<T> extends PromiseLike<IOptional<T>> {
onSome(callback: (val: T) => void): IAsyncOptional<T>;

@@ -16,2 +17,3 @@ onNone(callback: () => void): IAsyncOptional<T>;

static None(): IAsyncOptional<never>;
get then(): <TResult1 = IOptional<T>, TResult2 = never>(onfulfilled?: ((value: IOptional<T>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => PromiseLike<TResult1 | TResult2>;
constructor(promise: PromiseLike<T | typeof Nil>);

@@ -18,0 +20,0 @@ onSome(callback: (val: T) => void): IAsyncOptional<T>;

@@ -27,2 +27,3 @@ "use strict";

exports.AsyncOptional = exports.Nil = void 0;
const optional_1 = require("./optional");
exports.Nil = Symbol();

@@ -40,2 +41,8 @@ class AsyncOptional {

}
get then() {
const promise = __classPrivateFieldGet(this, _promise).then(x => x === exports.Nil
? optional_1.Optional.None()
: optional_1.Optional.Some(x));
return promise.then.bind(promise);
}
onSome(callback) {

@@ -42,0 +49,0 @@ (() => __awaiter(this, void 0, void 0, function* () {

@@ -1,2 +0,3 @@

export interface IAsyncResult<T, X> {
import { IResult } from './result';
export interface IAsyncResult<T, X> extends PromiseLike<IResult<T, X>> {
onOk(callback: (val: T) => void): IAsyncResult<T, X>;

@@ -14,2 +15,3 @@ onErr(callback: (err: X) => void): IAsyncResult<T, X>;

static Err<T>(error: T): IAsyncResult<never, T>;
get then(): <TResult1 = IResult<T, X>, TResult2 = never>(onfulfilled?: ((value: IResult<T, X>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => PromiseLike<TResult1 | TResult2>;
constructor(promise: PromiseLike<T>);

@@ -16,0 +18,0 @@ onOk(callback: (val: T) => void): IAsyncResult<T, X>;

@@ -27,2 +27,3 @@ "use strict";

exports.AsyncResult = void 0;
const result_1 = require("./result");
const get_success_promise_1 = require("../functions/get-success-promise");

@@ -43,2 +44,6 @@ const get_failure_promise_1 = require("../functions/get-failure-promise");

}
get then() {
const promise = __classPrivateFieldGet(this, _promise).then(x => result_1.Result.Ok(x), x => result_1.Result.Err(x));
return promise.then.bind(promise);
}
onOk(callback) {

@@ -45,0 +50,0 @@ (() => __awaiter(this, void 0, void 0, function* () {

@@ -0,3 +1,4 @@

import { IOptional } from './optional';
export declare const Nil: unique symbol;
export interface IAsyncOptional<T> {
export interface IAsyncOptional<T> extends PromiseLike<IOptional<T>> {
onSome(callback: (val: T) => void): IAsyncOptional<T>;

@@ -16,2 +17,3 @@ onNone(callback: () => void): IAsyncOptional<T>;

static None(): IAsyncOptional<never>;
get then(): <TResult1 = IOptional<T>, TResult2 = never>(onfulfilled?: ((value: IOptional<T>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => PromiseLike<TResult1 | TResult2>;
constructor(promise: PromiseLike<T | typeof Nil>);

@@ -18,0 +20,0 @@ onSome(callback: (val: T) => void): IAsyncOptional<T>;

@@ -18,2 +18,3 @@ "use strict";

exports.AsyncOptional = exports.Nil = void 0;
const optional_1 = require("./optional");
exports.Nil = Symbol();

@@ -31,2 +32,8 @@ class AsyncOptional {

}
get then() {
const promise = __classPrivateFieldGet(this, _promise).then(x => x === exports.Nil
? optional_1.Optional.None()
: optional_1.Optional.Some(x));
return promise.then.bind(promise);
}
onSome(callback) {

@@ -33,0 +40,0 @@ (async () => {

@@ -1,2 +0,3 @@

export interface IAsyncResult<T, X> {
import { IResult } from './result';
export interface IAsyncResult<T, X> extends PromiseLike<IResult<T, X>> {
onOk(callback: (val: T) => void): IAsyncResult<T, X>;

@@ -14,2 +15,3 @@ onErr(callback: (err: X) => void): IAsyncResult<T, X>;

static Err<T>(error: T): IAsyncResult<never, T>;
get then(): <TResult1 = IResult<T, X>, TResult2 = never>(onfulfilled?: ((value: IResult<T, X>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => PromiseLike<TResult1 | TResult2>;
constructor(promise: PromiseLike<T>);

@@ -16,0 +18,0 @@ onOk(callback: (val: T) => void): IAsyncResult<T, X>;

@@ -18,2 +18,3 @@ "use strict";

exports.AsyncResult = void 0;
const result_1 = require("./result");
const get_success_promise_1 = require("../functions/get-success-promise");

@@ -34,2 +35,6 @@ const get_failure_promise_1 = require("../functions/get-failure-promise");

}
get then() {
const promise = __classPrivateFieldGet(this, _promise).then(x => result_1.Result.Ok(x), x => result_1.Result.Err(x));
return promise.then.bind(promise);
}
onOk(callback) {

@@ -36,0 +41,0 @@ (async () => {

{
"name": "return-style",
"version": "0.11.0",
"version": "0.11.2",
"description": "Non-intrusively convert the result of any function or promise to the user's desired style.",

@@ -51,3 +51,3 @@ "keywords": [

"hooks": {
"pre-commit": "yarn lint && yarn test",
"pre-commit": "yarn build && yarn lint && yarn test",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"

@@ -57,24 +57,24 @@ }

"devDependencies": {
"@blackglory/jest-matchers": "^0.1.1",
"@blackglory/types": "^0.1.3",
"@blackglory/jest-matchers": "^0.1.7",
"@blackglory/types": "^0.2.1",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/jest": "^26.0.14",
"@types/node": "^14.11.8",
"@typescript-eslint/eslint-plugin": "^4.4.0",
"@typescript-eslint/parser": "^4.4.0",
"eslint": "^7.11.0",
"husky": "^4.3.0",
"iterable-operator": "^0.12.2",
"jest": "^26.5.2",
"@rollup/plugin-typescript": "^8.1.0",
"@types/jest": "^26.0.19",
"@types/node": "^14.14.19",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"eslint": "^7.17.0",
"husky": "^4.3.6",
"iterable-operator": "^0.12.4",
"jest": "^26.6.3",
"jest-extended": "^0.11.5",
"rollup": "^2.29.0",
"rollup": "^2.35.1",
"rollup-plugin-terser": "^7.0.2",
"standard-version": "^9.0.0",
"ts-jest": "^26.4.1",
"standard-version": "^9.1.0",
"ts-jest": "^26.4.4",
"tscpaths": "^0.0.9",
"typescript": "^4.0.3"
"typescript": "^4.1.3"
},
"dependencies": {}
}

@@ -221,3 +221,3 @@ # return-style

interface AsyncResult<T, X> {
interface AsyncResult<T, X> extends PromiseLike<Result<T, X>> {
onOk(callback: (val: T) => void): AsyncResult<T, X>

@@ -258,3 +258,3 @@ onErr(callback: (err: X) => void): AsyncResult<T, X>

interface AsyncOptional<T> {
interface AsyncOptional<T> extends PromiseLike<Optional<T>> {
onSome(callback: (val: T) => void): AsyncOptional<T>

@@ -261,0 +261,0 @@ onNone(callback: () => void): AsyncOptional<T>

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc