ethers.js/lib.commonjs/wordlists/wordlist.js

46 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2022-09-05 16:57:11 -04:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Wordlist = void 0;
const index_js_1 = require("../utils/index.js");
2022-11-30 15:44:23 -05:00
/**
* A Wordlist represents a collection of language-specific
2023-02-12 22:14:26 -05:00
* words used to encode and devoce [[link-bip-39]] encoded data
2022-11-30 15:44:23 -05:00
* by mapping words to 11-bit values and vice versa.
*/
2022-09-05 16:57:11 -04:00
class Wordlist {
locale;
2022-11-30 15:44:23 -05:00
/**
* Creates a new Wordlist instance.
*
* Sub-classes MUST call this if they provide their own constructor,
* passing in the locale string of the language.
*
* Generally there is no need to create instances of a Wordlist,
* since each language-specific Wordlist creates an instance and
* there is no state kept internally, so they are safe to share.
*/
2022-09-05 16:57:11 -04:00
constructor(locale) {
(0, index_js_1.defineProperties)(this, { locale });
}
2022-11-30 15:44:23 -05:00
/**
* Sub-classes may override this to provide a language-specific
* method for spliting %%phrase%% into individual words.
*
* By default, %%phrase%% is split using any sequences of
* white-space as defined by regular expressions (i.e. ``/\s+/``).
*/
split(phrase) {
return phrase.toLowerCase().split(/\s+/g);
2022-09-05 16:57:11 -04:00
}
2022-11-30 15:44:23 -05:00
/**
* Sub-classes may override this to provider a language-specific
* method for joining %%words%% into a phrase.
*
* By default, %%words%% are joined by a single space.
*/
2022-09-05 16:57:11 -04:00
join(words) {
return words.join(" ");
}
}
exports.Wordlist = Wordlist;
//# sourceMappingURL=wordlist.js.map