markdown-proofing
Version:
A markdown proofing platform for individuals, teams, and organizations.
103 lines (71 loc) • 3.45 kB
JavaScript
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);
var _location = require('../location');
var _location2 = _interopRequireDefault(_location);
var _markdownSpellcheck = require('markdown-spellcheck');
var _markdownSpellcheck2 = _interopRequireDefault(_markdownSpellcheck);
var _spellConfig = require('markdown-spellcheck/es5/spell-config');
var _spellConfig2 = _interopRequireDefault(_spellConfig);
var _spellcheck = require('markdown-spellcheck/es5/spellcheck');
var _spellcheck2 = _interopRequireDefault(_spellcheck);
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 opts = {
ignoreAcronyms: true,
ignoreNumbers: true,
suggestions: false,
dictionary: {
language: 'en-us'
}
};
var SpellingAnalyzer = function () {
function SpellingAnalyzer() {
var args = arguments.length <= 0 || arguments[0] === undefined ? { configurationFile: './.spelling' } : arguments[0];
_classCallCheck(this, SpellingAnalyzer);
this.configurationFile = args.configurationFile;
}
_createClass(SpellingAnalyzer, [{
key: 'analyze',
value: function analyze(str) {
return this.initialize().then(function () {
var result = new _analyzerResult2.default();
var spellResult = _markdownSpellcheck2.default.spell(str, opts);
spellResult.forEach(function (x) {
result.addMessage('spelling-error', x.word, _location2.default.getLine(str, x.index), _location2.default.getLineColumn(str, x.index));
});
return result;
});
}
// The returned Promise resolves to `true` if initialization
// was not required (as in, it already took place).
// `false` is returned if initialization was ran.
}, {
key: 'initialize',
value: function initialize() {
var _this = this;
return new Promise(function (resolve) {
if (SpellingAnalyzer.initialized) {
resolve(SpellingAnalyzer.initialized);
} else {
_spellConfig2.default.initialise(_this.configurationFile, function () {
_spellcheck2.default.initialise(opts);
_spellConfig2.default.getGlobalWords().forEach(function (x) {
return _spellcheck2.default.addWord(x, /* temporary: */true);
});
SpellingAnalyzer.initialized = true;
resolve(!SpellingAnalyzer.initialized);
});
}
});
}
}]);
return SpellingAnalyzer;
}();
exports.default = SpellingAnalyzer;
SpellingAnalyzer.initialized = false;
module.exports = exports['default'];
;