Skip to content

Commit

Permalink
feat(ProjectCreateForm): added the ability to enter vowels in the pro…
Browse files Browse the repository at this point in the history
…ject key
  • Loading branch information
Troff8 committed Jun 1, 2023
1 parent a893d51 commit 832587d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/KeyInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const KeyInput: React.FC<KeyInputProps> = ({

const onInputChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = keyPredictor(e.target.value);
const newValue = keyPredictor(e.target.value, { allowVowels: true });
setInputState(newValue);

onDirty?.();
Expand Down
21 changes: 12 additions & 9 deletions src/utils/keyPredictor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export const keyPredictor = (str: string) =>
str
.trim()
// eslint-disable-next-line no-control-regex
.replace(/[^\x00-\x7F]/g, '')
// eslint-disable-next-line no-useless-escape
.replace(/[aeiou `~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]|/gi, '')
.toUpperCase()
.slice(0, 10);
export const keyPredictor = (str: string, { allowVowels } = { allowVowels: false }) => {
// eslint-disable-next-line no-control-regex
let key = str.trim().replace(/[^\x00-\x7F]/g, '');

key = allowVowels
? // eslint-disable-next-line no-useless-escape
key.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]|/gi, '')
: // eslint-disable-next-line no-useless-escape
key.replace(/[aeiouy `~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]|/gi, '');

return key.toUpperCase().slice(0, 10);
};

0 comments on commit 832587d

Please sign in to comment.