aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-06-17 23:23:30 +1000
committerTerry Truong <terry06890@gmail.com>2022-06-17 23:23:30 +1000
commit2dc9cb2f46d57180b1f6ed78d214d6a09d591d7a (patch)
tree3c63c23c9ca6c535f81b636dd092a1dc915479ae /src
parentb22b5e6c0ce07cfc62bed354744178458abcbf35 (diff)
Avoid capitalisation of apostrophe-s in tile-names
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