Sha256: ec7fe72d165facae48c1bd7e71c20711604d327cad579341cca60de736838159
Contents?: true
Size: 918 Bytes
Versions: 4
Compression:
Stored size: 918 Bytes
Contents
import * as Normalize from './normalize' import { currentConfig } from './config' import { promises as fs } from 'fs' import unfetch from 'isomorphic-unfetch' const fetchOrReadFile = async ( input: string, ): Promise<Response | { json: () => Promise<unknown> }> => { const fileURL = new URL(`${currentConfig.japaneseAddressesApi}${input}`) if (fileURL.protocol === 'http:' || fileURL.protocol === 'https:') { return unfetch(fileURL.toString()) } else if (fileURL.protocol === 'file:') { const filePath = decodeURI(fileURL.pathname) return { json: async () => { const contents = await fs.readFile(filePath) return JSON.parse(contents.toString('utf-8')) }, } } else { throw new Error(`Unknown URL schema: ${fileURL.protocol}`) } } Normalize.__internals.fetch = fetchOrReadFile export const config = currentConfig export const normalize = Normalize.normalize
Version data entries
4 entries across 4 versions & 1 rubygems