-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
61 lines (54 loc) · 1.83 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {
canadaPostSaultSteMarieSpelling,
lowerCaseSaultSteMarieSpellings,
preferredSaultSteMarieSpelling
} from './spellings.js'
function sanitizeSpelling(possibleSpelling: string): string {
return possibleSpelling
.trim()
.toLowerCase()
.replaceAll(/[\s,.-]/g, '')
}
/**
* Adds a new spelling of Sault Ste. Marie to the list of checked spellings.
* @param newSpelling - A new spelling of Sault Ste. Marie.
*/
export function addSaultSteMarieSpelling(newSpelling: string): void {
lowerCaseSaultSteMarieSpellings.add(sanitizeSpelling(newSpelling))
}
/**
* Determines whether a word is a spelling of Sault Ste. Marie.
* @param possibleSpelling - A possible spelling of Sault Ste. Marie.
* @returns `true` if the possible spelling appears to be a spelling of Sault Ste. Marie.
*/
export function isSaultSteMarie(possibleSpelling: string): boolean {
return lowerCaseSaultSteMarieSpellings.has(sanitizeSpelling(possibleSpelling))
}
/**
* Returns the preferred spelling of Sault Ste. Marie.
* @param possibleSpelling - A possible spelling of Sault Ste. Marie.
* @param preferredSpelling - The preferred spelling of Sault Ste. Marie.
* @returns The preferred spelling if the possible spelling is a spelling of Sault Ste. Marie. Otherwise, the possible spelling is returned.
*/
export function fixSaultSteMarie(
possibleSpelling: string,
preferredSpelling: string = preferredSaultSteMarieSpelling
): string {
if (isSaultSteMarie(possibleSpelling)) {
return preferredSpelling
}
return possibleSpelling
}
export {
preferredSaultSteMarieSpelling,
canadaPostSaultSteMarieSpelling,
lowerCaseSaultSteMarieSpellings
} from './spellings.js'
export default {
addSaultSteMarieSpelling,
isSaultSteMarie,
fixSaultSteMarie,
preferredSaultSteMarieSpelling,
canadaPostSaultSteMarieSpelling,
lowerCaseSaultSteMarieSpellings
}