This repository has been archived by the owner on May 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use default validator and translate its error message (fixes #494)…
… (#554)
- Loading branch information
1 parent
7d58d53
commit 5a1b95d
Showing
4 changed files
with
59 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const tokenizeWords = require('talisman/tokenizers/words'); | ||
|
||
const TRANSLATION_KEY_PREFIX = 'TRANSLATION_KEY:'; | ||
|
||
// Minimum of words that qualify as a sentence. | ||
const MIN_WORDS = 1; | ||
|
||
// Maximum of words allowed per sentence to keep recordings in a manageable duration. | ||
const MAX_WORDS = 14; | ||
|
||
const INVALIDATIONS = [{ | ||
fn: (sentence) => { | ||
const words = tokenizeWords(sentence); | ||
return words.length < MIN_WORDS || words.length > MAX_WORDS; | ||
}, | ||
error: `${TRANSLATION_KEY_PREFIX}sc-validation-number-of-words`, | ||
}, { | ||
regex: /[0-9]+/, | ||
error: `${TRANSLATION_KEY_PREFIX}sc-validation-no-numbers`, | ||
}, { | ||
regex: /[<>+*#@^[\]()/]/, | ||
error: `${TRANSLATION_KEY_PREFIX}sc-validation-no-symbols`, | ||
}, { | ||
// Any words consisting of uppercase letters or uppercase letters with a period | ||
// in-between are considered abbreviations or acronyms. | ||
// This currently also matches fooBAR but we most probably don't want that either | ||
// as users wouldn't know how to pronounce the uppercase letters. | ||
regex: /[A-Z]{2,}|[A-Z]+\.*[A-Z]+/, | ||
error: `${TRANSLATION_KEY_PREFIX}sc-validation-no-abbreviations`, | ||
}]; | ||
|
||
module.exports = { | ||
INVALIDATIONS, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters