# @alpakaio/alpaka-native-useragent

> User Agent builder used by Alpaka React Native apps

Latest version **1.1.0** (published 2019-10-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @alpakaio/alpaka-native-useragent
pnpm add @alpakaio/alpaka-native-useragent
yarn add @alpakaio/alpaka-native-useragent
bun add @alpakaio/alpaka-native-useragent
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-10-15 |
| First published | 2019-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Victoria French |
| Maintainers | phillrodgers, thomastuts, victoriafrench |
| Keywords | react-native, ios, android, windows, tvos, device, alpaka |

## Links

- npm: https://www.npmjs.com/package/@alpakaio/alpaka-native-useragent
- Repository: https://github.com/alpakaio/alpaka-native-useragent
- Homepage: https://github.com/alpakaio/alpaka-native-useragent#readme
- Issues: https://github.com/alpakaio/alpaka-native-useragent/issues
- npm.io page: https://npm.io/package/@alpakaio/alpaka-native-useragent

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2019-10-15
- 1.0.2 — 2019-10-14
- 1.0.1 — 2019-05-22
- 1.0.0 — 2019-05-22

## README

# alpaka-native-useragent

[![npm version](https://badge.fury.io/js/%40alpakaio%2Falpaka-native-useragent.svg)](https://badge.fury.io/js/%40alpakaio%2Falpaka-native-useragent)

User Agent builder used by [Alpaka](https://www.alpaka.io) [React Native](https://github.com/facebook/react-native) apps.

## TOC

* [Installation](#installation)
* [Usage](#usage)
* [API](#api)
* [Troubleshooting](#troubleshooting)
* [Release Notes](#release-notes)
* [react-native-dom / react-native-web](#react-native-dom)

## Installation

Using npm:

```shell
npm install --save @alpakaio/alpaka-native-useragent
```

> ⚠️ This package has a peer dependency of [React Native Device Info]() at version 2.0.0 or higher.

## Usage

```js
import UserAgent from '@alpakaio/alpaka-native-useragent';
```

## API

| Method                                                            | Return Type         |  iOS | Android | Windows | Since  |
| ----------------------------------------------------------------- | ------------------- | :--: | :-----: | :-----: | ------ |
| [getUserAgentAsync()](#getuseragentasync)                         | `Promise<string>`   |  ✅  |   ✅    |   ✅    | 1.0.0 |

### getUserAgentAsync()

Gets the appropriate user-agent string to use with Alpaka services.

**Examples**

```js
const userAgentString = await UserAgent.getUserAgentAsync(); 
// "Alpaka Punch; 1.0.0; b.17; en-GB; (Apple; iOS; 12.1; Handset; iPhone10,6)"
```

```js
UserAgent.getUserAgentAsync().then((userAgentString) => {
    // "Alpaka Punch; 1.0.0; b.17; en-GB; (Apple; iOS; 12.1; Handset; iPhone10,6)"
});
```

## Troubleshooting

When installing or using `alpaka-native-useragent`, you may encounter the following problems:

<details>
  <summary>[tests] - Cannot run my test suite when using this library</summary>

`alpaka-native-useragent` relies on `react-native-device-info` which contains native code, and needs to be mocked. Jest Snapshot support may work though.

Here's how to do it with jest for example:

```js
// in your package.json:
"jest": {
  "setupFiles": [
    "./testenv.js"
  ],


// testenv.js:
jest.mock('@alpakaio/alpaka-native-useragent', () => {
  return {
    getUserAgentAsync: jest.fn(),
  };
});
```

</details>

<details>
    <summary>[warnings] - dispatch_sync</summary>
    
Some of the APIs internally used will throw warnings in certain conditions like on tvOS or the iOS emulator. This won't be visible in production but even in development it may be irritating. It is useful to have the warnings because these devices return no state, and that can be surprising, leading to github support issues. The warnings is intended to educate you as a developer. If the warnings are troublesome you may try this in your code to suppress them:
    
```javascript
import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Required dispatch_sync to load constants for RNDeviceInfo']);
```
</details>

## Release Notes

See the [CHANGELOG.md](https://github.com/alpakaio/alpaka-native-useragent/blob/master/CHANGELOG.md).

## react-native-dom

This library was made compatible with [react-native-dom](https://github.com/vincentriemer/react-native-dom) and [react-native-web](https://github.com/necolas/react-native-web) by providing an empty polyfill in order to avoid breaking builds.

---
_Source: https://npm.io/package/@alpakaio/alpaka-native-useragent · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
