index.js 950 B

12345678910111213141516171819202122232425262728293031
  1. // src/index.ts
  2. var defaultAliases = {
  3. a: ["an", "our"]
  4. };
  5. var defaultUselessWords = ["a", "an", "i", "in", "of", "s", "the"];
  6. function areDocsInformative(docs, name, {
  7. aliases = defaultAliases,
  8. uselessWords = defaultUselessWords
  9. } = {}) {
  10. const docsWords = new Set(splitTextIntoWords(docs));
  11. const nameWords = splitTextIntoWords(name);
  12. for (const nameWord of nameWords) {
  13. docsWords.delete(nameWord);
  14. }
  15. for (const uselessWord of uselessWords) {
  16. docsWords.delete(uselessWord);
  17. }
  18. return !!docsWords.size;
  19. function normalizeWord(word) {
  20. const wordLower = word.toLowerCase();
  21. return aliases[wordLower] ?? wordLower;
  22. }
  23. function splitTextIntoWords(text) {
  24. return (typeof text === "string" ? [text] : text).flatMap((name2) => {
  25. return name2.replace(/\W+/gu, " ").replace(/([a-z])([A-Z])/gu, "$1 $2").trim().split(" ");
  26. }).flatMap(normalizeWord).filter(Boolean);
  27. }
  28. }
  29. export {
  30. areDocsInformative
  31. };