How to use iso-url - 2 common examples

To help you get started, we’ve selected a few iso-url examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipfs / js-ipfs / src / core / components / files-regular / add-from-url.js View on Github external
return async (url, options, callback) => {
    if (typeof options === 'function') {
      callback = options
      options = {}
    }

    let files

    try {
      const parsedUrl = new URL(url)
      const res = await fetch(url)

      if (!res.ok) {
        throw new Error('unexpected status code: ' + res.status)
      }

      // TODO: use res.body when supported
      const content = Buffer.from(await res.arrayBuffer())
      const path = decodeURIComponent(parsedUrl.pathname.split('/').pop())

      files = await self.add({ content, path }, options)
    } catch (err) {
      if (callback) {
        return callback(err)
      }
      throw err
github ipfs / js-ipfs-http-client / src / files-regular / add-from-url.js View on Github external
const requestWithRedirect = (url, opts, sendOneFile, callback) => {
  const parsedUrl = new URL(url)

  const req = getRequest(parsedUrl, (res) => {
    if (res.statusCode >= 400) {
      return callback(new Error(`Failed to download with ${res.statusCode}`))
    }

    const redirection = res.headers.location

    if (res.statusCode >= 300 && res.statusCode < 400 && redirection) {
      if (!validUrl(redirection)) {
        return callback(new Error('redirection url must be an http(s) url'))
      }

      requestWithRedirect(redirection, opts, sendOneFile, callback)
    } else {
      const requestOpts = {

iso-url

Isomorphic/Universal WHATWG URL API with some support legacy node URL API

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis

Popular iso-url functions