27 lines
595 B
JavaScript
27 lines
595 B
JavaScript
import * as dateFns from "date-fns";
|
|
|
|
export function filenameToSlug(input) {
|
|
return stringToSlug(input.substring(0, input.indexOf(".")));
|
|
}
|
|
|
|
export function stringToSlug(str) {
|
|
return str
|
|
.trim()
|
|
.toLowerCase()
|
|
.replace(/[\W_]+/g, "-")
|
|
.replace(/^-+|-+$/g, "");
|
|
}
|
|
|
|
export function formatDate(date) {
|
|
return dateFns.format(Date.parse(date), "PPP");
|
|
}
|
|
|
|
/**
|
|
* Silliness to make sure dates don't get passed to the
|
|
* page function below as [object Object]
|
|
* @param {*} obj
|
|
* @returns
|
|
*/
|
|
export function stringifyAndParse(obj) {
|
|
return JSON.parse(JSON.stringify(obj));
|
|
}
|