Class WordLib

Hierarchy

  • WordLib

Constructors

  • Constructor for creating a new WordLib object. If a custom dictionary is supplied, language property will be ignored. Defaults to english if no argument is passed.

    Parameters

    • args: ConstructorArguments

      Object consisting of:

      • number args.language - (Optional) Pick language for wordlib. Can either be sv or en.
      • string[] args.customDictionary - (Optional) A custom dictionary as an array of strings.

      Example usage:

      const enWords = new WordLib({language: "en"});
      const customWords = new WordLib({customDictionary: ["custom", "dictionary"]})

    Returns WordLib

Properties

dictionary: string[]

Methods

  • Finds any anagrams of specified word.

    Parameters

    • word: string

      Word to find anagrams of.

    • Optional customDictionary: CustomDictionary

      Object consisting of:

      • string[] args.customDictionary - (Optional) A custom dictionary as an array of strings.

    Returns string[]

    An array of anagrams of specified word.

    Example usage:

    const enWords = new WordLib({language: "en"});
    const res = enWords.anagramsOf("orange");
    //=> ["onager"]
  • Returns an array of words that can be formed using the supplied letters.

    Parameters

    • letters: string

      Letters to form words from.

    • Optional args: LengthCustomDictionaryArgs

      Object consisting of:

      • number args.length - (Optional) Only returns words of length n.
      • string[] args.customDictionary - (Optional) A custom dictionary as an array of strings.

    Returns string[]

    An array of words, made from supplied letters.

    Example usage:

    const enWords = new WordLib({customDictionary: ["test", "set", "testing"]});
    const res = enWords.containing("estt");
    //=> ["test", "set"]
  • Returns an array of words, all ending with specified word.

    Parameters

    • word: string

      String which all words should end with.

    • Optional args: LengthCustomDictionaryArgs

    Returns string[]

    Example usage:

    const words = new WordLib({customDictionary: ["sword", "words"]});
    const res = words.endsWith("word");
    //=> ["sword"]

    Params

    number args.length - (Optional) The length of something.

    Params

    string[] args.customDictionary - (Optional) A custom dictionary as an array of strings.

  • Returns all words in dictionary.

    Returns string[]

    An array of words.

    Example usage:

    const words = new WordLib({customDictionary: ["a", "custom", "dictionary"]});
    const res = words.getDictionaryWords();
    //=> ["a", "custom", "dictionary"]
  • Returns words that can be created from known characters and allowed characters. Questionmark (?) is used as a wildcard.

    Parameters

    • word: string

      String

    • Optional args: AllowedCharactersCustomDictionaryArgs

      Object consisting of:

      • string[] CustomDictionary - (Optional) A custom dictionary as an array of strings.
      • string[] AllowedCharacters - (Optional) An array of characters which are allowed to fill in the unknown characters.

    Returns string[]

    An array of possible words.

    Example usage:

    const words = new WordLib({language: "en"});
    const res = words.getPossibleWords("h?ll?", {allowedCharacters: ["e", "l", "a", "o"]});
    //=> [ "hollo", "hallo", "hello", "holla" ]
  • Returns words that can be created from a string of characters including wildcards (Marked as '?').

    Parameters

    • letters: string

      Letters including wildcards which to form words from.

    • Optional args: LengthCustomDictionaryArgs

      Object consisting of:

      • number args.length - (Optional) Only return words of length.
      • string[] args.customDictionary - (Optional) Return words from a custom dictionary.

    Returns string[]

    An array of words that can be formed from characters including wildcards.

    Example usage:

    const words = new WordLib({language: "en"});
    const res = words.getWildcardWords("te???rgrab", { length: 10 });
    //=> [ "ratbaggery", "begartered", "gubernator", "regretably", "bergmaster", "boragewort", "grubstaker", "tunaburger", "aberrating", "arbitrages", "regretable", "arbitrager" ]
  • Returns a boolean value depending on if a word exists in dictionary.

    Parameters

    • word: string

      Word to look up.

    • Optional customDictionary: CustomDictionary

    Returns boolean

    True if word exists in dictionary, otherwise false.

    Example usage:

    const enWords = new WordLib({language: "en"});
    const res = enWords.isWord("word")
    //=> true
  • Returns all words of specified length.

    Parameters

    • length: number
    • Optional customDictionary: CustomDictionary

      Object consisting of:

      • string[] args.customDictionary - (Optional) A custom dictionary as an array of strings.

    Returns string[]

    An array of words of length specified.

    Example usage:

    const enWord = new WordLib({language: "en"});
    const res = enWord.ofLength(31);
    //=> ["dichlorodiphenyltrichloroethane"]
  • Returns all palindromes in dictiobary.

    Parameters

    • Optional args: LengthCustomDictionaryArgs

      Object consisting of:

    Returns string[]

    An array of palindromes.

    const words = new WordLib({customDictionary: ["kinnikinnik", "sms", "orange"]});
    const res = words.palindromes(10);
    //=> ["kinnikinnik"]

    Params

    number args.length - (Optional) Only return palindromes of length specified.

    Params

    string[] args.customDictionary - (Optional) A custom dictionary as an array of strings.

  • Returns a random word from dictionary.

    Parameters

    • Optional args: LengthCustomDictionaryArgs

      number args.length - (Optional) The desired length of the random word.

      • string[] args.customDictionary - (Optional) A custom dictionary as an array of strings.

    Returns string

    A randomly chosen word.

    Example usage:

    const enWords = new WordLib({language: "en"});
    const res = enWords.random();
    //=> "quiddle"
  • Returns words that are similar (according to its levenshtein distance) to specified word.

    Parameters

    • word: string

      Word to find similar words to.

    • Optional customDictionary: CustomDictionary

      Object consisting of:

      • string[] args.customDictionary - (Optional) A custom dictionary as an array of strings.

    Returns string[]

    An array of words which levenshtein distance is <= 2.

    Example usage:

    const enWords = new WordLib({language: "en"});
    const res = enWords.similarTo("typescript");
    //=> [ 'telescript', 'typoscript', 'typescripts']
  • Returns an array of words, all starting with specified word.

    Parameters

    • word: string

      String that all words should start with.

    • Optional args: LengthCustomDictionaryArgs

      Object consisting of:

      • number args.length - (Optional) The length of words returned.
      • string[] args.customDictionary - (Optional) A custom dictionary as an array of strings.

    Returns string[]

    An array of words, starting with specified word.

    Example usage:

    const words = new WordLib({customDictionary: ["sword", "words"]});
    const res = words.startsWith("word");
    //=> ["words"]

Generated using TypeDoc