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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@okode/ngx-common

v1.6.4

Published

Okode Common for Ionic 4+ projects.

Readme

@okode/ngx-common

Okode Common for Ionic 4+ projects.

Install package in client App

npm i @okode/ngx-common

Usage

In app/core module:


import { NgModule } from '@angular/core';
import { OkodeNgxCommonModule } from '@okode/ngx-common';
import { IonicStorageModule } from '@ionic/storage';
import { HttpClientModule } from '@angular/common/http';

@NgModule({
  imports: [
    IonicStorageModule.forRoot(), // Required
    HttpClientModule, // Required
    OkodeNgxCommonModule.forRoot(),

Services

Environment

This service allows the selection of environment config before starting the app. It requires that the file src/assets/environments.json exists in the project:

{
  "default": {
    "version": "0.1.100",
    "versionCode": "1100"
  },
  "dev": { "envName": "dev", [...] },
  "pre": { "envName": "pre", [...] },
  "pro": { "envName": "pro", [...] },
  ...
}

If only default and other environment exist, the selector will not appear.

Usage

Access to environment config value:

import { Environment } from '@okode/ngx-common';
console.log('Selected environment', Environment.config().envName);

Navigator

Ionic NavController wrapper with custom transitions

Functions
push(url: string, params?: {}, animation: 'default' | 'push' | 'modal' | 'fade' | 'safepush' = 'default', startNavFlow = false): Promise<boolean>
pop(url?: string, params?: {}): Promise<boolean>
popToRoot(): Promise<boolean>
setRoot(url: string, params?: {}): Promise<boolean>
closeCurrentNavFlow(params?: {}) 
getParams(): any
getViews(): RouteView[] // RouteView: @ionic/angular interface
setDefaultAnimation(animation: 'default' | 'push' | 'modal' | 'fade' | 'safepush')

default animation in iOS performs push, and modal in Android (default native behavior)

safepush is a simple push animation alternative for custom designs where the original can give bugs

It is possible to open a new navigation flow startNavFlow as true in push(), this allows to return to previous page at any moment calling closeCurrentNavFlow()

Usage
import { Navigator } from '@okode/ngx-common';
constructor(private nav: Navigator) {}
ngOnInit() {
  console.log('Nav params:', this.nav.getParams());
}
navToDetail(id: number) {
  this.nav.push(`/foo/detail/${id}`);
}

HardwareBackButton

This service allows you to control the behavior of the Android physical button. If is enabled will try to pop() current view via Navigator if no Ionic overlay presented (alert, action-sheet, loading). It is not initialized when importing the module, it is necessary to call the enable() function when starting if you want to use it.

Functions
enable(condition?:() => boolean)
disable()

condition (optional) is a filter function that allows to customize behavior and determine (with boolean return value) if continue with the default behavior or not.

It's possible to customize behavior of hardware back on a particular page implementing OnHardwareBackButton inferface.

Usage
import { HardwareBackButton } from '@okode/ngx-common';
constructor(private hardwareBackButton: HardwareBackButton) {}
this.hardwareBackButton.enable();

OnHardwareBackButton inferface:

import { OnHardwareBackButton } from '@okode/ngx-common';
export class MyPage implements OnHardwareBackButton {
kdOnHardwareBackButton() { /* overwrite back button behavior () on this page */ }

HttpCacheInterceptor

Allows caching GET responses (temporally in memory)

Register provider in app @NgModule

  { provide: HTTP_CACHE_INTERCEPTOR_DURATION_MINS, useValue: 5 },
  { provide: HTTP_INTERCEPTORS, useClass: HttpCacheInterceptor, multi: true },

HTTP_CACHE_INTERCEPTOR_DURATION_MINS (minutes number) is optional, default: null (temporal cache in memory not expires)

Add header to services that you want to cache (applies in GETs)

  headers = headers.append('X-NGX-CACHE-INTERCEPTOR', 'cache-response');

X-NGX-CACHE-INTERCEPTOR header will not be sent to the server

Clear all cache responses (applies in all HTTP methods)

  headers = headers.append('X-NGX-CACHE-INTERCEPTOR', 'clear-cache');

Important: X-NGX-CACHE-INTERCEPTOR header will not be sent to the server

SentryErrorHandler

SentryErrorHandler service for Angular ErrorHandler provide

Usage

In app/core module:

import { NgModule, ..., ErrorHandler } from '@angular/core';
import { SentryErrorHandler } from '@okode/ngx-common';

@NgModule({
  providers: [
    ...
    { provide: ErrorHandler, useClass: SentryErrorHandler }

In app init

import { SentryErrorHandler } from '@okode/ngx-common';
...
SentryErrorHandler.init(dsn, release, environment, ignoreErrors?);
Functions
static init(dsn: string, release: string, environment: string, ignoreErrors = [])
static sendServerError(error: HttpErrorResponse) // HTTP ERROR WARNING
static sendServerErrorHandled(error: HttpErrorResponse, errorCode: string) // HTTP ERROR DEBUG
static sendCustomError(title: string, level: Sentry.Severity, transaction: string, error: any)
handleError(error) // base function override

MMobileService

Usage

Plugin '@ionic-native/device/ngx' required

import { MMobileService } from '@okode/ngx-common';
import { Device } from '@ionic-native/device/ngx';

@NgModule({
  imports: [
  providers: [
    ...
    Device, // Required
    MMobileService
Functions
init(baseUrl: string, appName: string, version: string, jwtConfigName?: string, timeoutMillis?: number)
//
reloadConfig()
getCustomConfig()
getServiceUrl(key: string)
getJwtLoginUrl()
getJwtRefreshUrl()
getVersion()
getTimeout()
isActive() {
getFeatures()
isDeviceLocked()isInitialized()
async getLastUpdatedDate()