An open API service indexing awesome lists of open source software.

https://github.com/untemps/user-permissions-utils

Collection of utility functions to manage user permissions
https://github.com/untemps/user-permissions-utils

permissions utils

Last synced: 3 months ago
JSON representation

Collection of utility functions to manage user permissions

Awesome Lists containing this project

README

        

# @untemps/user-permissions-utils

Collection of utility functions to manage user permissions.

![npm](https://img.shields.io/npm/v/@untemps/user-permissions-utils?style=for-the-badge)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/untemps/user-permissions-utils/index.yml?style=for-the-badge)](https://github.com/untemps/user-permissions-utils/actions)
![Codecov](https://img.shields.io/codecov/c/github/untemps/user-permissions-utils?style=for-the-badge)

## Installation

```bash
yarn add @untemps/user-permissions-utils
```

## Utils

`getPermission`:

Returns a promise resolved when the permission is granted

```javascript
import { getPermission } from '@untemps/user-permissions-utils'

const init = async () => {
try {
await getPermission('microphone')
...
} catch (error) {
console.error(error)
}
}
```

`getUserMediaStream`:

Returns a promise resolved when the permission is granted and the stream is retrieved

```javascript
import { getUserMediaStream } from '@untemps/user-permissions-utils'

const init = async () => {
try {
const stream = await getUserMediaStream('microphone', { audio: true })
if(!!stream) {
const audioContext = new AudioContext()
const streamNode = audioContext.createMediaStreamSource(stream)
...
} else {
console.error('Stream is not available')
}
} catch (error) {
console.error(error)
}
}
```

## Todos

- Add permissions-based API:
- clipboard
- geolocation
- notification
- ...
- Add commitlint to ensure commit logs are valid