@hckrnews/local-fetch

Local Fetch

Usage no npm install needed!

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

README

Local Fetch

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 file data like the fetch method.

Example usage

import localFetchfrom '@hckrnews/local-fetch'

const fetch = await localFetcher('file:///Users/pieter.wigboldus/projects/local-fetch/src/__fixtures__/example.json')

Returns the body as string.

fetch.text()

Returns the body parsed as JSON.

fetch.json()

Returns the body as ReadableStream.

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

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