@statx/utils
Advanced tools
| export declare const isEqualSet: (current: Set<unknown>, prev?: Set<unknown>) => boolean; |
| export const isEqualSet = (current, prev) => { | ||
| if (!prev) | ||
| return false; | ||
| if (current.size !== prev.size) | ||
| return false; | ||
| for (const state of prev) { | ||
| if (!current.has(state)) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| }; | ||
| //# sourceMappingURL=is-equal.js.map |
| {"version":3,"file":"is-equal.js","sourceRoot":"","sources":["../src/is-equal.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAqB,EAAE,IAAmB,EAAE,EAAE;IACvE,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAA;IACvB,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAA;IAC5C,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"} |
| export declare class Result<TRes, TErr> { | ||
| value: TRes | undefined; | ||
| error: TErr | undefined; | ||
| ok: boolean; | ||
| constructor(data: { | ||
| ok: boolean; | ||
| value: TRes; | ||
| error: TErr; | ||
| } | Result<TRes, TErr>); | ||
| static success<T, E>(value: T): Result<T, E>; | ||
| static failure<E, T>(error: E): Result<T, E>; | ||
| bind<T extends (value: TRes) => unknown>(fn: T): unknown; | ||
| match(handleValue: (value: TRes) => unknown, handleError?: (value: TErr) => unknown): unknown; | ||
| } |
| export class Result { | ||
| value; | ||
| error; | ||
| ok; | ||
| constructor(data) { | ||
| this.value = data.value; | ||
| this.error = data.error; | ||
| this.ok = data.ok; | ||
| } | ||
| static success(value) { | ||
| return new Result({ ok: true, value, error: undefined }); | ||
| } | ||
| static failure(error) { | ||
| return new Result({ ok: false, value: undefined, error }); | ||
| } | ||
| bind(fn) { | ||
| return this.ok ? fn(this.value) : new Result(this); | ||
| } | ||
| match(handleValue, handleError) { | ||
| return this.ok ? handleValue(this.value) : handleError?.(this.error); | ||
| } | ||
| } | ||
| //# sourceMappingURL=result-container.js.map |
| {"version":3,"file":"result-container.js","sourceRoot":"","sources":["../src/result-container.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,MAAM;IACjB,KAAK,CAAkB;IACvB,KAAK,CAAkB;IACvB,EAAE,CAAS;IACX,YAAY,IAAkE;QAC5E,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAA;IACnB,CAAC;IACD,MAAM,CAAC,OAAO,CAAO,KAAQ;QAC3B,OAAO,IAAI,MAAM,CAAO,EAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,SAAc,EAAC,CAAC,CAAA;IACnE,CAAC;IACD,MAAM,CAAC,OAAO,CAAO,KAAQ;QAC3B,OAAO,IAAI,MAAM,CAAO,EAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAc,EAAE,KAAK,EAAC,CAAC,CAAA;IACpE,CAAC;IACD,IAAI,CAAqC,EAAK;QAC5C,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAa,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAA;IAC5D,CAAC;IACD,KAAK,CAAC,WAAqC,EAAE,WAAsC;QACjF,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,KAAa,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,KAAa,CAAC,CAAA;IACtF,CAAC;CACF"} |
| export const isEqualSet = (current: Set<unknown>, prev?: Set<unknown>) => { | ||
| if (!prev) return false | ||
| if (current.size !== prev.size) return false | ||
| for (const state of prev) { | ||
| if (!current.has(state)) { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } |
| export class Result<TRes, TErr> { | ||
| value: TRes | undefined | ||
| error: TErr | undefined | ||
| ok: boolean | ||
| constructor(data: {ok: boolean; value: TRes; error: TErr} | Result<TRes, TErr>) { | ||
| this.value = data.value | ||
| this.error = data.error | ||
| this.ok = data.ok | ||
| } | ||
| static success<T, E>(value: T) { | ||
| return new Result<T, E>({ok: true, value, error: undefined as E}) | ||
| } | ||
| static failure<E, T>(error: E) { | ||
| return new Result<T, E>({ok: false, value: undefined as T, error}) | ||
| } | ||
| bind<T extends (value: TRes) => unknown>(fn: T) { | ||
| return this.ok ? fn(this.value as TRes) : new Result(this) | ||
| } | ||
| match(handleValue: (value: TRes) => unknown, handleError?: (value: TErr) => unknown) { | ||
| return this.ok ? handleValue(this.value as TRes) : handleError?.(this.error as TErr) | ||
| } | ||
| } |
+2
-1
@@ -1,1 +0,2 @@ | ||
| export * from './throttle.js'; | ||
| export { throttle } from './throttle.js'; | ||
| export { isEqualSet } from './is-equal.js'; |
+2
-1
@@ -1,2 +0,3 @@ | ||
| export * from './throttle.js'; | ||
| export { throttle } from './throttle.js'; | ||
| export { isEqualSet } from './is-equal.js'; | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AACtC,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA"} |
+1
-1
| The MIT License (MIT) | ||
| Copyright (c) 2022-present Andrey Larkin | ||
| Copyright (c) 2022-2024-present Andrey Larkin | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
+3
-2
| { | ||
| "name": "@statx/utils", | ||
| "version": "1.11.1", | ||
| "version": "1.12.0", | ||
| "private": false, | ||
@@ -44,2 +44,3 @@ "description": "Extry tiny smart statx manager", | ||
| "build:tsc": "tsc", | ||
| "fix": "eslint --fix \"**/*.{ts,tsx}\"", | ||
| "test": "tsx src/index.test.ts", | ||
@@ -61,3 +62,3 @@ "test:watch": "tsx watch src/index.test.ts" | ||
| }, | ||
| "gitHead": "2571f09f8ee530d807031bf08c37b571eb99c678" | ||
| "gitHead": "9dda8bd34a07d4ed896c927f83ba8a127930289c" | ||
| } |
+2
-1
@@ -1,1 +0,2 @@ | ||
| export * from './throttle.js' | ||
| export {throttle} from './throttle.js' | ||
| export {isEqualSet} from './is-equal.js' |
13728
44.96%23
53.33%229
57.93%