({ url }, propKey)
| 56 | |
| 57 | return new Proxy(callable, { |
| 58 | get({ url }, propKey) { |
| 59 | // If we're just getting the url, return it |
| 60 | if ( propKey === 'url' ) return `${ url }.json` |
| 61 | |
| 62 | // If we're using an HTTP method |
| 63 | // then do a request to the url |
| 64 | if ( HTTP_METHODS.includes(propKey.toUpperCase()) ) { |
| 65 | return (data) => fetchMethod({ |
| 66 | url: `${ url }.json`, |
| 67 | method: propKey.toUpperCase(), |
| 68 | data |
| 69 | }) |
| 70 | } |
| 71 | |
| 72 | // Otherwise drill down to the next property |
| 73 | // Example: |
| 74 | // From DoesItAPI.kind... |
| 75 | // To DoesItAPI.kind.apps... |
| 76 | return generateAPI({ apiUrl: `${url}/${propKey}` }) |
| 77 | |
| 78 | }, |
| 79 | // Handles when () goes after a property key |
| 80 | // Example: DoesItAPI() or DoesItAPI.app() |
| 81 | // Proxy.handler.apply - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/apply |
nothing calls this directly
no test coverage detected