# react-native-package

> Provides a consistent format to define and export packages for React Native.

Latest version **2.6.2** (published 2017-09-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-package
pnpm add react-native-package
yarn add react-native-package
bun add react-native-package
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.6.2 |
| Published | 2017-09-03 |
| First published | 2017-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Mark Miyashita |
| Maintainers | negativetwelve |
| Keywords | dx, module, native, package, react-native |

## Links

- npm: https://www.npmjs.com/package/react-native-package
- Repository: https://github.com/negativetwelve/react-native-package/tree/master/packages/react-native-package
- Homepage: https://github.com/negativetwelve/react-native-package
- npm.io page: https://npm.io/package/react-native-package

## Dependencies (2)

- [react-native-module-check](https://npm.io/package/react-native-module-check.md) ^2.6.2
- [react-native-module-guard](https://npm.io/package/react-native-module-guard.md) ^2.6.2

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 2.6.2 (latest) — 2017-09-03
- 2.6.1 — 2017-08-31
- 2.6.0 — 2017-08-27
- 2.5.0 — 2017-08-23
- 2.4.1 — 2017-08-22
- 2.4.0 — 2017-08-22
- 2.3.0 — 2017-08-22
- 2.2.0 — 2017-08-22
- 1.3.0 — 2017-08-16
- 1.2.0 — 2017-08-15
- 1.1.0 — 2017-08-14
- 1.0.0 — 2017-08-14

## README

# react-native-package

[![npm](https://img.shields.io/npm/v/react-native-package.svg)](https://www.npmjs.com/package/react-native-package)
[![npm](https://img.shields.io/npm/dt/react-native-package.svg)](https://www.npmjs.com/package/react-native-package)
[![npm](https://img.shields.io/npm/l/react-native-package.svg)](https://github.com/negativetwelve/react-native-package/blob/master/LICENSE)

Provides a consistent format to define and export packages for React Native.

## Getting Started

Install `react-native-package` using `yarn`:

```shell
yarn add react-native-package
```

## Motivation

This package (pun intended) addresses several issues when creating a NativeModule for React Native:

1. Consistent way of checking if a NativeModule was installed correctly.
2. Allows 'guarding' a module on a platform that it has not been implemented on yet.
3. Helpful error messages when a module has not been implemented on a platform.

## Usage

This is an example from the `react-native-instabug-sdk` which was the motivation for this package.

```javascript
import {Platform} from 'react-native';
import Package from 'react-native-package';


export default Package.create({
  json: require('./package.json'),
  nativeModule: NativeModules.RNInstabugSDK,
  enabled: Platform.select({
    ios: true,
  }),
  export: (Instabug) => ({
    // Constants that this module exports.
    events: {
      ...
    },
    modes: {
      ...
    },

    // All methods that this NativeModule is supposed to export:
    startWithToken: (token, event) => Instabug.startWithToken(token, event),
  }),
});
```

Using values from the `package.json`, we can record a consistent warning if we determine this package was not installed correctly:

> Warning: react-native-instabug-sdk was not installed correctly. Please follow the instructions in the README: https://github.com/negativetwelve/react-native-instabug-sdk#readme.

It will also record a message if the Package is not enabled on the current platform:

> Warning: react-native-instabug-sdk does not currently have an implementation for Android. If you would like to contribute, please submit a PR to https://github.com/negativetwelve/react-native-instabug-sdk.

But, calling a method on that platform, Android in this case, such as:

```javascript
import React from 'react';
import Instabug from 'react-native-instabug-sdk';


export default class App extends React.Component {
  componentDidMount() {
    Instabug.startWithToken(TOKEN, EVENT);
  }

  render() {
    return (
      <Text>Testing Instabug</Text>
    );
  }
}
```

will not error! :tada:

## Contributing

If you have any ideas on how this module could be better, [create an Issue](https://github.com/negativetwelve/react-native-package/issues) or [submit a PR](https://github.com/negativetwelve/react-native-package/pulls).

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