feat: convert all files to esm
This commit is contained in:
parent
ef6923ece6
commit
e8fd3a17d2
34 changed files with 202 additions and 228 deletions
|
@ -1,19 +1,19 @@
|
|||
const dayjs = require("dayjs");
|
||||
const utc = require("dayjs/plugin/utc");
|
||||
const advancedFormat = require("dayjs/plugin/advancedFormat");
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc.js";
|
||||
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
||||
|
||||
const pluralizeBase = require("pluralize");
|
||||
import pluralizeBase from "pluralize";
|
||||
|
||||
const keys = Object.keys;
|
||||
const values = Object.values;
|
||||
const entries = Object.entries;
|
||||
export const keys = Object.keys;
|
||||
export const values = Object.values;
|
||||
export const entries = Object.entries;
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(advancedFormat);
|
||||
|
||||
const formatDate = (date, format) => dayjs.utc(date).format(format);
|
||||
export const formatDate = (date, format) => dayjs.utc(date).format(format);
|
||||
|
||||
const organizeByDate = (collection) => {
|
||||
export const organizeByDate = (collection) => {
|
||||
const collectionByDate = {};
|
||||
|
||||
collection.forEach((item) => {
|
||||
|
@ -37,7 +37,7 @@ const allTags = (collection, ignore = []) => {
|
|||
return [...tagSet];
|
||||
};
|
||||
|
||||
const allTagCounts = (collection, ignore = ["post"]) => {
|
||||
export const allTagCounts = (collection, ignore = ["post"]) => {
|
||||
if (!collection.length) {
|
||||
throw new Error("Invalid collection, no items");
|
||||
}
|
||||
|
@ -62,28 +62,28 @@ const allTagCounts = (collection, ignore = ["post"]) => {
|
|||
return tagArray;
|
||||
};
|
||||
|
||||
const filter = (collection, filters = []) => {
|
||||
export const filter = (collection, filters = []) => {
|
||||
return collection.filter((item) => !filters.includes(item));
|
||||
};
|
||||
|
||||
const pluralize = (string, count = 0) => {
|
||||
export const pluralize = (string, count = 0) => {
|
||||
return pluralizeBase(string, count);
|
||||
};
|
||||
|
||||
const filterCatalogueTags = (tags) => {
|
||||
export const filterCatalogueTags = (tags) => {
|
||||
// In the case of catalogue items, the 0-index is "catalogue"
|
||||
// and the 1-index is the catalogueType. We don't need to
|
||||
// show those in the front-end.
|
||||
return filter(tags, [tags[0], tags[1]]);
|
||||
};
|
||||
|
||||
const limit = (collection, limit = 5) => collection.slice(0, limit);
|
||||
export const limit = (collection, limit = 5) => collection.slice(0, limit);
|
||||
|
||||
const filterFavourites = (collection) => {
|
||||
export const filterFavourites = (collection) => {
|
||||
return collection.filter((item) => item.data.favourite);
|
||||
};
|
||||
|
||||
const isOld = (dateArg) => {
|
||||
export const isOld = (dateArg) => {
|
||||
const date = dayjs(dateArg);
|
||||
const now = dayjs();
|
||||
|
||||
|
@ -91,19 +91,3 @@ const isOld = (dateArg) => {
|
|||
|
||||
return diffInYears >= 2;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
allTagCounts,
|
||||
allTags,
|
||||
entries,
|
||||
filter,
|
||||
filterCatalogueTags,
|
||||
filterFavourites,
|
||||
formatDate,
|
||||
isOld,
|
||||
keys,
|
||||
limit,
|
||||
organizeByDate,
|
||||
pluralize,
|
||||
values,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue