Skip to content

Commit

Permalink
use cartesian product to generate combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Mar 8, 2024
1 parent 5a44098 commit 542292b
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ npm install @cityssm/is-sault-ste-marie
```javascript
import { isSaultSteMarie, fixSaultSteMarie } from '@cityssm/is-sault-ste-marie'

// Test whether a string is a spelling of Sault Ste. Marie.
// Tests whether a string is a spelling of Sault Ste. Marie.

console.log(isSaultSteMarie('Sault Ste. Marie')) // => true
console.log(isSaultSteMarie('Sault-Sainte-Marie')) // => true
Expand Down
3 changes: 1 addition & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export declare const preferredSaultSteMarieSpelling = "Sault Ste. Marie";
export declare const canadaPostSaultSteMarieSpelling = "S-STE-MARIE";
/**
* Determines whether a word is a spelling of Sault Ste. Marie.
* @param {string} possibleSpelling - A possible spelling of Sault Ste. Marie.
Expand All @@ -13,3 +11,4 @@ export declare function isSaultSteMarie(possibleSpelling: string): boolean;
* @returns {string} - The preferred spelling if the possible spelling is a spelling of Sault Ste. Marie. Otherwise, the possible spelling is returned.
*/
export declare function fixSaultSteMarie(possibleSpelling: string, preferredSpelling?: string): string;
export { preferredSaultSteMarieSpelling, canadaPostSaultSteMarieSpelling, lowerCaseSaultSteMarieSpellings } from './spellings.js';
41 changes: 2 additions & 39 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
export const preferredSaultSteMarieSpelling = 'Sault Ste. Marie';
export const canadaPostSaultSteMarieSpelling = 'S-STE-MARIE';
const lowerCaseSaultSteMarieSpellings = new Set([
// Proper spellings
'sault sainte marie',
'sault ste marie',
// Canada Post
's ste marie',
// MPAC
'sault sainte m',
'sault ste mari',
'saulte ste marie',
// Slang
'the sault',
'the soo',
// Sainte Typos
'sault saint marie',
'sault st marie',
// Other Typos
'ault ste marie',
'dault ste marie',
'salt ste marie',
'salut ste marie',
'saulat ste marie',
'sault st emarie',
'sault ste maire',
'sault ste mare',
'sault ste marei',
'sault ste mari',
'sault ste mrie',
'soo ste marie',
// Others
's s m',
's s marie',
'sault stemarie',
'saultstemarie',
'ssm',
'ssmarie'
]);
import { lowerCaseSaultSteMarieSpellings, preferredSaultSteMarieSpelling } from './spellings.js';
/**
* Determines whether a word is a spelling of Sault Ste. Marie.
* @param {string} possibleSpelling - A possible spelling of Sault Ste. Marie.
Expand All @@ -62,3 +24,4 @@ export function fixSaultSteMarie(possibleSpelling, preferredSpelling = preferred
}
return possibleSpelling;
}
export { preferredSaultSteMarieSpelling, canadaPostSaultSteMarieSpelling, lowerCaseSaultSteMarieSpellings } from './spellings.js';
57 changes: 10 additions & 47 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,7 @@
export const preferredSaultSteMarieSpelling = 'Sault Ste. Marie'

export const canadaPostSaultSteMarieSpelling = 'S-STE-MARIE'

const lowerCaseSaultSteMarieSpellings = new Set([
// Proper spellings
'sault sainte marie',
'sault ste marie',

// Canada Post
's ste marie',

// MPAC
'sault sainte m',
'sault ste mari',
'saulte ste marie',

// Slang
'the sault',
'the soo',

// Sainte Typos
'sault saint marie',
'sault st marie',

// Other Typos
'ault ste marie',
'dault ste marie',
'salt ste marie',
'salut ste marie',
'saulat ste marie',
'sault st emarie',
'sault ste maire',
'sault ste mare',
'sault ste marei',
'sault ste mari',
'sault ste mrie',
'soo ste marie',

// Others
's s m',
's s marie',
'sault stemarie',
'saultstemarie',
'ssm',
'ssmarie'
])
import {
lowerCaseSaultSteMarieSpellings,
preferredSaultSteMarieSpelling
} from './spellings.js'

/**
* Determines whether a word is a spelling of Sault Ste. Marie.
Expand Down Expand Up @@ -76,3 +33,9 @@ export function fixSaultSteMarie(
}
return possibleSpelling
}

export {
preferredSaultSteMarieSpelling,
canadaPostSaultSteMarieSpelling,
lowerCaseSaultSteMarieSpellings
} from './spellings.js'
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.25",
"eslint-config-cityssm": "^1.4.2"
},
"dependencies": {
"just-cartesian-product": "^4.2.0"
}
}
3 changes: 3 additions & 0 deletions spellings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare const preferredSaultSteMarieSpelling = "Sault Ste. Marie";
export declare const canadaPostSaultSteMarieSpelling = "S-STE-MARIE";
export declare const lowerCaseSaultSteMarieSpellings: Set<string>;
25 changes: 25 additions & 0 deletions spellings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import cartesianProduct from 'just-cartesian-product';
export const preferredSaultSteMarieSpelling = 'Sault Ste. Marie';
export const canadaPostSaultSteMarieSpelling = 'S-STE-MARIE';
const saultSpellings = [
'ault',
'dault',
's',
'salt',
'salut',
'sault',
'saulte',
'soo',
'sult'
];
const steSpellings = ['s', 'st', 'ste', 'saint', 'sainte'];
const marieSpellings = ['m', 'mare', 'marei', 'maire', 'marie', 'mary'];
const lowerCaseSaultSteMarieSpellingsList = cartesianProduct([
saultSpellings,
steSpellings,
marieSpellings
]).map((combination) => {
return combination.join(' ');
});
lowerCaseSaultSteMarieSpellingsList.push('sault stemarie', 'saultstemarie', 'ssm', 'ssmarie');
export const lowerCaseSaultSteMarieSpellings = new Set(lowerCaseSaultSteMarieSpellingsList);
40 changes: 40 additions & 0 deletions spellings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import cartesianProduct from 'just-cartesian-product'

export const preferredSaultSteMarieSpelling = 'Sault Ste. Marie'

export const canadaPostSaultSteMarieSpelling = 'S-STE-MARIE'

const saultSpellings = [
'ault',
'dault',
's',
'salt',
'salut',
'sault',
'saulte',
'soo',
'sult'
]

const steSpellings = ['s', 'st', 'ste', 'saint', 'sainte']

const marieSpellings = ['m', 'mare', 'marei', 'maire', 'marie', 'mary']

const lowerCaseSaultSteMarieSpellingsList = cartesianProduct([
saultSpellings,
steSpellings,
marieSpellings
]).map((combination) => {
return combination.join(' ')
})

lowerCaseSaultSteMarieSpellingsList.push(
'sault stemarie',
'saultstemarie',
'ssm',
'ssmarie'
)

export const lowerCaseSaultSteMarieSpellings = new Set(
lowerCaseSaultSteMarieSpellingsList
)

0 comments on commit 542292b

Please sign in to comment.