-
Notifications
You must be signed in to change notification settings - Fork 448
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
Allow excluding wordlists when building for browserify #105
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,26 @@ | ||
// browserify by default only pulls in files that are hard coded in requires | ||
// In order of last to first in this file, the default wordlist will be chosen | ||
// based on what is present. (Bundles may remove wordlists they don't need) | ||
const wordlistFilenames: string[] = [ | ||
'chinese_simplified', | ||
'chinese_traditional', | ||
'korean', | ||
'french', | ||
'italian', | ||
'spanish', | ||
'japanese', | ||
'english', // Last language available in list will be the default. | ||
]; | ||
const wordlists: { [index: string]: string[] } = {}; | ||
let _default: string[] | undefined; | ||
try { | ||
_default = require('./wordlists/chinese_simplified.json'); | ||
wordlists.chinese_simplified = _default as string[]; | ||
} catch (err) {} | ||
try { | ||
_default = require('./wordlists/chinese_traditional.json'); | ||
wordlists.chinese_traditional = _default as string[]; | ||
} catch (err) {} | ||
try { | ||
_default = require('./wordlists/korean.json'); | ||
wordlists.korean = _default as string[]; | ||
} catch (err) {} | ||
try { | ||
_default = require('./wordlists/french.json'); | ||
wordlists.french = _default as string[]; | ||
} catch (err) {} | ||
try { | ||
_default = require('./wordlists/italian.json'); | ||
wordlists.italian = _default as string[]; | ||
} catch (err) {} | ||
try { | ||
_default = require('./wordlists/spanish.json'); | ||
wordlists.spanish = _default as string[]; | ||
} catch (err) {} | ||
try { | ||
_default = require('./wordlists/japanese.json'); | ||
wordlists.japanese = _default as string[]; | ||
wordlists.JA = _default as string[]; | ||
} catch (err) {} | ||
try { | ||
_default = require('./wordlists/english.json'); | ||
wordlists.english = _default as string[]; | ||
wordlists.EN = _default as string[]; | ||
} catch (err) {} | ||
wordlistFilenames.forEach(lang => { | ||
try { | ||
_default = require('./wordlists/' + lang + '.json'); | ||
wordlists[lang] = _default as string[]; | ||
if (lang === 'japanese') wordlists.JA = _default as string[]; | ||
if (lang === 'english') wordlists.EN = _default as string[]; | ||
} catch (err) {} | ||
}); | ||
|
||
// Last one to overwrite wordlist gets to be default. | ||
export { wordlists, _default }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,6 +185,18 @@ export function validateMnemonic( | |
export function setDefaultWordlist(language: string): void { | ||
const result = wordlists[language]; | ||
if (result) DEFAULT_WORDLIST = result; | ||
else | ||
throw new Error('Could not find wordlist for language "' + language + '"'); | ||
} | ||
|
||
export function getDefaultWordlist(): string { | ||
if (!DEFAULT_WORDLIST) throw new Error('No Default Wordlist set'); | ||
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. Maybe this should just return null...? 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. I think 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. Why don't you export 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. what do you mean? |
||
return Object.keys(wordlists).filter(lang => { | ||
if (lang === 'JA' || lang === 'EN') return false; | ||
return wordlists[lang].every( | ||
(word, index) => word === DEFAULT_WORDLIST![index], | ||
); | ||
})[0]; | ||
} | ||
|
||
export { wordlists } from './_wordlists'; |
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.
I expect this function to throw error if the wordlist does not exist.
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.
In addition, why don't we provide
getDefaultWordlist
as well.