first commit
This commit is contained in:
25
node_modules/n8n-workflow/dist/esm/result.js
generated
vendored
Normal file
25
node_modules/n8n-workflow/dist/esm/result.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { ensureError } from './errors';
|
||||
export const createResultOk = (data) => ({
|
||||
ok: true,
|
||||
result: data,
|
||||
});
|
||||
export const createResultError = (error) => ({
|
||||
ok: false,
|
||||
error,
|
||||
});
|
||||
/**
|
||||
* Executes the given function and converts it to a Result object.
|
||||
*
|
||||
* @example
|
||||
* const result = toResult(() => fs.writeFileSync('file.txt', 'Hello, World!'));
|
||||
*/
|
||||
export const toResult = (fn) => {
|
||||
try {
|
||||
return createResultOk(fn());
|
||||
}
|
||||
catch (e) {
|
||||
const error = ensureError(e);
|
||||
return createResultError(error);
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=result.js.map
|
||||
Reference in New Issue
Block a user