Version 1
[yaffs-website] / node_modules / uncss / node_modules / lodash / attempt.js
diff --git a/node_modules/uncss/node_modules/lodash/attempt.js b/node_modules/uncss/node_modules/lodash/attempt.js
new file mode 100644 (file)
index 0000000..a848ef5
--- /dev/null
@@ -0,0 +1,33 @@
+var apply = require('./internal/apply'),
+    isError = require('./isError'),
+    rest = require('./rest');
+
+/**
+ * Attempts to invoke `func`, returning either the result or the caught error
+ * object. Any additional arguments are provided to `func` when it's invoked.
+ *
+ * @static
+ * @memberOf _
+ * @category Util
+ * @param {Function} func The function to attempt.
+ * @returns {*} Returns the `func` result or error object.
+ * @example
+ *
+ * // avoid throwing errors for invalid selectors
+ * var elements = _.attempt(function(selector) {
+ *   return document.querySelectorAll(selector);
+ * }, '>_>');
+ *
+ * if (_.isError(elements)) {
+ *   elements = [];
+ * }
+ */
+var attempt = rest(function(func, args) {
+  try {
+    return apply(func, undefined, args);
+  } catch (e) {
+    return isError(e) ? e : new Error(e);
+  }
+});
+
+module.exports = attempt;