# sunburst.js

> Sunburst API client library for Node.js, React Native, and in-browser JavaScript

Latest version **2.1.3** (published 2019-02-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install sunburst.js
pnpm add sunburst.js
yarn add sunburst.js
bun add sunburst.js
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.3 |
| Published | 2019-02-26 |
| First published | 2017-05-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=6.5 |
| Dependencies | 2 |
| Unpacked size | 75.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | SunsetWx, LLC. |
| Maintainers | umpc |
| Keywords | sunsetwx, api, sunsetwx api, sunburst, sunburst-js, client, client library, javascript, node, node.js, react-native, react native, sunrise, sunset, weather, prediction, geolocation, nature, color, photography, tourism |

## Links

- npm: https://www.npmjs.com/package/sunburst.js
- Repository: https://github.com/sunsetwx/sunburst.js
- Issues: https://github.com/sunsetwx/sunburst.js/issues
- npm.io page: https://npm.io/package/sunburst.js

## Dependencies (2)

- [npm](https://npm.io/package/npm.md) ^6.4.1
- [buffer](https://npm.io/package/buffer.md) ^5.1.0

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 2.1.3 (latest) — 2019-02-26
- 2.1.2 — 2018-11-02
- 2.1.1 — 2018-07-16
- 2.1.0 — 2018-07-16
- 2.0.0 — 2018-07-02
- 1.2.3 — 2018-05-13
- 1.2.2 — 2018-04-26
- 1.2.1 — 2018-04-26
- 1.2.0 — 2018-04-26
- 1.1.0 — 2018-04-25
- 1.0.0 — 2018-04-25
- 0.0.4 — 2017-07-15
- 0.0.3 — 2017-05-31
- 0.0.2 — 2017-05-30
- 0.0.1 — 2017-05-27

## README

# sunburst.js

### Sunburst API client library for JavaScript

This library provides authorization handling and methods for accessing the Sunburst API from [SunsetWx](https://sunsetwx.com/).

* Supports Node.js, React Native, and popular web browsers.

### Platform Support

Platform     | Version
------------ | -------
Node.js      | 6.5+
React Native | 0.54+

## Installation and usage

JavaScript in-browser script tag usage:

* Place `dist/sunburst.iife.js` into your website's files.

```html
<!-- The library is exposed as a global variable: SunburstJS -->
<script src="assets/js/sunburst.iife.js"></script>
```

Installation using npm:

```sh
npm i sunburst.js
```

Node.js 8.10+ usage:

```js
const SunburstJS = require('sunburst.js');
```

Node.js 6.5+ usage:

```js
const SunburstJS = require('sunburst.js/dist/sunburst.node.js');
```

Usage with React Native or your favorite module bundler:

```js
import SunburstJS from 'sunburst.js';
```

## Getting started

Create a session pair. Also known as `clientId` and `clientSecret`, which are our API keys:

```js
(async () => {
  try {
    const sunburst = new SunburstJS();

    const session = await sunburst.createSession({
      email: 'example@example.com',
      password: 'hunter2',
      type: 'permanent',
      scope: ['predictions']
    });
    console.log(session);
  } catch (ex) {
    // Handle general network or parsing errors.
    return console.error(ex);
  }
})();
```

Now you can make API requests:

```js
let sunburst = new SunburstJS({
  clientId: 'f78fe615-8eb1-48c4-be21-e5f4f437e8ba',
  clientSecret: '18qwl0htsPX|[!NGQ@[qK{X;[&^EVzaH',
  scope: ['predictions']
});
```

Here is an example of making four quality prediction requests:

```js
(async () => {
  try {
    const now = new Date();
    const thisTimeTomorrow = now.setDate(now.getDate() + 1);

    const resp = await sunburst.batchQuality([
      {
        geo: [40.7933949, -77.8600012],
        type: 'sunrise'
      },
      {
        geo: [40.7933949, -77.8600012],
        type: 'sunset'
      },
      {
        geo: [40.7933949, -77.8600012],
        type: 'sunrise',
        after: thisTimeTomorrow
      },
      {
        geo: [40.7933949, -77.8600012],
        type: 'sunset',
        after: thisTimeTomorrow
      }
    ]);

    resp.forEach(({ collection, error }) => {
      if (error) {
        // Handle individual query errors separately,
        // as some queries may have still succeeded.
        return console.error(error);
      }
      collection.features.forEach(({ properties }) => {
        console.log(properties);
      });
    });
  } catch (ex) {
    // Handle general network or parsing errors.
    return console.error(ex);
  }
})();
```

More examples, for each endpoint: [https://sunburst.sunsetwx.com/v1/docs](https://sunburst.sunsetwx.com/v1/docs?javascript=)

## License

The source code is available under the [ISC License](https://opensource.org/licenses/ISC).

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