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

ngx-ds-core

v0.0.12

Published

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.3.0.

Downloads

8

Readme

AngWorkspace

This project was generated with Angular CLI version 17.3.0.

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The application will automatically reload if you change any of the source files.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run ng e2e to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI Overview and Command Reference page.

Whats included?

The library inludes the following components.

1. DSAppService

How to use the service import the service

import { DSAppService } from  'ngx-ds-core';

use it in a component you want to send httprequest to. Below we have an example using the service to login.

constructor(
    private appService: DSAppService,
) { }

 async onSubmit(): Promise<void> {
    if (this.signInForm.valid) {
      const login = await this.appService.postItem<LoginDto>(
        `${environment.restBaseUrl}auth/login`,
        this.signInForm.value,
        false,
        false
      );
      if (login?.accessToken) {
        this.profileService.changeProfile(login);
        this.router.navigateByUrl('/customer');
      } else if (login?.redirectUrl) {
        this.appService.onMessageService.next({
          severity: 'secondary',
          summary: 'Reset Password',
          detail: 'Your password has expired, please insert a new password',
        });
        this.router.navigateByUrl(login.redirectUrl);
      } else {
        this.appService.onMessageService.next({
          severity: 'error',
          summary: 'Wrong Credentials',
          detail: 'User not found or your password is incorrect',
        });
      }
    } else {
    }
  }

In app.component.ts you should subscribe for the subject appService.onMessageService

constructor(
    private appService: DSAppService,
  ) {}

  ngOnInit() {
    // subscribe to message service
    this.appService.onMessageService.subscribe((message: Message) => {
        // the example below uses primeng message service. It will show a toast. 
        // you can replace it with your own message service. 
      this.messageService.add(message);
    });
  }
}

2. AuthInterceptor

The interceptor adds in each http request a bearer token. The interceptor looks for the token in localstorage with the key 'user'. The object saved with the 'user' key must have the jwt token named 'accessToken'

{
"accessToken": "jdfklasdjf...",
...
}

How to use the Auth Interceptor. import the interceptor

import { AuthInterceptor } from  'ngx-ds-core';

add it to providers (usually you want to add it to app.module.ts)

  providers: [
    { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
  ],

3. AuthGuard

This components protects the endpoints from being access if the user is not loggedin. AuthGuard checks in localstorage for the user object stored with the key 'user'. If the value for the key 'user' is null or undefined the authguard will trigger a redirect to the route 'auth/login' , otherwise will let the user to access the resource.

How to use it? import authguard.

import { authGuard } from  'ngx-ds-core';

protect the routes that you want.

export const routes: Routes = [
  {
    path: 'auth',
    component: BlankLayoutComponent,
    children: [
      {
        path: '',
        loadChildren: () => import('./pages/auth/auth.module').then(m => m.AuthModule),
      },
    ],
  },
  {
    path: 'overview',
    component: FullLayoutComponent,
    canActivate: [authGuard],
    children: [{ path: '', component: CustomerComponent }],
  },
 ]

4. Pipes

DateAgo Pipe. import the pipe

import { DateAgoPipe } from  'ngx-ds-core';

use it whenever you want to transform a date into a how long ago text compared to the actual date. this is an example how to use it.

<td>{{ tableData.updatedAt | dateAgo }}</td>

5. Global Functions

markFormGroupTouched(formGroup: FormGroup). Use this function when the form is not valid. This function will emphasise on the input that are not valid. This function will get called in case theres a nested form inside the formgroup.

/**
 * Marks all controls in a form group as touched
 * @param formGroup - The form group to touch
 */
export function markFormGroupTouched(formGroup: FormGroup) {
  Object.values(formGroup.controls).forEach(control => {
    if (control instanceof FormGroup) {
      markFormGroupTouched(control);
    } else if (control instanceof FormControl) {
      if (control.invalid) {
        control.markAsDirty();
        control.updateValueAndValidity({ onlySelf: true });
      }
    }
  });
}