Browse Source

dev: add more to NariMethodsFeature

KernelDeimos 7 months ago
parent
commit
fc9a371e09
1 changed files with 12 additions and 1 deletions
  1. 12 1
      src/putility/src/features/NariMethodsFeature.js

+ 12 - 1
src/putility/src/features/NariMethodsFeature.js

@@ -52,7 +52,14 @@ module.exports = {
             instance._.nariMethods[method_name] = bound_fn;
 
             instance[method_name] = async (...args) => {
-                const endArgsIndex = spec.positional.length;
+                const endArgsIndex = (() => {
+                    if ( spec.firstarg_options ) {
+                        if ( typeof args[0] === 'object' ) {
+                            return 0;
+                        }
+                    }
+                    return spec.positional.length;
+                })();
                 const posArgs = args.slice(0, endArgsIndex);
                 const endArgs = args.slice(endArgsIndex);
 
@@ -71,11 +78,15 @@ module.exports = {
                 if ( typeof endArgs[0] === 'function' ) {
                     callbacks.success = endArgs[0];
                     endArgs.shift();
+                } else if ( options.success ) {
+                    callbacks.success = options.success;
                 }
 
                 if ( typeof endArgs[0] === 'function' ) {
                     callbacks.error = endArgs[0];
                     endArgs.shift();
+                } else if ( options.error ) {
+                    callbacks.error = options.error;
                 }
 
                 if ( spec.separate_options ) {