# Files

# getFilesWithKeyword(keyword)

It returns the file object from a keyword

const file = await getFilesWithKeyword('myKeyword')
console.log(file)

# fetchLocalFile(localPath, options)

This function helps to fetch local files from Pitcher Folders without any extra setting and cross platform. As a use-case, let's say you have a json file that you want to load from Pitcher Folders/json/. Normally you would need to write an ajax call to achieve this, with this function you can easily achieve this without any extra code. The function fetches the file and by default returns as json. If you would want to get the whole response, you can send returnJson: false as an option.

# options

property required default description
documentPath no undefined Default document path, if not provided, uses window.documentPath. Recommended not to provide any path to get it work cross-platform automatically
returnJson no true By default it executes response.json() on response object and returns json. If you want to access default response object you can disable this.

# Examples

// Basic example

import { fetchLocalFile } from '@pitcher/core'

const json = await fetchLocalFile('json/12345.json')
console.log(json)
// Get whole response object

import { fetchLocalFile } from '@pitcher/core'

const response = await fetchLocalFile('json/12345.json', { returnJson: false })
console.log(response)