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

gloomydate

v1.3.9

Published

A library for calculating relative time strings, compatible with both ESM and MPA environments.

Downloads

88

Readme

GloomyDate

This project is a date calculation library developed by the FE developer GloomyStore.

Usage

It's simple.

Installation

  • Node.js (ESM):

    • Install using npm i gloomydate.
  • General HTML Project (MPA):

    • Add it using <script src='https://cdn.gloomy-store.com/gloomyDate/gloomyDate.cjs.js'></script>.

How to Use

ESM Method

import gloomyDate from 'gloomydate';

const result = gloomyDate.date('2022-05-02 14:10:44');
console.log(result); // Expected output: '1년 전'

MPA Method

<script src='https://cdn.gloomy-store.com/gloomyDate/gloomyDate.js'></script>
<script>
  const result = window.gloomyDate.date('2022-05-02 14:10:44', 'en');
  console.log(result); // Expected output: 'before 1 year'
</script>

Input

  • Supports three input formats:

    1. String in the format '2023-04-25 14:55:40'
    2. String in the format '20230425145540'
    3. Int timestamp in the format 1723729654882 (number)
    4. Date object (JavaScript Date object)

    Example: gloomyDate.date('20230425145540') // Expected output: '1년 전' Example: gloomyDate.date(new Date()) // Output for the current time

  • Language Option:

    • Supports ko, en, jp for three languages. The default output is in Korean if the second argument is not provided.
    • Example: gloomyDate.date('20230425145540', 'en') Expected output: 1 year ago

Output

  • Returns an automatically calculated string:

    • Formats like X년 전, X달 전, X일 전, X시간 전, X분 전, 방금 전 in Korean.
    • If you pass en or jp as the second argument, the output will be in that language.
  • Future Date Handling:

    • Now, it can handle future dates as well as past dates. Outputs like 1년 후, 2달 후, 3일 후 are possible. This is handled automatically by the gloomyDate.date function.
    • Example: gloomyDate.date('2025-08-15 10:00:00') // Expected output: '1년 후'
    • Example: gloomyDate.date('2023-10-01 10:00:00') // Expected output: '1달 전'

Real-World Usage Example

import gloomyDate from 'gloomydate';

const [data, setData] = useState([
  { title: 'title1', date: gloomyDate.date('2022-05-10 10:55:40') },
  { title: 'title2', date: gloomyDate.date('2023-02-11 15:50:30') },
  { title: 'title3', date: gloomyDate.date('2025-08-15 10:00:00') } // Example of a future date
]);

return (
  <div className="list-bg">
    {data.map((e, i) =>
      <div key={i}>
        <p className="date">{e.date}</p> {/* Expected output: '2달 전', '1년 전', '1년 후' */}
      </div>
    )}
  </div>
);

Example of Rendered HTML

<div class="list-bg">
    <p class="date">11달 전</p>
    <p class="date">2달 전</p>
    <p class="date">1년 후</p>
</div>

Getting Started

Install the gloomydate module by running npm install gloomydate in your terminal. After installation, start the app with npm start or yarn start.


Now, you can easily use GloomyDate in both ESM and MPA environments, and it can handle both past and future dates! 🎉