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

@tuhinkarmakar/relative-time

v1.0.1

Published

A relative time formatter for Angular.

Downloads

3

Readme

ng-relative-time npm version

A simple relative time formatter for Angular. Uses bleeding-edge formatting APIs for headache-free internationalization.

Table of Contents

Features

  • Internationalization: Formats strings using the browser's locale. Uses built-in browser APIs for internationalization. No setup required. The heavy-lifting is done by the browser.
  • Time Travelling Formatter: The formatter works with both past and future timestamps.

Installation

Run npm i @tuhinkarmakar/relative-time to install library into your project.

Usage

  1. First import the RelativeTimeModule in your root module.
import { BrowserModule } from "@angular/platform-browser"
import { NgModule } from "@angular/core"
import { RelativeTimeModule } from "@tuhinkarmakar/relative-time"   // <-- Import the module like this

import { AppComponent } from "./app.component"

@NgModule({
    declarations: [AppComponent],
    imports:      [BrowserModule, RelativeTimeModule],    // <-- Add it to the imports array
    providers:    [],
    bootstrap:    [AppComponent],
})
export class AppModule {}
  1. Use the relativeTime pipe with a datetime string accepted by the Date() constructor. See Date.parse() MDN page for supported formats.
{{ timestamp | relativeTime }} // Output: yesterday / tomorrow / 5 seconds ago / in 5 months etc.

Browser Support

Since the library uses Intl.RelativeTimeFormat, it only works on Google Chrome 71+ and Mozilla Firefox 65+. Browser support will get better as more vendors start implmenting the proposal.

See this MDN page for details.

Task List

  • [ ] Add supoort for Schemantics
  • [ ] Add a declaration file for Intl.RelativeTimeFormat

Contributing

Report bugs and share enhancement ideas here. PRs are also welcome.