www.spaceplanner.app

Web client to the spaceplanner API
git clone git://jacobedwards.org/www.spaceplanner.app
Log | Files | Refs

commit ab97aa40fc5c4c8cd236921e7106ff0cf57128d4
parent 2ed8c240784262ef0e5f6591310fa86a3196a16e
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Fri, 30 Aug 2024 17:59:01 -0700

Add name formatting functions

These help with capitalizing and identifying words in names.

Diffstat:
Mfiles/lib/ui.js | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git a/files/lib/ui.js b/files/lib/ui.js @@ -72,6 +72,26 @@ function toggle_setup_button(a, b) { }, false) } +export function prettyName(name, options) { + options = options ?? {} + options.separator = options.separator ?? /[-_]/ + options.title = options.title ?? true + + let words = name.split(options.separator) + for (let i in words) { + words[i] = capitalize(words[i]) + if (!options.title) { + break + } + } + + return words.join(" ") +} + +export function capitalize(word) { + return word.charAt(0).toUpperCase() + word.substr(1) +} + export function warning(content) { let warning = document.createElement("span") warning.classList.add("warning")