
Security News
NIST Officially Stops Enriching Most CVEs as Vulnerability Volume Skyrockets
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.
Locale-agnostic date formatting utilities
This package doesn't seek to contain the knowledge about the specific locale-dependent date formats, but provides a flexible and concise way to construct them.
import { formatDate } from "dateshape";
formatDate(new Date(), "{YYYY}-{MM}-{DD} {HH}:{mm}:{ss}");
// 2022-07-19 12:34:56
import { formatDate } from "dateshape";
let eraTemplate = ({ E }) => E === 1 ? "AD {YE}" : "{YE} BC";
// {YE} stands for the unsigned year of a calendar era
formatDate("2022-07-19", eraTemplate);
// AD 2022
formatDate(-62200000000000, eraTemplate);
// 3 BC
import { formatDate } from "dateshape";
let weekDays = "Sun Mon Tue Wed Thu Fri Sat".split(" ");
let months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ");
let shortDateFormat = {
template: "{WD}, {MMM} {D}",
transform: {
WD: ({ weekDay }) => weekDays[weekDay],
MMM: ({ month }) => months[month],
},
};
formatDate("2022-12-02T12:34:56.789", shortDateFormat);
// Fri, Dec 2
import { formatDate } from "dateshape";
import { customLocale } from "./customLocale";
formatDate(new Date(), customLocale.fullDate);
// þriðjudagur 19. júlí 2022
formatDate(new Date(), customLocale.shortDate);
// 19.07.2022
const customWeekDays = [
"sunnudagur",
"mánudagur",
"þriðjudagur",
"miðvikudagur",
"fimmtudagur",
"föstudagur",
"laugardagur",
];
const customMonths = [
"janúar",
"febrúar",
"mars",
"apríl",
"maí",
"júní",
"júlí",
"ágúst",
"september",
"október",
"nóvember",
"desember",
];
export const customLocale = {
shortDate: "{DD}.{MM}.{Y}",
fullDate: {
template: "{WD} {D}. {MMM} {Y}",
transform: {
WD: ({ weekDay }) => customWeekDays[weekDay],
MMM: ({ month }) => customMonths[month],
},
},
};
import { formatDuration } from "dateshape";
formatDuration(123456);
// 2"03.456"
| Placeholder | Value |
|---|---|
{Y} | Year |
{YY} | Year, zero-prefixed when shorter than 2 digits |
{YYYY} | Year, zero-prefixed when shorter than 4 digits |
{yy} | Year, last 2 digits zero-prefixed when shorter than 2 digits |
{YE} | Year of a calendar era (specified by AD/BC or CE/BCE) |
{E} | Christian era: 1 for AD, -1 for BC |
{CE} | Common Era: 1 for CE, -1 for BCE |
{M} | Month |
{MM} | Month, zero-prefixed when shorter than 2 digits |
{D} | Day |
{DD} | Day, zero-prefixed when shorter than 2 digits |
{H} | Hours |
{HH} | Hours, zero-prefixed when shorter than 2 digits |
{h} | 12h-clock hours |
{hh} | 12h-clock hours, zero-prefixed when shorter than 2 digits |
{a} | Day period: AM/PM |
{m} | Minutes |
{mm} | Minutes, zero-prefixed when shorter than 2 digits |
{s} | Seconds |
{ss} | Seconds, zero-prefixed when shorter than 2 digits |
{ms} | Milliseconds, zero-prefixed when shorter than 3 digits |
{tz} | Time zone |
{iso} | Local time zone ISO date string |
{isoDate} | Date (= {YYYY}-{MM}-{DD}) |
{isoTime} | Time (= {HH}:{mm}:{ss}) |
{isoTimeMs} | Time with milliseconds |
The following unformatted date components are also available as placeholder values: timestamp, year, month, day, hours, hours12 (12h-clock hours), minutes, seconds, milliseconds, weekDay, timezoneOffset, input (the first argument of the formatDate() call).
FAQs
Locale-agnostic date formatting utilities
The npm package dateshape receives a total of 8 weekly downloads. As such, dateshape popularity was classified as not popular.
We found that dateshape demonstrated a healthy version release cadence and project activity because the last version was released less than 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
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.