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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ngx-guardian

v1.1.6

Published

<p align="center"> <img src="https://raw.githubusercontent.com/rjlopezdev/ngx-guardian/master/ngx-guardian-logo.svg?sanitize=true" alt="Ngx Guardian logo" width="200" height="200"> <p align="center"> Logo designed by <a href="https://www.behance.net/y

Readme

Ngx Guardian is a minimal, powerfull and easy configurable permission manager that grant the power to manage different roles in your Angular project.

Summary

Installation

Using Angular CLI

ng add ngx-guardian

Using npm

Setup

In your App Module:

@NgModule({
    declarations: [. . .],
    providers: [. . .],
    imports: [
        NgxGuardianModule.forRoot({
            // Set up your managers here (see Permission specification)
            managers: [
                fooPermissionManager,
                otherFooPermissionManager,
                ...
            ],
            // Manager role to set its manager as default
            defaultRole: Role.ROLE_NAME,
            // Set a manager by localStorage value (see below)
            setFromStorage: true,
            // Navigate to this route if no role set
            unauthorizedRoute: '/no-auth',
            // Navigate to this route if user is no granted for route
            noGrantedRoute: '/no-granted'
        })
    ],
    exports: [. . .]
})
export class AppModule { }

You can delegate default manager setup to NgxGuardian setting a role in localStorage:

localStorage.setItem('ngx-guardian-role', 'ROLE_NAME');

forRoot() Config

| Name | Type | Default | Required | Description | | --- | :---: | :---: | :---: | --- | | managers | NgxGuardianManager[] | - | :heavy_check_mark: | Permission Managers for application (with roles & actions over resources) | defaultRole | string | - | - | Default role to set its manager (if no provided, manager is disabled) | setFromStorage | boolean | false | - | Set role by localStorage value | unauthorizedRoute | string | "no-auth" | - | Route to navigate if no manager set | noGrantedRoute | string | "no-granted" | - | Route to navigate if user has no permissions

Manager preference setup

As there are different strategies to configure the default manager, the following priority has been established:

  1. setFromLocalStorage has priority over defaultRole strategie.
  2. If no setFromLocalStorage strategie is provided, default manager will be set with defaultRole strategie.
  3. If no set manager strategie is provided, the permission manager will be disabled.

Proposed files structure

├── src
    └── ngx-guardian
        ├── ngx-roles.ts
        ├── ngx-permissions.ts
        ├── ngx-resources.ts
        ├── ngx-config.ts
        ├── ngx-foo-manager.ts
        ├── ...
        └── ngx-other-foo-manager.ts

Permission specification

  1. Define your roles
// ngx-roles.ts

export enum NgxGuardianRole {
    ADMIN = 'ADMIN',
    DEFAULT = 'DEFAULT',
    ONLY_VIEW = 'ONLY_VIEW'
}
  1. Define your actions
// ngx-actions.ts

export enum NgxGuardianAction {
    CREATE = 'CREATE',
    READ = 'READ',
    UPDATE = 'UPDATE',
    DELETE = 'DELETE',
    APPROVE = 'APPROVE',
    REJECT = 'REJECT'
}
  1. Define your resources
// ngx-resources.ts

import { NgxGuardianResource } from 'ngx-guardian';

export const FOO: NgxGuardianResource = {
    name: 'FOO',
    routes: []
};

export const PIZZA: NgxGuardianResource = {
    name: 'PIZZA',
    routes: []
};
  1. Define your permission managers
//ngx-foo-manager.ts

import { NgxGuardianManager } from 'ngx-guardian';
import { NgxGuardianRole } from './ngx-role';
import { FOO, PIZZA } from './ngx-resources';
import { NgxGuardianAction } from './ngx-permissions';

export const defaultManager: NgxGuardianManager = {
    role: NgxGuardianRole.ADMIN,
    permissions: [
        {
            FOO,
            actions: [
                NgxGuardianAction.CREATE,
                NgxGuardianAction.READ
            ]
        },
        {
            resource: PIZZA,
            actions: [
                NgxGuardianAction.CREATE,
                NgxGuardianAction.READ
            ]
        }
    ]
}

Directives usage

The purpose of ngx-guardian directives is to simplify the logic of the templates designed to show, hide or modify the components or HTML code blocks according to permissions or user roles.

ShowIfGranted

This directive shows or hides a html block or component depending on whether a user has permission over a specific resource.

<!-- This component will be shown ONLY IF user has CREATE permission over PIZZA resource -->
<component-to-show-or-hide *ngxShowIfGranted="'CREATE - PIZZA'">
</component-to-show-or-hide>

<!-- This html block will be shown ONLY IF user has READ permission over PIZZA resource -->
<div *ngxShowIfGranted="'READ - PIZZA'">
    <p> Paragraph intended for users with READ permissions over pizza </p>
</div>

DisableIfNoGranted

This directive enable or disable a html block or component depending on whether a user has permission over a specific resource.

<!-- This component will be set disabled IF user HAS NOT CREATE permission over PIZZA resource -->
<component-to-enable-or-disable ngxDisableIfNoGranted="'READ - PIZZA'">
</component-to-enable-or-disable>

<!-- This html block will be set disabled IF user HAS NOT READ permission over PIZZA resource -->
<button ngxDisableIfNoGranted="'UPDATE - PIZZA'">
    Update pizza toppings
</button>

Service usage

The purpose of the Permission Service is to offer an interface for communication with the permission manager.

| Method | Signature | Output | Description | | --- | :---: | :---: | --- | isGranted | (action: string, resource: string) | boolean | If user can perform an action over resource | disableManager | - | - | Disable default permission manager | setManagerByRole | (role: string) | boolean | Set current manager for role provided | canNavigateTo | (url: string) | boolean | Returns if the user is granted to navigate to the path provided