Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
short-time-ago
Advanced tools
Readme
This package exports a single function, timeAgo
,
which describes the time elapsed between a given date and the current date
in a human readable format (for example, "10 minutes ago", "in 3 seconds").
now
anchor timeen_US
locale support.View on unpkg.
Using npm
:
npm i short-time-ago
Using yarn
:
yarn add short-time-ago
UMD build:
<!-- Add UMD script -->
<script src="https://unpkg.com/short-time-ago"></script>
<!-- Usage -->
<script>
const timeAgo = window['short-time-ago'].timeAgo;
const myDate = new Date();
const description = timeAgo(myDate);
// Output: `just now`.
console.log(description);
</script>
Module build:
<script type="module">
import { timeAgo } from 'https://unpkg.com/short-time-ago?module';
const myDate = new Date();
const description = timeAgo(myDate);
// Output: `just now`.
console.log(description);
</script>
Basic usage:
import { timeAgo } from 'short-time-ago';
const myDate = new Date();
const description = timeAgo(myDate);
// Output: `just now`.
console.log(description);
Specifying a custom current date with the now
parameter:
import { timeAgo } from 'short-time-ago';
const myDate = new Date('2019-01-01T00:00:00.000Z');
const now = new Date('2019-01-01T00:01:00.000Z');
const description = timeAgo(myDate, now);
// Output: `1 minute ago`.
console.log(description);
import { timeAgo } from 'short-time-ago';
const myDate = new Date('2019-01-02T00:00:00.000Z');
const now = new Date('2019-01-01T00:00:00.000Z');
const description = timeAgo(myDate, now);
// Output: `in 1 day`.
console.log(description);
timeAgo: (date: Date, now?: Date) => string;
Explore the API on jsDocs.io.
The following table describes timeAgo
's output.
Time elapsed | Past output | Future output |
---|---|---|
< 1 second | just now | just now |
< 1 minute | N second(s) ago | in N second(s) |
< 1 hour | N minute(s) ago | in N minute(s) |
< 1 day | N hour(s) ago | in N hour(s) |
< 1 month (30.5 days) | N day(s) ago | in N day(s) |
< 1 year (365 days) | N month(s) ago | in N month(s) |
> 1 year | N year(s) ago | in N year(s) |
MIT License
Copyright (c) 2020 Edoardo Scibona
See LICENSE file.
FAQs
A small, no dependencies, Typescript utility to describe time differences in a human readable format (for example, '1 minute ago')
The npm package short-time-ago receives a total of 78 weekly downloads. As such, short-time-ago popularity was classified as not popular.
We found that short-time-ago demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.