{"id":25383243,"url":"https://github.com/paddls/ngx-common","last_synced_at":"2025-08-01T04:36:48.224Z","repository":{"id":38312906,"uuid":"265310366","full_name":"paddls/ngx-common","owner":"paddls","description":"A collection of useful features to enhance your Angular apps","archived":false,"fork":false,"pushed_at":"2025-03-31T17:35:35.000Z","size":1281,"stargazers_count":28,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T22:07:20.603Z","etag":null,"topics":["angular","rxjs","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@paddls/ngx-common","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paddls.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-19T17:07:09.000Z","updated_at":"2025-02-14T18:47:20.000Z","dependencies_parsed_at":"2024-06-21T15:19:34.889Z","dependency_job_id":"e11931c3-62ba-4eab-bfca-65783f082a7d","html_url":"https://github.com/paddls/ngx-common","commit_stats":{"total_commits":93,"total_committers":9,"mean_commits":"10.333333333333334","dds":0.6129032258064516,"last_synced_commit":"fe646092ddbe40427caffb7d37abee9c27057706"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddls%2Fngx-common","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddls%2Fngx-common/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddls%2Fngx-common/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddls%2Fngx-common/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paddls","download_url":"https://codeload.github.com/paddls/ngx-common/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125897,"owners_count":21051823,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","rxjs","typescript"],"created_at":"2025-02-15T08:01:15.942Z","updated_at":"2025-04-09T23:19:41.270Z","avatar_url":"https://github.com/paddls.png","language":"TypeScript","readme":"# NgxCommon\n\n![ngx-common-ci](https://github.com/paddls/ngx-common/workflows/ngx-common-build/badge.svg)\n[![npm version](https://badge.fury.io/js/%40paddls%2Fngx-common.svg)](https://badge.fury.io/js/%40paddls%2Fngx-common)\n![GitHub](https://img.shields.io/github/license/paddls/ngx-common)\n![GitHub repo size](https://img.shields.io/github/repo-size/paddls/ngx-common)\n![GitHub last commit](https://img.shields.io/github/last-commit/paddls/ngx-common)\n![GitHub issues](https://img.shields.io/github/issues/paddls/ngx-common)\n![GitHub top language](https://img.shields.io/github/languages/top/paddls/ngx-common)\n\n## Informations\n\n\u003e :warning: Since version 2.0.3, ```ngx-common``` and ```rxjs-common``` have been published under ```@paddls``` namespace. We continue to maintain ```@witty-services``` namespace, but now, ```ngx-common``` depends on ```@paddls/rxjs-common```\n\n| `Angular`          | `NgxCommon`       |\n|--------------------|-------------------|\n| `14.0.0` and above | `5.0.0` and above |\n| `13.0.0` and above | `4.0.0` and above |\n| `12.0.0` and above | `3.0.0` and above |\n| `6.0.0` and above  | `1.0.0` and above |\n\n## Summary\n\n* [How to install](#how-to-install)\n* [Get Started](#get-started)\n    * [@OnAttributeChange](#onattributechange)\n    * [takeUntilDestroy](#takeuntildestroy)\n    * [Error handling](#error-handling)\n    * [Configuration provider](#configuration-provider)\n    * [Local storage service](#local-storage-service)\n    * [@Log](#log)\n\n## How to install\n\n```\nnpm install --save @paddls/ngx-common\n```\n\n## Get Started\n\n### @OnAttributeChange\n\nDecorator ```@OnAttributeChange``` allow you to observe a class attribute with an observable.\n\nUsage:\n\n```typescript\nimport { takeUntilDestroy, OnAttributeChange } from '@paddls/ngx-common';\nimport { Observable } from 'rxjs';\n\nclass MyComponent {\n\n  public attribute: string;\n\n  @OnAttributeChange('attribute')\n  public myAttribute$: Observable\u003cstring\u003e; // emit value on each modification of the referent attribute\n\n  public constructor() {\n    this.myAttribute$.pipe(\n      takeUntilDestroy(this),\n    ).subscribe(() =\u003e {\n      // do some stuff\n    });\n  }\n}\n```\n\n### takeUntilDestroy\n\n`takeUntilDestroy` will automatically unsubscribe any `RxJS` subscription on component or directive destruction.\n\nUsage:\n\n```typescript\nimport { takeUntilDestroy, OnDestroyListener } from '@paddls/ngx-common';\nimport { interval } from 'rxjs';\n\n@OnDestroyListener()\nclass MyComponent {\n\n  public constructor() {\n    interval(100).pipe(\n      takeUntilDestroy(this), // this observable will be unsubscribed automatically on component destruction\n    ).subscribe();\n  }\n}\n```\n\n### Error handling\n\n`NgxErrorHandlerModule` provides a robust error handling mechanism to handle error through your Angular app.\n\nFirst, import `NgxErrorHandlerModule` in your root module :\n\n```typescript\nimport { NgxErrorHandlerModule } from '@paddls/ngx-common';\n\n@NgModule({\n  imports: [\n    NgxErrorHandlerModule.forRoot([\n      MyErrorHandler\n    ]),\n  ]\n})\nexport class AppModule {\n}\n```\n\nYou can register a list of error handlers in the `forRoot` method of the module.\n\nHere is an example of an error handler :\n\n```typescript\n@Injectable()\nexport class DefaultHttpErrorHandler implements ErrorHandler {\n\n  public handle(err: any): Observable\u003cany\u003e {\n    // DO SOMETHING\n\n    return throwError(err);\n  }\n\n  public canHandle(err: any): boolean {\n    return true; // Filter errors\n  }\n}\n```\n\nYou can specify as many handlers as you want. `handle()` methods will be called in order each time `canHandle()` method\nreturns `true`.\n\nTo handle any `RxJS` error, simply add the `handleError()` operator to your `Observable` :\n\n```typescript\nsource$.pipe(\n  handleError()\n).subscribe()\n```\n\n### Configuration provider\n\n`NgxConfigModule` provides a wrapper to inject any app config retrieved by `HTTP` into your app. To start, simply import\n`NgxConfigModule` in your root module :\n\n```typescript\nimport { NgxConfigModule } from '@paddls/ngx-common';\n\n@NgModule({\n  imports: [\n    NgxConfigModule.forRoot('https://my-config-url.com'),\n  ]\n})\nexport class AppModule {\n}\n```\n\nThen, each time you need your app config through your app, inject `NgxConfigService` :\n\n```typescript\nimport { NgxConfigService } from '@paddls/ngx-common';\n\n@Injectable()\nexport class MyService {\n\n  public constructor(configService: NgxConfigService) {\n    configService.getConfig('key').subscribe(console.log);\n    \n    console.log(configService.getConfigSnapshot('key'));\n  }\n\n}\n```\n\n### Local storage service\n\n`NgxLocalStorageModule` provides a wrapper to `localStorage` API that injects values into `RxJS` hot observables each time\na value is updated into the storage.\nTo start, simply import `NgxLocalStorageModule` in your root module :\n\n```typescript\nimport { NgxLocalStorageModule } from '@paddls/ngx-common';\n\n@NgModule({\n  imports: [\n    NgxLocalStorageModule.forRoot(),\n  ]\n})\nexport class AppModule {\n}\n```\n\nThen, use it like this :\n\n```typescript\nimport { NgxLocalStorageService } from '@paddls/ngx-common';\n\n@Injectable()\nexport class MyService {\n\n  public constructor(localStorageService: NgxLocalStorageService) {\n    localStorageService.get('key').subscribe(console.log); // 'value'\n    \n    localStorageService.set('key', 'value').subscribe(console.log); // 'value'\n    \n    localStorageService.remove('key');\n    \n    localStorageService.clear();\n  }\n\n}\n```\n\n### @Log\n\nDecorator ```@Log``` allows you to debug method without modifying internal code.\n\nUsage:\n\n```typescript\nimport { Log } from '@paddls/ngx-common';\nimport { environment } from '../../environment.ts';\n\nclass MyClass {\n\n  @Log()\n  public myMethod(): any {\n\n  }\n\n  @Log(!environment.production) // the log should be disabled on production\n  public myMethod(): any {\n\n  }\n\n  @Log(true, 'red') // override default log color\n  public myMethod(): any {\n\n  }\n}\n\nnew MyClass().myMethod();\n// =\u003e should log duration, class, method, args and returned value\n```\n","funding_links":[],"categories":["Third Party Components"],"sub_categories":["Mixed Utilities"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaddls%2Fngx-common","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaddls%2Fngx-common","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaddls%2Fngx-common/lists"}