tickle/modules/utils/changeTitle.mjs

22 lines
641 B
JavaScript
Raw Permalink Normal View History

//@ts-check
/**
* Changes the document's title. Instead of passing the main title, you can also
* change the functions `title` member:
* ```js
* changeTitle.title = "My Site"
* changeTitle("Home") // produces "Home | My Site"
* ```
2023-05-09 02:00:53 +00:00
* if not `title` is passed, the document title (as found when running the function
* the first time) will be used.
* @param {string} title
* @param {string} mainTitle
* @returns
*/
export const changeTitle = (title, mainTitle = changeTitle.title) =>
document && (document.title = `${title} | ${mainTitle}`);
changeTitle.title = (document && document.title) || "";
export default changeTitle;