npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pemi

v1.0.6

Published

permission map

Downloads

168

Readme

用户权限值映射到16进制,用于缩小数据传输与保存时使用更小的空间

安装

npm i --save pemi
import { Permission, Module } from 'pemi'

const Sys = {
  View: { id: 'Sys.V', position: 1 }
}
const Log = {
  View: { id: 'Log.V', position: 1 },
  Create: { id: 'Log.C', position: 2 },
  Update: { id: 'Log.U', position: 3 },
  Delete: { id: 'Log.D', position: 4 }
}

const permission = new Permission(
  [new Module('Sys', Sys), new Module('Log', Log)]
)

权限位结构

interface Position {
  id?: string
  name?: string
  disabled?: boolean
  position: number
}

设置授权

permission.permit(['Log.V', 'Log.D'])
or
permission.permit({Sys: '0', Log: '9'})

判断是否有某一具体权限

permission.has(Log.View)
结果:
true
permission.has(Log.Create)
结果:
false

获取某一个权限块的权限具体结果

permission.get('Log')
结果:
{View: true, Create: false, Update: false, Delete: true}

将权限值转为16进制

permission.hexify()
结果:
{Sys: '0', Log: '9'}

或者获取所有有权限的id值

permission.arrayify()
结果:
['Log.V', 'Log.D']

后端可用16进制值进行保存或者去redis缓存,减少服务器内存消耗

  • permission.has: (permit: string | {id: string}) 判断是否有指定某一项权限
  • permission.any: (ary: string[]) 判断是否有指定任意一项权限
  • permission.all: (ary: string[]) 判断是否有指定的全部一项权限

如果需要控制权限定义及权限是否正常匹配等错误信息,可以new Permission(modules, { logger: console })