mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-13 20:29:24 +00:00
refactor(common/lmlayer): extract type guard for simple wordbreaker spec
This commit is contained in:
parent
57f15578d5
commit
3013d2a4fa
1 changed files with 5 additions and 4 deletions
|
|
@ -114,12 +114,10 @@ function compileWordBreaker(spec: WordBreakerSpec): string {
|
|||
* normalizes it to a common form that the compiler can deal with.
|
||||
*/
|
||||
function normalizeWordBreakerSpec(wordBreakerSpec: LexicalModelSource["wordBreaker"]): WordBreakerSpec {
|
||||
if (!wordBreakerSpec) {
|
||||
if (wordBreakerSpec == undefined) {
|
||||
// Use the default word breaker when it's unspecified
|
||||
return { use: 'default' };
|
||||
} else if (wordBreakerSpec === "default" || wordBreakerSpec === 'ascii') {
|
||||
return { use: wordBreakerSpec };
|
||||
} else if (typeof wordBreakerSpec === "function") {
|
||||
} else if (isSimpleWordBreaker(wordBreakerSpec)) {
|
||||
// The word breaker was passed as a literal function; use its source code.
|
||||
return { use: wordBreakerSpec };
|
||||
} else if (wordBreakerSpec.use) {
|
||||
|
|
@ -129,3 +127,6 @@ function normalizeWordBreakerSpec(wordBreakerSpec: LexicalModelSource["wordBreak
|
|||
}
|
||||
}
|
||||
|
||||
function isSimpleWordBreaker(spec: WordBreakerSpec | SimpleWordBreakerSpec): spec is SimpleWordBreakerSpec {
|
||||
return typeof spec === "function" || spec === "default" || spec === "ascii";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue