Socket
Socket
Sign inDemoInstall

s-date

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.2 to 1.6.1

index.d.ts

244

index.js

@@ -0,150 +1,98 @@

"use strict";
// years
function yyyy(date) {
return date.getFullYear().toString(); // {yyyy}
}
function yy(date) {
return date.getFullYear().toString().slice(-2); // {yy}
}
var yyyy = function (date) { return date.getFullYear().toString(); }; // {yyyy}
var yy = function (date) { return date.getFullYear().toString().slice(-2); }; // {yy}
// months
function m(date) {
var monthInt = date.getMonth() + 1;
return monthInt.toString(); // {m}
}
function mm(date) {
var monthInt = date.getMonth() + 1;
var mth = monthInt.toString();
return monthInt < 10 ? '0' + mth : mth; // {mm}
}
function month(date) {
var months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
return months[date.getMonth()]; // {Month}
}
function mo(date) {
return month(date).substr(0, 3);
}
var m = function (date) { return (date.getMonth() + 1).toString(); }; // {m}
var mm = function (date) {
var monthInt = date.getMonth() + 1;
return monthInt < 10 ? '0' + monthInt : monthInt.toString(); // {mm}
};
var month = function (date) {
var months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
return months[date.getMonth()]; // {Month}
};
var mo = function (date) { return month(date).substr(0, 3); };
// days
function day(date) {
return date.getDate();
}
function dd(date) {
var d = date.getDate();
return d < 10 ? '0' + d : d; // {dd}
}
function dayWithSuffix(date) {
var d = date.getDate();
var daySuffixes = Object.create(null);
daySuffixes.st = [1, 21, 31];
daySuffixes.nd = [2, 22];
daySuffixes.rd = [3, 23];
// loop through 'st', 'nd', and 'rd' (suffixes like '1st', '2nd', etc)
// if suffix is not found, it is 'th' (most numbers)
var suffixNotFound = true;
var suffix;
for (suffix in daySuffixes) {
if (daySuffixes[suffix].indexOf(d) > -1) {
suffixNotFound = false;
break;
var day = function (date) { return date.getDate().toString(); };
var dd = function (date) {
var d = date.getDate();
return d < 10 ? '0' + d : d.toString(); // {dd}
};
var dayWithSuffix = function (date) {
var d = date.getDate();
var daySuffixes = Object.create(null);
daySuffixes.st = [1, 21, 31];
daySuffixes.nd = [2, 22];
daySuffixes.rd = [3, 23];
// loop through 'st', 'nd', and 'rd' (suffixes like '1st', '2nd', etc)
// if suffix is not found, it is 'th' (most numbers)
var suffixNotFound = true;
var suffix = '';
for (suffix in daySuffixes) {
if (daySuffixes[suffix].indexOf(d) > -1) {
suffixNotFound = false;
break;
}
}
}
if (suffixNotFound) suffix = 'th';
return d + suffix;
}
function weekday(date) {
var weekdays = [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
];
return weekdays[date.getDay()];
}
function weekday3(date) {
return weekday(date).substr(0, 3);
}
function weekday2(date) {
return weekday(date).substr(0, 2);
}
function weekday1(date) {
return weekday(date)[0];
}
if (suffixNotFound)
suffix = 'th';
return d + suffix;
};
var weekday = function (date) {
var weekdays = [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
];
return weekdays[date.getDay()];
};
var weekday3 = function (date) { return weekday(date).substr(0, 3); };
var weekday2 = function (date) { return weekday(date).substr(0, 2); };
var weekday1 = function (date) { return weekday(date)[0]; };
// hours
function hours24(date) {
return date.getHours();
}
function hh24(date) {
var h = date.getHours();
return h < 10 ? '0' + h : h;
}
function hours(date) {
var h = date.getHours();
return h % 12 === 0 ? 12 : h % 12; // {h}
}
var hours24 = function (date) { return date.getHours().toString(); };
var hh24 = function (date) {
var h = date.getHours();
return h < 10 ? '0' + h : h.toString();
};
var hours = function (date) {
var h = date.getHours();
return h % 12 === 0 ? '12' : (h % 12).toString(); // {h}
};
// relies on `hours` function
function hh(date) {
var h = hours(date);
return h < 10 ? '0' + h : h;
}
function ampm(date) {
return date.getHours() < 12 ? 'am' : 'pm'; // {ampm}
}
function AMPM(date) {
return date.getHours() < 12 ? 'AM' : 'PM'; // {ampm}
}
var hh = function (date) {
var h = date.getHours();
var n = h % 12 === 0 ? 12 : h % 12;
return n < 10 ? '0' + n : n.toString();
};
var ampm = function (date) { return date.getHours() < 12 ? 'am' : 'pm'; }; // {ampm}
var AMPM = function (date) { return date.getHours() < 12 ? 'AM' : 'PM'; }; // {ampm}
// minutes, seconds
function minutes(date) {
var min = date.getMinutes();
return min < 10 ? '0' + min : min;
}
function seconds(date) {
var sec = date.getSeconds();
return sec < 10 ? '0' + sec : sec;
}
/*
formatDate('{mm}/{dd}/{yyyy}', new Date(2001, 0, 1)) => '01/01/2001'
*/
module.exports = function formatDate(format, date) {
// default to today
if (!date) date = new Date();
var map = {
var minutes = function (date) {
var min = date.getMinutes();
return min < 10 ? '0' + min : min.toString();
};
var seconds = function (date) {
var sec = date.getSeconds();
return sec < 10 ? '0' + sec : sec.toString();
};
var map = {
'{yyyy}': yyyy,

@@ -171,9 +119,7 @@ '{yy}': yy,

'{Seconds}': seconds
};
var regex = /\{yyyy\}|\{yy\}|\{m\}|\{mm\}|\{Month\}|\{Mo\}|\{d\}|\{dd\}|\{ds\}|\{Weekday\}|\{Day\}|\{Dy\}|\{D\}|\{h24\}|\{hh24\}|\{h\}|\{hh\}|\{ampm\}|\{AMPM\}|\{Minutes\}|\{Seconds\}/g;
return format.replace(regex, function(match) {
return map[match](date);
});
};
var regex = /\{yyyy\}|\{yy\}|\{m\}|\{mm\}|\{Month\}|\{Mo\}|\{d\}|\{dd\}|\{ds\}|\{Weekday\}|\{Day\}|\{Dy\}|\{D\}|\{h24\}|\{hh24\}|\{h\}|\{hh\}|\{ampm\}|\{AMPM\}|\{Minutes\}|\{Seconds\}/g;
module.exports = function formatDate(format, date) {
if (date === void 0) { date = new Date(); }
return format.replace(regex, function (match) { return map[match](date); });
};
{
"name": "s-date",
"version": "1.5.2",
"version": "1.6.1",
"description": "Tiny date/time formatter",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"coverage": "nyc --reporter=lcov --reporter=text ava",
"test": "ava"
"build": "tsc --declaration index.ts",
"coverage": "npm run build && nyc --reporter=lcov --reporter=text ava",
"test": "npm run build && ava"
},

@@ -27,4 +29,5 @@ "repository": {

"ava": "0.24.0",
"nyc": "11.4.1"
"nyc": "11.4.1",
"typescript": "3.0.3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc