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

simple-permissions

v5.0.1

Published

Trivial permissions implementation - takes an array and stores permissions from multiple targets for sources. 100% tested.

Downloads

20

Readme

Simple Permissions

Gitter
Trivial permissions implementation with following features

  • Many to many permissions (if you need one to many it is very easy to write some sort of wrapper)
  • Crossbrowser/Crossplatform
  • tested with ~100% coverage

Dependencies

  • Lodash

License

  • http://unlicense.org/

Installation:

bower install simple-permissions
npm install simple-permissions

Tests:

To launch tests you have to run npm install then npm test. If you want to contribute make sure to run grunt githooks first thing after clone. It will create pre-commit hook and run tests and jshint before you commit. Please use git flow - create a feature branch for your feature and send a pull request to dev. Please don't include dist folder in your commit.

API:

/**
 * @typedef {{target: String, source: String, permissions: Array}} SimplePermissions
 */

/**
 * Create/append permissions in a storage
 * @param {SimplePermissions[]} storage
 * @param {String|Array} to
 * @param {Object} permissionsMap
 */
function grant(storage, to, permissionsMap) {}

/**
 * Reduce/Remove permissions in a storage
 * @param {SimplePermissions[]} storage
 * @param {String|Array} from
 * @param {Object} permissionsMap
 */
function revoke(storage, from, permissionsMap) {}

Examples:

//one to many

var app = (function () {
	var permissions = [];

	return {
		permissions: permissions,
		grant: _.partial(grant, permissions, 'App'),
		revoke: _.partial(revoke, permissions, 'App')
	};
})();

app.grant({Admin: ['Read', 'Write', 'Email', 'Users'], User: ['Write', 'Read']});
console.log(_.map(app.permissions, function (entry) {
	return entry.source + ' - ' + entry.permissions.join(',')
}));
//["Admin - Read,Write,Email,Users", "User - Write,Read"]

app.revoke({User: ['Write']});
console.log(_.map(app.permissions, function (entry) {
	return entry.source + ' - ' + entry.permissions.join(',')
}));
//["Admin - Read,Write,Email,Users", "User - Read"]
//starting code
var Foo = {
		name: 'Foo',
		storage: []
	},
	s = Foo.storage;

///////////////////
// grant example //
///////////////////

//basic case
var str = 'whatever';
grant(s, Foo.name, {Bar: [str]});
var entry = _(s).find({target: Foo.name, source: 'Bar'});
//s.length === 1;
//entry.permissions[0] === str;

//works with multiple targets
var str = 'whatever';
grant(s, ['Bar', 'Baz', 'Qux'], {Foo: [str]});
var results = [
	_(s).find({target: 'Bar', source: Foo.name}),
	_(s).find({target: 'Baz', source: Foo.name}),
	_(s).find({target: 'Qux', source: Foo.name})
];
//s.length === 4;
//_.each(results, function (result) {
//	result.permissions[0] === str;
//});

//works with multiple permission rules
var str1 = 'anything';
var str2 = 'something else';
grant(s, 'Bar', {Foo: [str1], Baz: [str2]});
var result1 = _(s).find({target: 'Bar', source: Foo.name});
var result2 = _(s).find({target: 'Bar', source: 'Baz'});
//s.length === 5;
//result1.permissions[1] === str1;
//result2.permissions[0] === str2;

////////////////////
// revoke example //
////////////////////

//basic case
revoke(s, 'Foo', {Bar: ['whatever']});
//s.length === 4;
//_(s).find({target: Foo.name, source: 'Bar'}) === undefined;

//works with multiple permission rules
revoke(s, 'Bar', {Foo: ['anything'], Baz: ['something else']});
//s.length === 3
//_(s).find({target: 'Bar', source: Foo.name}).permissions[0] === 'whatever';
//_(s).find({target: 'Bar', source: 'Baz'}) === undefined;


// works with multiple targets
revoke(s, ['Bar', 'Baz', 'Qux'], {Foo: ['whatever']});
//s.length === 0

Analytics