Moved exports to the bottom. It just looks prettier.

This commit is contained in:
Alexander Andreev 2021-12-01 02:17:23 +04:00
parent 4415612d69
commit b7044af0e6
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -1,26 +1,22 @@
const moment = require("moment-timezone");
const formats = Object.freeze({
const date_formats = Object.freeze({
post_date: "Do MMMM YYYY HH:mm:ss z",
file_date: "YYYY-MM-DD HH:mm:ss z",
id_date: "YYYYMMDD-HHmm" });
exports.formats = formats;
function datetime(date, format=formats.post_date, timezone="UTC") {
function datetime(date, format=date_formats.post_date, timezone="UTC") {
return moment.utc(date).tz(timezone).format(format);
}
exports.datetime = datetime;
exports.getClientTimezone = ctx => {
function getClientTimezone(ctx) {
if (ctx.header['x-client-timezone'] !== undefined)
return ctx.header['x-client-timezone'];
else
return "UTC";
};
}
exports.getServiceByHost = (host, service="") => {
function getServiceByHost(host, service="") {
if (host.endsWith("onion"))
switch (service) {
case "radio": return "http://wsmkgnmhmzqm7kyzv7jnzzafvgm7xlmlfvzhgorpapd5or2arnhuktqd.onion";
@ -44,12 +40,13 @@ exports.getServiceByHost = (host, service="") => {
}
}
exports.rssLink = (proto, host, date, category, timezone="UTC") =>
`${proto}://${host}/mindflow#${category}-${datetime(date, formats.id_date, timezone)}`;
function rssLink(proto, host, date, category, timezone="UTC") {
return `${proto}://${host}/mindflow#${category}-${datetime(date, date_formats.id_date, timezone)}`;
}
// This code was taken from https://www.npmjs.com/package/mysql#custom-format
// Only fourth line was changed.
exports.mysqlQueryFormat = function (query, values) {
function mysqlQueryFormat(query, values) {
if (!values) return query;
return query.replace(/\:(\w+)/g, function (txt, key) {
if (values[key] !== undefined)
@ -58,3 +55,4 @@ exports.mysqlQueryFormat = function (query, values) {
}.bind(this));
};
module.exports = { date_formats, datetime, getClientTimezone, getServiceByHost, rssLink, mysqlQueryFormat }