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

shleemy

v1.2.2

Published

Human readable time manipulation. Turn '2021-01-27T22:36:54.757Z' into '6 weeks ago' without going to time prison.

Downloads

24

Readme

shleemy

  • Small
  • Mighty
  • No dependencies
  • Easy to use
  • You won't go to time prison for messing with time

Inspiration take from Carbon

Install

$ yarn add shleemy

Or

$ npm i shleemy

Usage

Basic

Get human readable values with tense information

Present

import { shleemy } from "shleemy";

const interval = shleemy(new Date());

console.log(interval.forHumans); // "just now"
console.log(interval.tense); // "present"

Past

import { shleemy } from "shleemy";

const date = new Date();
date.setMinutes(date.getMinutes() - 3);

console.log(shleemy(date).forHumans); // "3 minutes ago"
console.log(shleemy(date).tense); // "past"

Future

import { shleemy } from "shleemy";

const date = new Date();
date.setMinutes(date.getMinutes() + 70);

console.log(shleemy(date).forHumans); // "in an hour"
console.log(shleemy(date).tense); // "future"
interval values
import { shleemy } from "shleemy";

const date = new Date();
date.setHours(date.getHours() - 3);

console.log(shleemy(date).roundedHours); // 3
import { shleemy } from "shleemy";

const date = new Date();
date.setDays(date.getDays() - 12);

console.log(shleemy(date).roundedDays); // 12
console.log(shleemy(date).roundedWeeks); // 1
Basic Formatting
const date = new Date();
date.setDays(date.getDays() - 12);

const interval = shleemy(date);

console.log(interval.time); // 12:34
console.log(interval.date); // 12/03/2021

No locale as of now, so you backwards date people will have to do with day/month/year. Soz

Output manipulation

The Shleemy object can be used as a string!

import { shleemy } from "shleemy";

const date = new Date();
date.setDays(date.getDays() - 12);

const interval = shleemy(date);

console.log(`added ${interval}`); // added 12 days ago;
console.log(`${interval.replace('days', 'yonders')}`); // 12 yonders ago;

Available properties

import { shleemy } from "shleemy";

const date = new Date();
date.setDays(date.getDays() - 12);
const interval = shleemy(date);

console.log('seconds', interval.seconds);
console.log('rounded seconds', interval.roundedSeconds);
console.log('minutes', interval.minutes);
console.log('rounded minutes', interval.roundedMinutes);
console.log('hours', interval.hours);
console.log('rounded hours', interval.roundedHours);
console.log('days', interval.days);
console.log('rounded days', interval.roundedDays);
console.log('weeks', interval.weeks);
console.log('rounded weeks', interval.roundedWeeks);
console.log('months', interval.months);
console.log('rounded months', interval.roundedMonths);
console.log('years', interval.years);
console.log('rounded years', interval.roundedYears);
console.log('tense', interval.tense);

All properties will be positive values. You cannot have -3 days in the 4th dimension. Use tense for past/present/future value

Options

import { shleemy, ShleemyInterval } from "shleemy";

const date = new Date();
date.setDays(date.getDays() - 12);

const toDate = new Date();
toDate.setDays(toDate.getDays() - 20);

console.log(
  shleemy(date, {
    toDate: toDate, // default: new Date() (now)
    rounding: 'ceil', // default: floor
    humanReadable: {
      past: (value, interval) => `${value} ${ShleemyInterval.pluralInterval(value, interval)} yonders ago`, // default: ShleemyInterval.toHumanReadablePast
      future: (value, interval) => `in ${value} ${ShleemyInterval.pluralInterval(value, interval)} and you get the idea`, // default: ShleemyInterval.toHumanReadableFuture
      present: () => `seconds ago!`, // default: "just now"
    }
  }).days
); // 8