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

https://github.com/miniscruff/scopie-js

JS implementation of scopie
https://github.com/miniscruff/scopie-js

Last synced: 9 months ago
JSON representation

JS implementation of scopie

Awesome Lists containing this project

README

          

# Scopie

[![NPM Version](https://img.shields.io/npm/v/scopie.svg?style=for-the-badge&logoColor=white)](https://www.npmjs.com/package/scopie)
[![NPM Downloads](https://img.shields.io/npm/dw/scopie?style=for-the-badge&logoColor=white)](https://www.npmjs.com/package/scopie)

Javascript implementation of [scopie](https://github.com/miniscruff/scopie).

Generated documentation can be viewed at [DOCS.md](./DOCS.md).

## Example

```js
import { isAllowed } from "scopie";

const users = {
elsa: {
rules: ["allow/blog/create|update"],
},
bella: {
rules: ["allow/blog/create"],
},
]
const blogPosts = {}

function createBlog(username, blogSlug, blogContent) {
const user = users[username]
if (isAllowed(["blog/create"], user.rules)) {
blogPosts[blogSlug] = {
author: user,
content: blogContent,
}
}
}

function updateBlog(username, blogSlug, blogContent) {
const user = users[username]
if (isAllowed(["blog/update"], user.rules)) {
blogPosts[blogSlug] = {
author: user,
content: blogContent,
}
}
}
```

```typescript
import { isAllowed } from "scopie";

type User = {
rules: Array;
};

type BlogPost = {
author: User;
content: string;
}

type UserStore = {
[key: string]: User
}

type BlogStore = {
[key: string]: BlogPost
}

const users: UserStore = {
elsa: {
rules: ["allow/blog/create|update"],
},
bella: {
rules: ["allow/blog/create"],
},
}

const blogPosts: BlogStore = {}

function createBlog(username: string, blogSlug: string, blogContent: string) {
const user = users[username]
if (isAllowed(["blog/create"], user.rules)) {
blogPosts[blogSlug] = {
author: user,
content: blogContent,
}
}
}

function updateBlog(username: string, blogSlug: string, blogContent: string) {
const user = users[username]
if (isAllowed(["blog/update"], user.rules)) {
blogPosts[blogSlug] = {
author: user,
content: blogContent,
}
}
}
```