method-missing
Advanced tools
+267
| module.exports = { | ||
| "env": { | ||
| "es6": true, | ||
| "node": true | ||
| }, | ||
| "extends": "eslint:recommended", | ||
| "parserOptions": { | ||
| "sourceType": "module" | ||
| }, | ||
| "rules": { | ||
| "accessor-pairs": "error", | ||
| "array-bracket-spacing": "error", | ||
| "array-callback-return": "error", | ||
| "arrow-body-style": "error", | ||
| "arrow-parens": "error", | ||
| "arrow-spacing": "error", | ||
| "block-scoped-var": "error", | ||
| "block-spacing": "error", | ||
| "brace-style": [ | ||
| "error", | ||
| "1tbs" | ||
| ], | ||
| "callback-return": "error", | ||
| "camelcase": "error", | ||
| "capitalized-comments": [ | ||
| "error", | ||
| "always" | ||
| ], | ||
| "class-methods-use-this": "error", | ||
| "comma-dangle": "off", | ||
| "comma-spacing": [ | ||
| "error", | ||
| { | ||
| "after": true, | ||
| "before": false | ||
| } | ||
| ], | ||
| "comma-style": "error", | ||
| "complexity": "error", | ||
| "computed-property-spacing": [ | ||
| "error", | ||
| "never" | ||
| ], | ||
| "consistent-return": "error", | ||
| "consistent-this": "off", | ||
| "curly": "error", | ||
| "default-case": "error", | ||
| "dot-location": "error", | ||
| "dot-notation": "error", | ||
| "eol-last": "error", | ||
| "eqeqeq": "error", | ||
| "func-call-spacing": "error", | ||
| "func-name-matching": "error", | ||
| "func-names": "error", | ||
| "func-style": [ | ||
| "error", | ||
| "declaration" | ||
| ], | ||
| "generator-star-spacing": "error", | ||
| "global-require": "error", | ||
| "guard-for-in": "error", | ||
| "handle-callback-err": "error", | ||
| "id-blacklist": "error", | ||
| "id-length": "error", | ||
| "id-match": "error", | ||
| "indent": "off", | ||
| "init-declarations": "error", | ||
| "jsx-quotes": "error", | ||
| "key-spacing": "error", | ||
| "keyword-spacing": [ | ||
| "error", | ||
| { | ||
| "after": true, | ||
| "before": true | ||
| } | ||
| ], | ||
| "line-comment-position": "error", | ||
| "linebreak-style": [ | ||
| "error", | ||
| "unix" | ||
| ], | ||
| "lines-around-comment": "error", | ||
| "lines-around-directive": "error", | ||
| "max-depth": "error", | ||
| "max-len": "off", | ||
| "max-lines": "error", | ||
| "max-nested-callbacks": "error", | ||
| "max-params": "error", | ||
| "max-statements": "error", | ||
| "max-statements-per-line": "error", | ||
| "multiline-ternary": "error", | ||
| "new-cap": "error", | ||
| "new-parens": "error", | ||
| "newline-after-var": "off", | ||
| "newline-before-return": "off", | ||
| "newline-per-chained-call": "error", | ||
| "no-alert": "error", | ||
| "no-array-constructor": "error", | ||
| "no-await-in-loop": "error", | ||
| "no-bitwise": "error", | ||
| "no-caller": "error", | ||
| "no-catch-shadow": "error", | ||
| "no-class-assign": "off", | ||
| "no-console": "off", | ||
| "no-compare-neg-zero": "error", | ||
| "no-confusing-arrow": "error", | ||
| "no-continue": "error", | ||
| "no-div-regex": "error", | ||
| "no-duplicate-imports": "error", | ||
| "no-else-return": "error", | ||
| "no-empty-function": "error", | ||
| "no-eq-null": "error", | ||
| "no-eval": "error", | ||
| "no-extend-native": "error", | ||
| "no-extra-bind": "error", | ||
| "no-extra-label": "error", | ||
| "no-extra-parens": "error", | ||
| "no-floating-decimal": "error", | ||
| "no-implicit-coercion": "error", | ||
| "no-implicit-globals": "error", | ||
| "no-implied-eval": "error", | ||
| "no-inline-comments": "error", | ||
| "no-invalid-this": "off", | ||
| "no-iterator": "error", | ||
| "no-label-var": "error", | ||
| "no-labels": "error", | ||
| "no-lone-blocks": "error", | ||
| "no-lonely-if": "error", | ||
| "no-loop-func": "error", | ||
| "no-magic-numbers": "error", | ||
| "no-mixed-operators": "error", | ||
| "no-mixed-requires": "error", | ||
| "no-multi-assign": "error", | ||
| "no-multi-spaces": "error", | ||
| "no-multi-str": "error", | ||
| "no-multiple-empty-lines": "error", | ||
| "no-native-reassign": "error", | ||
| "no-negated-condition": "error", | ||
| "no-negated-in-lhs": "error", | ||
| "no-nested-ternary": "error", | ||
| "no-new": "error", | ||
| "no-new-func": "error", | ||
| "no-new-object": "error", | ||
| "no-new-require": "error", | ||
| "no-new-wrappers": "error", | ||
| "no-octal-escape": "error", | ||
| "no-param-reassign": "error", | ||
| "no-path-concat": "error", | ||
| "no-plusplus": "error", | ||
| "no-process-env": "error", | ||
| "no-process-exit": "error", | ||
| "no-proto": "error", | ||
| "no-prototype-builtins": "error", | ||
| "no-restricted-globals": "error", | ||
| "no-restricted-imports": "error", | ||
| "no-restricted-modules": "error", | ||
| "no-restricted-properties": "error", | ||
| "no-restricted-syntax": "error", | ||
| "no-return-assign": "error", | ||
| "no-return-await": "error", | ||
| "no-script-url": "error", | ||
| "no-self-compare": "error", | ||
| "no-sequences": "error", | ||
| "no-shadow": "error", | ||
| "no-shadow-restricted-names": "error", | ||
| "no-spaced-func": "error", | ||
| "no-sync": "error", | ||
| "no-tabs": "error", | ||
| "no-template-curly-in-string": "error", | ||
| "no-ternary": "error", | ||
| "no-throw-literal": "error", | ||
| "no-trailing-spaces": "error", | ||
| "no-undef-init": "error", | ||
| "no-undefined": "error", | ||
| "no-underscore-dangle": "error", | ||
| "no-unmodified-loop-condition": "error", | ||
| "no-unneeded-ternary": "error", | ||
| "no-unused-expressions": "error", | ||
| "no-use-before-define": "error", | ||
| "no-useless-call": "error", | ||
| "no-useless-computed-key": "error", | ||
| "no-useless-concat": "error", | ||
| "no-useless-constructor": "error", | ||
| "no-useless-escape": "error", | ||
| "no-useless-rename": "error", | ||
| "no-useless-return": "error", | ||
| "no-var": "error", | ||
| "no-void": "error", | ||
| "no-warning-comments": "error", | ||
| "no-whitespace-before-property": "error", | ||
| "no-with": "error", | ||
| "nonblock-statement-body-position": "error", | ||
| "object-curly-newline": "error", | ||
| "object-curly-spacing": "error", | ||
| "object-property-newline": "error", | ||
| "object-shorthand": "error", | ||
| "one-var": "off", | ||
| "one-var-declaration-per-line": "off", | ||
| "operator-assignment": "error", | ||
| "operator-linebreak": "error", | ||
| "padded-blocks": "off", | ||
| "prefer-arrow-callback": "error", | ||
| "prefer-const": "error", | ||
| "prefer-destructuring": "error", | ||
| "prefer-numeric-literals": "error", | ||
| "prefer-promise-reject-errors": "error", | ||
| "prefer-reflect": "off", | ||
| "prefer-rest-params": "error", | ||
| "prefer-spread": "error", | ||
| "prefer-template": "error", | ||
| "quote-props": "error", | ||
| "quotes": [ | ||
| "error", | ||
| "single" | ||
| ], | ||
| "radix": "error", | ||
| "require-await": "error", | ||
| "require-jsdoc": "off", | ||
| "rest-spread-spacing": [ | ||
| "error", | ||
| "never" | ||
| ], | ||
| "semi": "error", | ||
| "semi-spacing": "error", | ||
| "sort-imports": "error", | ||
| "sort-keys": "error", | ||
| "sort-vars": "error", | ||
| "space-before-blocks": "error", | ||
| "space-before-function-paren": "off", | ||
| "space-in-parens": [ | ||
| "error", | ||
| "never" | ||
| ], | ||
| "space-infix-ops": "error", | ||
| "space-unary-ops": "error", | ||
| "spaced-comment": [ | ||
| "error", | ||
| "always", { | ||
| "block": { | ||
| "markers": ["!"], | ||
| "exceptions": ["*"], | ||
| "balanced": false | ||
| } | ||
| } | ||
| ], | ||
| "strict": "error", | ||
| "symbol-description": "error", | ||
| "template-curly-spacing": [ | ||
| "error", | ||
| "never" | ||
| ], | ||
| "template-tag-spacing": "error", | ||
| "unicode-bom": [ | ||
| "error", | ||
| "never" | ||
| ], | ||
| "valid-jsdoc": "error", | ||
| "vars-on-top": "error", | ||
| "wrap-iife": "error", | ||
| "wrap-regex": "error", | ||
| "yield-star-spacing": "error", | ||
| "yoda": [ | ||
| "error", | ||
| "never" | ||
| ] | ||
| } | ||
| }; |
+13
-1
@@ -1,1 +0,13 @@ | ||
| module.exports = require('./lib/method-missing'); | ||
| /*! | ||
| * Method Missing. | ||
| * | ||
| * Application entry file. | ||
| * @author Jarrad Seers <jarrad@seers.me> | ||
| * @created 29/03/2017 NZDT | ||
| */ | ||
| /** | ||
| * Module exports. | ||
| */ | ||
| module.exports = require('./lib/method-missing'); |
+4
-6
@@ -9,7 +9,5 @@ /*! | ||
| 'use strict'; | ||
| /** | ||
| * Method Missing Error. | ||
| * | ||
| * | ||
| * @class MethodMissingError | ||
@@ -23,4 +21,4 @@ * @extends {Error} | ||
| * Creates an instance of MethodMissingError. | ||
| * @param {any} msg | ||
| * | ||
| * @param {any} msg | ||
| * | ||
| * @memberOf MethodMissingError | ||
@@ -31,3 +29,3 @@ */ | ||
| super(msg); | ||
| this.name = this.constructor.name | ||
| this.name = this.constructor.name; | ||
| Error.captureStackTrace(this, this.constructor); | ||
@@ -34,0 +32,0 @@ } |
+12
-16
@@ -9,4 +9,2 @@ /*! | ||
| 'use strict'; | ||
| /** | ||
@@ -20,3 +18,3 @@ * Module dependencies. | ||
| * MethodMissing Class | ||
| * | ||
| * | ||
| * @class MethodMissing | ||
@@ -29,10 +27,9 @@ */ | ||
| * Creates an instance of MethodMissing. | ||
| * @param {any} method | ||
| * | ||
| * @param {any} method | ||
| * | ||
| * @memberOf MethodMissing | ||
| */ | ||
| constructor(method) { | ||
| method = method || '__call'; | ||
| return proxy(this, method); | ||
| return proxy(this, method || '__call'); | ||
| } | ||
@@ -42,8 +39,8 @@ | ||
| * Static method handler. | ||
| * | ||
| * | ||
| * @static | ||
| * @param {any} that | ||
| * @param {any} method | ||
| * @returns | ||
| * | ||
| * @param {any} that | ||
| * @param {any} method | ||
| * @returns | ||
| * | ||
| * @memberOf MethodMissing | ||
@@ -53,4 +50,3 @@ */ | ||
| static static(that, method) { | ||
| method = method || '__call'; | ||
| return proxy(that, method); | ||
| return proxy(that, method || '__call'); | ||
| } | ||
@@ -64,2 +60,2 @@ | ||
| module.exports = MethodMissing; | ||
| module.exports = MethodMissing; |
+15
-17
@@ -9,4 +9,2 @@ /*! | ||
| 'use strict'; | ||
| /** | ||
@@ -20,26 +18,26 @@ * Module dependencies. | ||
| * Main proxy handler. | ||
| * | ||
| * @param {object} Class | ||
| * @param {string} method | ||
| * | ||
| * @param {object} Class | ||
| * @param {string} method | ||
| */ | ||
| function proxy(Class, method) { | ||
| return new Proxy(Class, { | ||
| get: function (obj, prop) { | ||
| get(obj, prop) { | ||
| if (Reflect.has(obj, prop)) { | ||
| return Reflect.get(obj, prop); | ||
| } else if (typeof method === 'function') { | ||
| return function() { | ||
| method.call(this, prop, arguments); | ||
| } | ||
| return function methodMissing(...args) { | ||
| method.call(this, prop, args); | ||
| }; | ||
| } else if (Reflect.has(obj, method)) { | ||
| return function() { | ||
| obj[method].call(this, prop, arguments); | ||
| } | ||
| } else { | ||
| throw new MethodMissingError( | ||
| `${method}, use method '__call(method, args)' in your class to catch.` | ||
| ); | ||
| return function methodMissing(...args) { | ||
| obj[method].call(this, prop, args); | ||
| }; | ||
| } | ||
| } | ||
| const err = `${method}, use method '__call(method, args)' in your class to catch.`; | ||
| throw new MethodMissingError(err); | ||
| }, | ||
| }); | ||
@@ -46,0 +44,0 @@ } |
+10
-5
| { | ||
| "name": "method-missing", | ||
| "version": "1.1.4", | ||
| "engines" : { | ||
| "node" : ">=6.0.0" | ||
| "version": "1.2.0", | ||
| "engines": { | ||
| "node": ">=6.0.0" | ||
| }, | ||
@@ -14,3 +14,3 @@ "engineStrict": true, | ||
| "scripts": { | ||
| "test": "node test" | ||
| "test": "eslint ./lib/*.js && node test" | ||
| }, | ||
@@ -33,3 +33,8 @@ "repository": { | ||
| }, | ||
| "homepage": "https://github.com/jarradseers/method-missing#readme" | ||
| "homepage": "https://github.com/jarradseers/method-missing#readme", | ||
| "devDependencies": { | ||
| "eslint": "^3.18.0", | ||
| "eslint-config-airbnb-base": "^11.1.2", | ||
| "eslint-plugin-import": "^2.2.0" | ||
| } | ||
| } |
+11
-37
@@ -24,6 +24,2 @@ # Method Missing Class | ||
| constructor() { | ||
| super(); | ||
| } | ||
| __call(name, args) { | ||
@@ -37,3 +33,3 @@ console.log(`The method '${name}' was called with:`, args); | ||
| simple.nonExistent('Hello!'); | ||
| // The method 'nonExistent' was called with: { '0': 'Hello!' } | ||
| // The method 'nonExistent' was called with: [ 'Hello!' ] | ||
| ``` | ||
@@ -53,4 +49,6 @@ | ||
| Simple = MethodMissing.static(Simple); | ||
| // Call the static method. | ||
| Simple.nonExistentStatic(1, 2, 3); | ||
| // The method 'nonExistentStatic' was called with: {0: 1, 1: 2, 2: 3} | ||
| // The method 'nonExistentStatic' was called with: [ 1, 2, 3 ] | ||
| ``` | ||
@@ -63,6 +61,2 @@ | ||
| constructor() { | ||
| super(); | ||
| } | ||
| iExist(str) { | ||
@@ -89,5 +83,5 @@ console.log(`I do exist ${str}.`); | ||
| Simple.nonExistentStatic('hey'); | ||
| // The method 'nonExistent' was called with: { '0': 'hello' } | ||
| // The method 'nonExistent' was called with: [ 'hello' ] | ||
| // I do exist world. | ||
| // The method 'nonExistentStatic' was called with: { '0': 'hey' } | ||
| // The method 'nonExistentStatic' was called with: [ 'hey' ] | ||
| ``` | ||
@@ -102,3 +96,3 @@ Used on an object: | ||
| }, (name, args) => { | ||
| console.log(`Sorry, method '${name}' doesn't exist.`); | ||
| console.log(`Sorry, method '${name}' doesn't exist.`, args); | ||
| }); | ||
@@ -110,3 +104,3 @@ | ||
| // hey there | ||
| // Sorry, method 'two' doesn't exist. | ||
| // Sorry, method 'two' doesn't exist. [] | ||
| ``` | ||
@@ -132,3 +126,3 @@ | ||
| Changing the `__call` method | ||
| Changing the `__call` method (if you must, just be careful with this). | ||
@@ -158,26 +152,6 @@ ```js | ||
| test.nonExistentStatic('world'); | ||
| // The method 'nonExistentStatic' was called with: { '0': 'hey' } | ||
| // The method 'nonExistent' was called with: { '0': 'hello' } | ||
| // The method 'nonExistentStatic' was called with: { '0': 'world' } | ||
| // The method 'nonExistent' was called with: [ 'hello' ] | ||
| // The method 'nonExistentStatic' was called with: [ 'world' ] | ||
| ``` | ||
| Modifying the arguments to be an array: | ||
| ```js | ||
| class Args extends MethodMissing { | ||
| constructor() { | ||
| super(); | ||
| } | ||
| __call(name, [...args]) { | ||
| console.log(`The method '${name}' was called with:`, args); | ||
| } | ||
| } | ||
| new Args().say('hello', 'world!'); | ||
| // The method 'say' was called with: [ 'hello', 'world!' ] | ||
| ``` | ||
| ## Tests | ||
@@ -184,0 +158,0 @@ |
+8
-16
@@ -9,17 +9,12 @@ /*! | ||
| // TODO : Write some real unit tests ;) | ||
| 'use strict'; | ||
| const MethodMissing = require('../'); | ||
| class Simple extends MethodMissing { | ||
| constructor() { | ||
| super(); | ||
| } | ||
| iExist(str) { | ||
| console.log(`I do exist ${str}.`); | ||
| return this; | ||
| } | ||
| __call(name, args) { | ||
| console.log(`The method '${name}' was called with:`, args); | ||
| return this; | ||
| } | ||
@@ -49,2 +44,3 @@ static __call(name, args) { | ||
| console.log(`The method '${name}' was called with:`, args); | ||
| return this; | ||
| } | ||
@@ -67,7 +63,5 @@ static missing(name, args) { | ||
| class RealSimple extends MethodMissing { | ||
| constructor() { | ||
| super(); | ||
| } | ||
| __call(name, [...args]) { | ||
| console.log(`The method '${name}' was called with:`, args); | ||
| return this; | ||
| } | ||
@@ -80,7 +74,5 @@ } | ||
| class Args extends MethodMissing { | ||
| constructor() { | ||
| super(); | ||
| } | ||
| __call(name, [...args]) { | ||
| console.log(`The method '${name}' was called with:`, args); | ||
| return this; | ||
| } | ||
@@ -93,6 +85,6 @@ } | ||
| const object = MethodMissing.static({ | ||
| one: function() { | ||
| one () { | ||
| console.log('hey there'); | ||
| } | ||
| }, (name, args) => { | ||
| }, | ||
| }, (name) => { | ||
| console.log(`Sorry, method '${name}' doesn't exist.`); | ||
@@ -99,0 +91,0 @@ }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18374
78.74%10
11.11%464
133.17%3
Infinity%158
-14.13%1
Infinity%