UNPKG

markdown-proofing

Version:

A markdown proofing platform for individuals, teams, and organizations.

66 lines (48 loc) 2.25 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _analyzerResult = require('../analyzer-result'); var _analyzerResult2 = _interopRequireDefault(_analyzerResult); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var MatchWordListAnalyzer = function () { function MatchWordListAnalyzer(messageType, words) { _classCallCheck(this, MatchWordListAnalyzer); this.messageType = messageType; this.words = words; } _createClass(MatchWordListAnalyzer, [{ key: 'analyze', value: function analyze(str) { var result = new _analyzerResult2.default(); var usages = []; // Populate usages object with counts of usages this.words.forEach(function (x) { var regExp = new RegExp(x, 'gi'); var matches = str.match(regExp); if (matches && matches.length > 0) { var prop = matches[0].toLowerCase(); usages.push({ word: prop, count: matches.length }); } }); usages.sort(function (a, b) { return b.count - a.count; }); var messageItems = usages.map(function (usage) { return usage.word + ': ' + usage.count; }); if (messageItems.length > 0) { result.addMessage(this.messageType, messageItems.join(', ')); } return result; } }]); return MatchWordListAnalyzer; }(); exports.default = MatchWordListAnalyzer; module.exports = exports['default'];