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

@irony0901/is-now

v1.0.3

Published

elapsed time

Downloads

15

Readme

irony isNow

A library that expresses rough date or time

use

To install ironyIsNow, use yarn

$ yarn add @irony0901/is-now

Index

Examples

getStarted

import {isNow} from '@irony0901/is-now';

/** 
 * The argument can also be a number type. 
 * Example) isNow.about( Date.now() + 60000 )
**/
const now = Date.now();
const future_afterMoment = isNow.about( new Date( now + 60000 ) );
const future_minute = isNow.about( now + 60001 );
const future_hour = isNow.about( now + 60001 * 60 );
const future_day = isNow.about( now + 60001 * 60 * 24 );
const future_month = isNow.about( now + 60001 * 60 * 24 * 30 );
const future_year = isNow.about( now + 60001 * 60 * 24 * 365 );

const past_justBefore = isNow.about( now - 60000 );
const past_minute = isNow.about( now - 60001 );
const past_hour = isNow.about( now - (60001 * 60) );
const past_day = isNow.about( now - (60001 * 60 * 24) );
const past_month = isNow.about( now - (60001 * 60 * 24 * 30) );
const past_year = isNow.about( now - (60001 * 60 * 24 * 365) );


console.log( future_afterMoment )   // 'after a moment'
console.log( future_minute )        // '1 minute later'
console.log( future_hour )          // '1 hour later'
console.log( future_day )           // '1 day later'
console.log( future_month )         // '1 month later'
console.log( future_year )          // '1 year later'

console.log( past_justBefore )      // 'just before'
console.log( past_minute )          // '1 minute ago'
console.log( past_hour )            // '1 hour ago'
console.log( past_day )             // '1 day ago'
console.log( past_month )           // '1 month ago'
console.log( past_year )            // '1 year ago'
setTimeout(() => {
  /**
   * The current time is initialized (Property named standard in the isNow class) 
   * at the time when the 'isNow' object is loaded.
  **/ 
  console.log('[setTimeout]', isNow.about( new Date( now + 60000 ) ) ) // '[setTimeout] after a moment'
}, 2000)

unitSetting

import {isNow} from '@irony0901/is-now';

isNow.unit.afterMoment = '조금 후';
isNow.unit.minuteLater = '분 후';
isNow.unit.hourLater = '시간 후';
isNow.unit.dayLater = '일 후';
isNow.unit.weekLater = '주 후';
isNow.unit.monthLater = '월 후';
isNow.unit.yearLater = '년 후';

isNow.unit.justBefore = '방금 전';
isNow.unit.minuteAgo = '분 전';
isNow.unit.hourAgo = '시간 전';
isNow.unit.dayAgo = '일 전';
isNow.unit.weekAgo = '주 전';
isNow.unit.monthAgo = '월 전';
isNow.unit.yearAgo = '년 전';

const now = Date.now();
const future_afterMoment = isNow.about( now + 60000 );
const future_minute = isNow.about( now + 60001 );
const future_hour = isNow.about( now + 60001 * 60 );
const future_day = isNow.about( now + 60001 * 60 * 24 );
const future_month = isNow.about( now + 60001 * 60 * 24 * 30 );
const future_year = isNow.about( now + 60001 * 60 * 24 * 365 );

const past_justBefore = isNow.about( now - 60000 );
const past_minute = isNow.about( now - 60001 );
const past_hour = isNow.about( now - (60001 * 60) );
const past_day = isNow.about( now - (60001 * 60 * 24) );
const past_month = isNow.about( now - (60001 * 60 * 24 * 30) );
const past_year = isNow.about( now - (60001 * 60 * 24 * 365) );

console.log( future_afterMoment )   // '조금 후'
console.log( future_minute )        // '1 분 후'
console.log( future_hour )          // '1 시간 후'
console.log( future_day )           // '1 일 후'
console.log( future_month )         // '1 월 후'
console.log( future_year )          // '1 년 후'

console.log( past_justBefore )      // '방금 전'
console.log( past_minute )          // '1 분 전'
console.log( past_hour )            // '1 시간 전'
console.log( past_day )             // '1 일 전'
console.log( past_month )           // '1 월 전'
console.log( past_year )            // '1 년 전'

setStandardDate

import {isNow} from '@irony0901/is-now';

/**
 * The method named about
 * 
**/
const compareNowResult = isNow.about() // same isNow.about( Date.now() )
console.log('compareNowResult is ', compareNowResult) // 'compareNowResult is after a moment'

isNow.standard = new Date(0); // 1970-01-01T00:00:00.000Z
const compareModifiedResult = isNow.about()
console.log('compareModifiedResult is ', compareModifiedResult) // 'compareModifiedResult is ${N} year later'

createInstance

import { isNow, createIsNow } from '@irony0901/is-now';

const isNow_ko = createIsNow();
isNow_ko.unit.afterMoment = '조금 후';
isNow_ko.unit.minuteLater = '분 후';
isNow_ko.unit.hourLater = '시간 후';
isNow_ko.unit.dayLater = '일 후';
isNow_ko.unit.weekLater = '주 후';
isNow_ko.unit.monthLater = '월 후';
isNow_ko.unit.yearLater = '년 후';

isNow_ko.unit.justBefore = '방금 전';
isNow_ko.unit.minuteAgo = '분 전';
isNow_ko.unit.hourAgo = '시간 전';
isNow_ko.unit.dayAgo = '일 전';
isNow_ko.unit.weekAgo = '주 전';
isNow_ko.unit.monthAgo = '월 전';
isNow_ko.unit.yearAgo = '년 전';

console.log('Ver_Eng', isNow.about())   // 'Ver_Eng after a moment'
console.log('Ver_Ko', isNow_ko.about()) // 'Ver_Ko 조금 후'

predict

A method that can modify the return result of the 'about' method.
The initialization form is as follows

({diff, about, unit}: ElapsedPredictArg) => 
  Math.abs(diff) === about ? unit : `${about} ${unit}`

ElapsedPredictArg

  • diff: number
    The difference between the time at the time of the 'about' method and the time of the IsNow.standard field.
    Millisecond.
    positive value - future
    negative value - past
  • about: number
    Unconditionally positive value.
    Value to be expressed according to the value of the field in IsNow.unit
  • unit: string
    The value of one of the fields in IsNow.unit
import {isNow} from '@irony0901/is-now';

const now = Date.now();
isNow.predict = ({diff, about, unit}) => {
  console.log(`[PREDICT] diff: ${diff}, about: ${about}, unit: ${unit}`);
  return Math.abs(diff) === about ? unit : `${about} ${unit}`
}

console.log('[afterMoment]', isNow.about());
/** 
 * '[PREDICT] diff: 1, about: 1, unit: after a moment'
 * '[afterMoment] after a moment'
 **/

console.log('[minute]', isNow.about(  now + (12000 * 2) ) );
/** 
 * '[PREDICT] diff: 120007, about: 2, unit: minute later'
 * '[minute] 2 minute later'
 **/

isNow.predict = ({diff, about, unit}) => {
  return Math.abs(diff) === about ? `${unit}. [${about}] millisconds` : `[${about}] ${unit}`
}

console.log('[afterMoment]', isNow.about(now + 250));
/** 
 * '[afterMoment] after a moment. [250] milliscdonds'
 **/

console.log('[minute]', isNow.about(  now + (12000 * 2) ) );
/** 
 * '[minute] [2] minute later'
 **/