UNPKG

entity-finder

Version:
65 lines (64 loc) 2.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isComplex = exports.isAbbr = exports.filterOneWordName = exports.containsWords = exports.startsWith = void 0; const atonic = require("atonic"); const utils = require("./utils"); function startsWith(text, start) { text = atonic .lowerCase(text.trim().toLowerCase()) .replace(/[,-]+/g, " ") .trim(); start = atonic .lowerCase(start.trim().toLowerCase()) .replace(/[,-]+/g, " ") .trim(); return text.indexOf(start) === 0; } exports.startsWith = startsWith; function containsWords(text, search) { text = atonic.lowerCase(text.trim().toLowerCase()); search = atonic.lowerCase(search.trim().toLowerCase()); const textWords = text.split(/[\s,-]+/g); const searchWords = search.split(/[\s,-]+/g); for (let word of searchWords) { if (!textWords.find((tw) => tw.startsWith(word))) { return false; } } return true; } exports.containsWords = containsWords; function filterOneWordName(name, title) { const wordsCount = utils.countWords(name); if (wordsCount === 1 && name.length !== title.length) { return false; } return true; } exports.filterOneWordName = filterOneWordName; function isAbbr(name, title) { const words = title.split(/[\s-]+/g); if (words.length >= name.length) { return true; } return false; } exports.isAbbr = isAbbr; function isComplex(name, title) { const titleParts = title.split(","); if (titleParts.length > 1) { title = titleParts[0]; const wordsCount = utils.countWords(name); const titleWordsCount = utils.countWords(title); if (wordsCount === 1 && titleWordsCount === 1 && name.length === title.length) { return true; } if (wordsCount > 1 && wordsCount === titleWordsCount) { return true; } } return false; } exports.isComplex = isComplex;