mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
fixed #619
This commit is contained in:
parent
f8f2f52be9
commit
38c8a20c45
6 changed files with 37 additions and 38 deletions
|
|
@ -447,6 +447,19 @@ function getAdjective(string) {
|
|||
// get ordinal out of integer: 1 => 1st
|
||||
const nth = n => n+(["st","nd","rd"][((n+90)%100-10)%10-1]||"th");
|
||||
|
||||
// get two-letters code (abbreviation) from string
|
||||
function abbreviate(name, restricted = []) {
|
||||
const parsed = name.replace("Old ", "O ").replace(/[()]/g, ""); // remove Old prefix and parentheses
|
||||
const words = parsed.split(" ");
|
||||
const letters = words.join("");
|
||||
|
||||
let code = words.length === 2 ? words[0][0]+words[1][0] : letters.slice(0,2);
|
||||
for (let i = 1; i < letters.length-1 && restricted.includes(code); i++) {
|
||||
code = letters[0] + letters[i].toUpperCase();
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
// conjunct array: [A,B,C] => "A, B and C"
|
||||
function list(array) {
|
||||
if (!Intl.ListFormat) return array.join(", ");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue