ngx-humanize-duration

[![npm version](https://badge.fury.io/js/ngx-humanize-duration.svg)](https://badge.fury.io/js/ngx-humanize-duration)   ![Build](https://github.com/george3447/ngx-humanize-duration/workflows/Build/badge.svg?branch=master)

Stats

StarsIssuesVersionUpdatedCreatedSize
ngx-humanize-duration
511.2.52 years ago2 years agoMinified + gzip package size for ngx-humanize-duration in KB

Readme

Angular Humanize Duration

npm version   Build

Angular wrapper for Humanize Duration library. Provides Angular pipe and service.

Installation

npm install humanize-duration ngx-humanize-duration

Quick Start

Import ngx-humanize-duration module in Angular app.

import { NgxHumanizeDurationModule } from 'ngx-humanize-duration';

@NgModule({
  imports: [
    NgxHumanizeDurationModule
  ],
})

Usage

With pipe in templates

<p>
  {{ yearInMillieSeconds | humanizeDuration:{ delimiter: ' and ', largest:2 } }}
</p>

With a service

import {
  NgxHumanizeDurationOptions,
  NgxHumanizeDurationService,
} from "ngx-humanize-duration";

@Injectable({
  providedIn: "root",
})
export class MyService {
  constructor(private ngxHumanizeDurationService: NgxHumanizeDurationService) {}

  humanizeDuration(value: number, options?: NgxHumanizeDurationOptions) {
    return this.ngxHumanizeDurationService.humanizeDuration(value, options);
  }
}

Advanced Usage

If you find yourself setting same options over and over again, you can set the defaults using forRoot method, which you can still override at Module or Component or Service level

import { NgxHumanizeDurationModule, NgxHumanizerOptions } from 'ngx-humanize-duration';

const defaults: NgxHumanizerOptions = {};

@NgModule({
  imports: [
    NgxHumanizeDurationModule.forRoot(defaults)
  ],
})

If you have Lazy Loaded modules and you want to use the defaults that you have set using above method, just import the NgxHumanizeDurationModule

import { NgxHumanizeDurationModule, NgxHumanizerOptions } from 'ngx-humanize-duration';

const defaults: NgxHumanizerOptions = {};

@NgModule({
  imports: [
    NgxHumanizeDurationModule
  ],
})

If you want to override the defaults at Module Level

import { NgxHumanizeDurationModule, NgxHumanizerOptions } from 'ngx-humanize-duration';

const moduleLevelOptions: NgxHumanizerOptions = {};

@NgModule({
  imports: [
    NgxHumanizeDurationModule.forFeature(moduleLevelOptions)
  ],
})

If you want to override the defaults at Component level

<p>
  {{ yearInMillieSeconds | humanizeDuration:{ componentLevelOptions } }}
</p>

If you want to override the defaults at Service level

import { NgxHumanizeDurationService } from "ngx-humanize-duration";

@Injectable({
  providedIn: "root",
})
export class MyService {
  constructor(private ngxHumanizeDurationService: NgxHumanizeDurationService) {}

  humanizeDuration() {
    const humanizedDuration = this.ngxHumanizeDurationService.humanizeDuration(
      value,
      newOptions
    );
  }
}

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.