<commit_before># roles-npm
A user authorization library, integrates with MongoDB back-end, ported from Meteor accounts.

Based on the [Meteor roles package Version 1.2.15](https://github.com/alanning/meteor-roles/tree/4c64ea0b24fec774279cb472b2d4205ec8048ef8).

## Usage

```js
import Roles from '@alanning/roles'
import { MongoClient } from 'mongodb'

// MongoDB connection
const db = await MongoClient.connect(MONGO_URL)
// Pass the users and roles collection to the Roles constructor
const roles = new Roles({
    users: db.collection('users')
    roles: db.collection('roles')
})
```

The roles instance has all the methods documented [here](http://alanning.github.io/meteor-roles/classes/Roles.html).

## Build

```sh
npm run build
```

## Testing

Start your local MongoDB server:

```sh
mongod
```

Then:

```sh
npm test
```

A `roles-npm` database will be used during testing.  Feel free to delete that database after the tests are run.<commit_msg>include npm install and await examples<commit_after># roles-npm
A user authorization library, integrates with MongoDB back-end, ported from Meteor accounts.

Based on the [Meteor roles package Version 1.2.15](https://github.com/alanning/meteor-roles/tree/4c64ea0b24fec774279cb472b2d4205ec8048ef8).

## Usage

In the directory with your project's `package.json`:
```sh
npm install @alanning/roles --save
```

In your app code:
```js
import Roles from '@alanning/roles'
import { MongoClient } from 'mongodb'

// MongoDB connection
const db = await MongoClient.connect(MONGO_URL)
// Pass the users and roles collection to the Roles constructor
const roles = new Roles({
    users: db.collection('users')
    roles: db.collection('roles')
})
const isAuthorized = await roles.userIsInRole(loggedInUser, 'manager', 'acme')  
```

The roles instance has all the methods documented [here](http://alanning.github.io/meteor-roles/classes/Roles.html).

## Build

```sh
npm run build
```

## Testing

Start your local MongoDB server:

```sh
mongod
```

Then:

```sh
npm test
```

A `roles-npm` database will be used during testing.  Feel free to delete that database after the tests are run.
{'fraction_non_alphanumeric': 0.11522248243559718, 'fraction_numerical': 0.027166276346604217, 'mean_word_length': 4.621052631578947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '994421', 'n_tokens_mistral': 760, 'n_tokens_neox': 675, 'n_words': 228}