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

timeagoplus

v0.1.5

Published

A utility library for calculating time differences and formatting them in various languages.

Downloads

5

Readme

timeagoplus

timeagoplus is a WebAssembly (Wasm) package that provides a utility to calculate and display the time elapsed since a given timestamp in a human-readable format. It supports multiple languages.

Features

  • Calculates the time elapsed since a given timestamp.
  • Supports detailed labels (e.g., "1 year, 2 months ago").
  • Multi-language support.

Installation

Install the package via npm:

npm install timeagoplus

Usage

Below are examples of how to use the timeagoplus package in both a React component and a plain JavaScript file.

React Example

First, make sure you have installed the timeagoplus package:

npm install timeagoplus

Now, here's how you can use it in a React component:

import React, { useState, useEffect } from 'react';
import init, { TimeAgo, Language } from 'timeagoplus';

const HomePage: React.FC = () => {
  const [time, setTime] = useState('');

  useEffect(() => {
    let intervalId: NodeJS.Timeout;

    // Initialization (Runs Only Once)
    init().then(() => {
      // Create a TimeAgo instance with default language and detailed label
      const timeAgo = new TimeAgo(Language.TRK);

      // Example using timestamp
      setTime(timeAgo.format(new Date().getTime())); // "now"

      // Update Logic (Runs every second)
      intervalId = setInterval(() => {
        setTime(timeAgo.format(new Date('2024-06-27T20:00:00+03:00')));
      }, 1000); // Update every second
    });

    // Cleanup (Runs when the component unmounts)
    return () => clearInterval(intervalId);
  }, []);

  return <div>{time}</div>;
};

export default HomePage;

JavaScript Example

For plain JavaScript, make sure to also install the timeagoplus package:

npm install timeagoplus

Here's how you can use it in a simple HTML file:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>TimeAgoPlus Example</title>
  </head>
  <body>
    <div id="time"></div>
    <script type="module">
      import init, { TimeAgo, Language } from 'timeagoplus';

      document.addEventListener('DOMContentLoaded', async () => {
        await init();
        const timeAgo = new TimeAgo(Language.TRK);

        // Example using timestamp
        document.getElementById('time').textContent = timeAgo.format(
          new Date().getTime()
        ); // "now"

        // Update Logic (Runs every second)
        setInterval(() => {
          document.getElementById('time').textContent = timeAgo.format(
            new Date('2024-06-27T20:00:00+03:00')
          );
        }, 1000); // Update every second
      });
    </script>
  </body>
</html>

Both examples initialize the timeagoplus package, create a TimeAgo instance, and set up an interval to update the displayed time every second. The React example uses React hooks, while the JavaScript example uses plain DOM manipulation.

Supported Languages

The Language enum provides a wide range of languages you can use.

| Language Code | Language Name | | ------------- | ----------------------- | | ACM | Mesopotamian Arabic | | AEC | Saidi Arabic | | AEB | Tunisian Arabic | | AMH | Amharic | | APC | North Levantine Arabic | | APD | Samar-Leyte Visayan | | ARQ | Algerian Arabic | | ARS | Najdi Arabic | | ARY | Moroccan Arabic | | ARZ | Egyptian Arabic | | ASM | Assamese | | AWD | Awadhi | | AYN | Northern Altai | | AZB | South Azerbaijani | | AZE | Azerbaijani | | BGC | Haryanvi | | BHJ | Bhojpuri | | BLG | Bulgarian | | BMS | Javanese | | BNG | Bengali | | CEB | Cebuano | | CFR | Crimean Tatar | | CHN | Mandarin Chinese | | CJY | Jinyu Chinese | | CIT | Citak | | CCX | Northern Luri | | CZC | Czech | | DCC | Dakhini | | DUT | Dutch | | ENG | English | | FRN | French | | FUV | Nigerian Fulfulde | | GAZ | West Central Oromo | | GER | German | | GJR | Gujarati | | GRK | Greek, Modern (1453-) | | HAK | Hakka Chinese | | HAT | Haitian; Haitian Creole | | HIL | Hiligaynon | | HND | Hindi | | HNE | Chhattisgarhi | | HNG | Hungarian | | HSN | Xiang Chinese | | HUA | Mandarin Chinese | | IGR | Igbo | | ILO | Iloko | | INZ | Indonesian | | ITN | Italian | | JAN | Javanese | | JPN | Japanese | | KAZ | Kazakh | | KJV | Kannada | | KKN | Kokni | | KMR | Khmer | | KNN | Gan Chinese | | KUR | Central Kurdish | | LMO | Lombard | | MEX | Mexican Spanish | | MJS | Malaccan Creole Malay | | MKD | Macedonian | | MKP | Mohawk | | MHJ | Mahajani | | MLI | Malayalam | | MNP | Manipuri | | MQM | Macaense | | MRT | Marathi | | NEP | Nepali | | NPL | Nepali | | ORY | Odia | | PBT | Southern Pashto | | PBU | Northern Pashto | | PES | Western Farsi | | PNJ | Eastern Panjabi | | PNB | Western Panjabi | | PQL | Pomeranian | | POR | Portuguese | | PRS | Eastern Farsi | | RUA | Kinyarwanda | | RUM | Romanian | | RUS | Russian | | RUW | Kinyarwanda | | SHD | Kundal Shahi | | SKR | Saraiki | | SNH | Sinhala | | SND | Sindhi | | SOM | Somali | | SPN | Spanish | | SRC | Serbian | | SUO | Finnish | | SWD | Swedish | | TCV | Caviteño | | TCW | Telugu | | TGL | Tagalog | | THJ | Tai | | TTR | Tatar | | TTS | Tausug | | TRK | Turkish | | TWS | Twi | | UKR | Ukrainian | | URD | Urdu | | UZB | Uzbek | | UIG | Uighur | | VIE | Vietnamese | | WUU | Wu Chinese | | YOR | Yoruba | | YUH | Chinese, Yue | | ZUU | Zulu |

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Fatih Yavuz

Repository

GitHub


This README includes a brief introduction, installation instructions, usage examples, a description of the time_ago function, supported languages, licensing information, and links to the author and repository.