npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@exodus/networking-mobile

v2.0.1

Published

Implementation of @exodus/networking-spec for a React Native context

Downloads

5,560

Readme

@exodus/networking-mobile

This repository contains the implementation of the @exodus/networking-spec for React Native contexts.

Installing

yarn add @exodus/networking-mobile

Usage

The following sections will outline how to use the various modules that are part of this package.

@exodus/networking-mobile/http + form

The React Native fetch implementation does not support a spec compliant FormData object. In order to have an API that is similar to what we are used to from the Browser, this module ships with its own FormData implementation.

To use it, import it and add data as you're used to:

import { FormData } from '@exodus/networking-mobile/form'

const formData = new FormData()
formData.append('name', 'Bruce Wayne')

// set is also available
formData.set('name', 'Batman')

// ...and many more: delete, get, getAll, entries, keys, values

As opposed to the Browser implementation, the RN FormData is not just a data container, but also knows how to serialize itself. Therefore the FormData implementation shipping with this module (which follows the Browser spec), cannot directly be used with RN's fetch.

To overcome this limitation, use the HttpClient that is part of this module. It comes with a fetch function that has the same signature as RN's fetch but can handle our FormData.

import { FormData, File } from '@exodus/networking-mobile/form'
import { createHttpClient } from '@exodus/networking-mobile/http'
import RNFS from '@exodus/react-native-fs'

const client = new createHttpClient({
  fs: RNFS,
  os: 'android',
  createUuid: uuidv4,
  hashString: shasum,
  logger,
})

const formData = new FormData()
formData.set('passport', new File(buffer, 'passport.jpg'))

await client.fetch('https://wayne.enterprises/upload', { method: 'POST', body: formData })

The client transforms FormData by writing files to the temporary folder, and appending the file URI, MIME type, and file name to an RN FormData object that is then passed to RN's fetch. Any temporarily created files are removed when the requests completes - successfully or otherwise.

Please note that the file used above is also provided by this module. It receives an object of type Buffer, a name, and optional properties to set the MIME type and last modified date. The MIME type takes no effect if used in conjunction with the HttpClient, since the client automatically derives the MIME type from the file extension.

@exodus/networking-mobile/cookie

The mobile CookieJar has to be instantiated with the platform it is running on.

import { CookieJar } from '@exodus/networking-browser/cookie'

const jar = new CookieJar('android')

A cookie can be removed by specifying its host and name (and optionally its path)

await jar.remove({ name: 'csrf', host: 'sub.domain.com' })

To get rid of all cookies, use the following:

await jar.removeAll()