@hckrnews/auto-fetch

Auto Fetch local/http

Usage no npm install needed!

<script type="module">
  import hckrnewsAutoFetch from 'https://cdn.skypack.dev/@hckrnews/auto-fetch';
</script>

README

Auto Fetch local/http

NPM version Coverage Scrutinizer Code Quality Quality Gate Status Bugs Code Smells Technical Debt Vulnerabilities Maintainability Rating Reliability Rating Security Rating

With this package you can get local or remote file data like the fetch method.

Example usage

import fetch '@hckrnews/auto-fetch'

const responseLocal = await fetch('./src/__fixtures__/example.json')
const responseRemote = await fetch('https://example.com')

Returns the body as string.

await response.text()

Returns the body parsed as JSON.

await response.json()

Returns the body as ReadableStream.

let result = ''
response.body.on('data', (chunk) => {
    result += chunk
})

response.body.on('end', () => {
    const data = JSON.parse(result)
})