-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(typedefs): added typedefs #37
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"cSpell.words": ["autocorrect", "autocorrector"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
import { FieldOptions, fieldTypes } from './createFieldParser'; | ||
import { Autocorrect, FieldOptions } from '../types'; | ||
|
||
const numberToLetterMismatches = { | ||
'8': 'B', | ||
|
@@ -18,26 +18,38 @@ const letterToNumberMismatches = { | |
S: '5', | ||
Z: '2', | ||
}; | ||
export interface Autocorrect { | ||
line: number; | ||
column: number; | ||
original: string; | ||
corrected: string; | ||
} | ||
|
||
/** | ||
* It takes a string and returns a string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This description is not helpful (just describes what already is understandable from the type anotations) |
||
* @param {string} char - The character to convert. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* @returns A function that takes a string and returns a string. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
export function letterToNumber(char: string): string { | ||
if (letterToNumberMismatches[char]) { | ||
return letterToNumberMismatches[char]; | ||
} | ||
return char; | ||
} | ||
|
||
/** | ||
* It takes a string and returns a string | ||
* @param {string} char - The character to convert. | ||
* @returns A function that takes a string and returns a string. | ||
*/ | ||
export function numberToLetter(char: string): string { | ||
if (numberToLetterMismatches[char]) { | ||
return numberToLetterMismatches[char]; | ||
} | ||
return char; | ||
} | ||
|
||
/** | ||
* It takes a string and a fieldOptions object, and returns an object with a correctedLine string and | ||
* an autocorrect array | ||
* @param {string} source - The string to be corrected | ||
* @param fieldOptions - Pick<FieldOptions, 'line' | 'type' | 'start'> | ||
* @returns An object with two properties: correctedLine and autocorrect. | ||
*/ | ||
export function autoCorrection( | ||
source: string, | ||
fieldOptions: Pick<FieldOptions, 'line' | 'type' | 'start'>, | ||
|
@@ -46,7 +58,7 @@ export function autoCorrection( | |
const autocorrect: Autocorrect[] = []; | ||
const chars = source.split(''); | ||
chars.forEach((char, i) => { | ||
if (fieldOptions.type === fieldTypes.ALPHABETIC) { | ||
if (fieldOptions.type === 'ALPHABETIC') { | ||
const correctedChar = numberToLetter(char); | ||
if (correctedChar !== char) { | ||
autocorrect.push({ | ||
|
@@ -57,7 +69,7 @@ export function autoCorrection( | |
}); | ||
} | ||
correctedLine += correctedChar; | ||
} else if (fieldOptions.type === fieldTypes.NUMERIC) { | ||
} else if (fieldOptions.type === 'NUMERIC') { | ||
const correctedChar = letterToNumber(char); | ||
if (correctedChar !== char) { | ||
autocorrect.push({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove those (autogenerated?) comments all over the PR.
They add a lot of unnecessary noise.