open-index/open-npm huggingface dataset:
npm package: @rray/oauth2
Description: A very simple OAuth2 implementation
Author: Nikita Skovoroda
Latest version: 1.0.0

# `@rray/oauth2`

A very simple OAuth2 implementation

## Global `fetch` expectation

Note: this package expects a global `fetch` to be set, which is present on newer Node.js versions.

It can be polyfilled with `node-fetch`, for example.

## Usage

```js
import { OAuth2 } from './oauth2.mjs'

// provides { full_auth_url, async auth(code) }
const oauth = OAuth2('google', { g_client_id, g_client_secret, g_redirect_uri })

server.get('/oauth', (req, res) => res.redirect(oauth.full_auth_url))

server.get('/oauth/callback', async (req, res) => {
  const userinfo = await oauth.auth(req.query.code)
  ...
})
```

## Providers support

Currently two providers have built-in support: `'google'` and `'yandex'`.

In order to use this with another provider, just pass in the corresponding provider object manually:

```js
const provider = { ... }
const oauth = OAuth2(provider, { client_id, client_secret, redirect_uri })
```

See [providers list](./providers.mjs) for the structure of the `provider` object.

## License

[MIT](./LICENSE)
npm package: @rrc-npm/r-hooks
Description: React custom hooks
Author: Rijosh
Latest version: 1.0.7

# React Custom Hooks

## Installation

    npm i @rrc-npm/r-hooks

or

    yarn add @rrc-npm/r-hooks

## Hooks

### useOutsideClick - [demo](https://codesandbox.io/s/useoutsideclick-8xh5e)

---

Trigger the callback function on clicking outside the referenced element.

```
// import from the package
import {useOutsideClick} from "@rrc-npm/r-hooks";

export default function Demo() {
    // define the ref
    const demoRef = useRef();

    // Handle clicking outside the element
    useOutsideClick(demoRef, () => {
        // your code
    });

    return (
        <div className="demo" ref={demoRef}>
            //....
        </div>
    );
}
```

### useEventListener - [demo](https://codesandbox.io/s/useeventlistener-jl35i)

---

Hook for handling any Javascript events.

```
useEventListener("mousedown", () => {
    // ... your code
});
```

### useLocalStorage - [demo](https://codesandbox.io/s/uselocalstorage-919mf)

---

Extended `useState` hook to keep data in the browser's `localStorage`. It can be used when a state needs to persist even after reloading the browser.

```
const [state,setState] = useLocalStorage(KEY,INITIAL_VALUE)
```

The `KEY` will be using as the key in the localStorage.

### useOnlineStatus - [demo](https://codesandbox.io/s/useonlinestatus-il29l)

---

Hook to check the network status and trigger the callback function if online.

```
    // get the status
    const isOnline = useOnlineStatus();

    // trigger on changing the status
    useEffect(() => {
        if (isOnline) console.log("You're online");
    }, [isOnline]);
```

### useUpdateEffect - [demo](https://codesandbox.io/s/useupdateeffect-qdn49)

---

An extended `useEffect` hook for triggering on updates not for initial rendering.

```
useUpdateEffect(() => {
    console.log("Updated");
}, [dependency]);
```

### useQueryState - [demo](https://codesandbox.io/s/usequerystate-n43wk)

---

Hook to create a persisting state same like `useLocalStorage`, but the data is added to the URL queries instead of local storage. It will be helpful if you need to share a URL with data filled.

```
const [state, setState] = useQueryState(KEY,INITIAL_VALUE);
```

The `KEY` will be using as the key in the URL query.

### useHashState - [demo](https://codesandbox.io/s/usehashstate-g510j)

---

This hooks is same like the `useQueryState`, but instead the query parameters, it is using the hash URLs.

```
const [state, setState] = useHashState(KEY,INITIAL_VALUE);
```

### useReadonly - [demo](https://codesandbox.io/s/usereadonly-epl5t)

---

This hook will keep a state as readonly. It can be used to compare the initial value of a changing state.

```
const initialState = useReadonly(name);
```