Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Mar 8, 2024
1 parent aecead7 commit 48e3aad
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 41 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export function isSaultSteMarie(possibleSpelling) {
const sanitizedSpelling = possibleSpelling
.trim()
.toLowerCase()
.replaceAll(/[,.-]/g, ' ')
.replaceAll(/\s+/g, ' ');
.replaceAll(/[\s,.-]/g, '');
return lowerCaseSaultSteMarieSpellings.has(sanitizedSpelling);
}
/**
Expand Down
3 changes: 1 addition & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export function isSaultSteMarie(possibleSpelling: string): boolean {
const sanitizedSpelling = possibleSpelling
.trim()
.toLowerCase()
.replaceAll(/[,.-]/g, ' ')
.replaceAll(/\s+/g, ' ')
.replaceAll(/[\s,.-]/g, '')

return lowerCaseSaultSteMarieSpellings.has(sanitizedSpelling)
}
Expand Down
24 changes: 8 additions & 16 deletions spellings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@ import cartesianProduct from 'just-cartesian-product';
export const preferredSaultSteMarieSpelling = 'Sault Ste. Marie';
export const canadaPostSaultSteMarieSpelling = 'S-STE-MARIE';
const wordSpellings = {
sault: [
'ault',
'dault',
's',
'salt',
'salut',
'sault',
'saulte',
'soo',
'sult'
],
sault: ['s', 'sault', 'saulte', 'soo'],
ste: ['s', 'st', 'ste', 'saint', 'sainte'],
marie: ['m', 'mare', 'marei', 'maire', 'marie', 'mary']
marie: ['m', 'mari', 'marie', 'mary']
};
const lowerCaseSaultSteMarieSpellingsList = cartesianProduct([
const product = cartesianProduct([
wordSpellings.sault,
wordSpellings.ste,
wordSpellings.marie
]).map((combination) => {
return combination.join(' ');
]);
// Generate spaced combinations
const lowerCaseSaultSteMarieSpellingsList = product.map((combination) => {
return combination.join('');
});
lowerCaseSaultSteMarieSpellingsList.push('the sault', 'the soo', 'sault stemarie', 'saultstemarie', 'ssm', 'ssmarie');
lowerCaseSaultSteMarieSpellingsList.push('saltstemarie', 'salutstemarie', 'thesault', 'thesoo');
export const lowerCaseSaultSteMarieSpellings = new Set(lowerCaseSaultSteMarieSpellingsList);
33 changes: 12 additions & 21 deletions spellings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,27 @@ export const preferredSaultSteMarieSpelling = 'Sault Ste. Marie'
export const canadaPostSaultSteMarieSpelling = 'S-STE-MARIE'

const wordSpellings = {
sault: [
'ault',
'dault',
's',
'salt',
'salut',
'sault',
'saulte',
'soo',
'sult'
],
sault: ['s', 'sault', 'saulte', 'soo'],
ste: ['s', 'st', 'ste', 'saint', 'sainte'],
marie: ['m', 'mare', 'marei', 'maire', 'marie', 'mary']
marie: ['m', 'mari', 'marie', 'mary']
}

const lowerCaseSaultSteMarieSpellingsList = cartesianProduct([
const product = cartesianProduct([
wordSpellings.sault,
wordSpellings.ste,
wordSpellings.marie
]).map((combination) => {
return combination.join(' ')
])

// Generate spaced combinations
const lowerCaseSaultSteMarieSpellingsList = product.map((combination) => {
return combination.join('')
})

lowerCaseSaultSteMarieSpellingsList.push(
'the sault',
'the soo',
'sault stemarie',
'saultstemarie',
'ssm',
'ssmarie'
'saltstemarie',
'salutstemarie',
'thesault',
'thesoo'
)

export const lowerCaseSaultSteMarieSpellings = new Set(
Expand Down
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import assert from 'node:assert';
import * as isSaultSteMarie from '../index.js';
describe('spellings', () => {
before(() => {
console.log([...isSaultSteMarie.lowerCaseSaultSteMarieSpellings]);
});
it('Has spellings of Sault Ste. Marie available', () => {
assert.ok(isSaultSteMarie.lowerCaseSaultSteMarieSpellings.size > 0);
});
});
describe('isSaultSteMarie()', () => {
it('Validates spellings of Sault Ste. Marie', () => {
assert.ok(isSaultSteMarie.isSaultSteMarie('Sault Ste. Marie'));
Expand Down
10 changes: 10 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import assert from 'node:assert'

import * as isSaultSteMarie from '../index.js'

describe('spellings', () => {
before(() => {
console.log([...isSaultSteMarie.lowerCaseSaultSteMarieSpellings])
})

it('Has spellings of Sault Ste. Marie available', () => {
assert.ok(isSaultSteMarie.lowerCaseSaultSteMarieSpellings.size > 0)
})
})

describe('isSaultSteMarie()', () => {
it('Validates spellings of Sault Ste. Marie', () => {
assert.ok(isSaultSteMarie.isSaultSteMarie('Sault Ste. Marie'))
Expand Down

0 comments on commit 48e3aad

Please sign in to comment.