1.0.4 • Published 1 year ago

slug-bip39 v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Module Documentation: slug-bip39

Description

The slug-bip39 module provides functions for working with BIP39 wordlists. These functions allow you to fetch the BIP39 wordlist from a file, pick random items from the wordlist, and generate a random "slug" by combining selected words.

Installation

No installation is required; this module is self-contained.

Usage

fetchBIP39Wordlist()

  • Reads the BIP39 wordlist from a file named "english.txt" (located in the same directory as the module).
  • Converts Windows-style line endings (\r\n) to Unix-style (\n).
  • Returns an array of BIP39 words.

pickRandomItems(arr, n)

  • Takes an array (arr) and a number (n) as input.
  • Shuffles the array randomly.
  • Selects the first n items from the shuffled array.
  • Joins the selected items with hyphens (-) and returns the resulting string.

getRandomSlug(num)

  • Takes a number (num) as input.
  • Calls fetchBIP39Wordlist() to get the BIP39 wordlist.
  • Calls pickRandomItems() to generate a random slug of num words.
  • Returns the random slug.

Example

const {
  fetchBIP39Wordlist,
  pickRandomItems,
  getRandomSlug,
} = require("./path/to/your/module");

// Example usage
(async () => {
  const wordlist = await fetchBIP39Wordlist();
  console.log("BIP39 Wordlist:", wordlist);

  const randomItems = pickRandomItems(wordlist, 5);
  console.log("Random Items:", randomItems);

  const randomSlug = await getRandomSlug(3);
  console.log("Random Slug:", randomSlug);
})();

License

This module is released under the MIT License.

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago