wip: migrate to bun

This commit is contained in:
jdalton
2023-09-16 14:47:50 -07:00
parent 2da024c3b4
commit 97d4a2fe19
1052 changed files with 30244 additions and 26856 deletions

30
src/attempt.ts Normal file
View File

@@ -0,0 +1,30 @@
import isError from './isError.js';
/**
* Attempts to invoke `func`, returning either the result or the caught error
* object. Any additional arguments are provided to `func` when it's invoked.
*
* @since 3.0.0
* @category Util
* @param {Function} func The function to attempt.
* @param {...*} [args] The arguments to invoke `func` with.
* @returns {*} Returns the `func` result or error object.
* @example
*
* // Avoid throwing errors for invalid selectors.
* const elements = attempt(selector =>
* document.querySelectorAll(selector), '>_>')
*
* if (isError(elements)) {
* elements = []
* }
*/
function attempt(func, ...args) {
try {
return func(...args);
} catch (e) {
return isError(e) ? e : new Error(e);
}
}
export default attempt;