aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.ts5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/lib.ts b/src/lib.ts
index c13992c..67ac4c3 100644
--- a/src/lib.ts
+++ b/src/lib.ts
@@ -108,8 +108,9 @@ export function randWeightedChoice(weights: number[]): number | null {
}
// Returns a string with words first-letter capitalised
export function capitalizeWords(str: string){
- return str.replace(/\b\w/g, x => x.toUpperCase());
- // '\b' matches word boundary, '\w' is like [a-zA-Z0-9_],
+ str = str.replace(/\b\w/g, x => x.toUpperCase()); // '\b' matches word boundary, '\w' is like [a-zA-Z0-9_]
+ str = str.replace(/(\w)'S/, '$1\'s'); // Avoid cases like "traveler's tree" -> "Traveler'S Tree"
+ return str;
}
// Dynamically obtains scroll bar width
// From stackoverflow.com/questions/13382516/getting-scroll-bar-width-using-javascript