From bf7ab70617c691da298e305e4995305305af3f45 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Tue, 17 Jan 2017 12:13:33 -0500 Subject: [PATCH 1/5] Don't show numbers as spelling errors --- src/js/spell-checker.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/js/spell-checker.js b/src/js/spell-checker.js index eed1944..b689486 100644 --- a/src/js/spell-checker.js +++ b/src/js/spell-checker.js @@ -71,11 +71,15 @@ function CodeMirrorSpellChecker(options) { // Define what separates a word - var rx_word = "!\"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ "; + var rx_word = /^[^!\"#$%&()*+,\-./:;<=>?@\[\\\]^_`{|}~\s]+/; + + // Ignore words that are just numbers + var rx_ignore = /^[0-9]+$/; + // Get array of custom words var customWords; - + if(options.customWords && options.customWords instanceof Array) { customWords = options.customWords || []; } @@ -83,22 +87,15 @@ function CodeMirrorSpellChecker(options) { // Create the overlay and such var overlay = { token: function(stream) { - var ch = stream.peek(); - var word = ""; - - if(rx_word.includes(ch)) { - stream.next(); - return null; + var word = stream.match(rx_word, true); + if(word) { + word = word[0]; // regex match body + if(!word.match(rx_ignore) && CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word)) + return "spell-error"; // CSS class: cm-spell-error + } else { + stream.next(); // skip non-word character } - while((ch = stream.peek()) != null && !rx_word.includes(ch)) { - word += ch; - stream.next(); - } - - if(CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word) && !~customWords.indexOf(word)) - return "spell-error"; // CSS class: cm-spell-error - return null; } }; From a91999933d19d075eb385d736acf03dc72eed0c9 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Tue, 24 Jan 2017 18:23:41 -0500 Subject: [PATCH 2/5] Restore use of customWords --- src/js/spell-checker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/spell-checker.js b/src/js/spell-checker.js index b689486..5d9d08b 100644 --- a/src/js/spell-checker.js +++ b/src/js/spell-checker.js @@ -90,7 +90,7 @@ function CodeMirrorSpellChecker(options) { var word = stream.match(rx_word, true); if(word) { word = word[0]; // regex match body - if(!word.match(rx_ignore) && CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word)) + if(!word.match(rx_ignore) && CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word) && !~customWords.indexOf(word)) return "spell-error"; // CSS class: cm-spell-error } else { stream.next(); // skip non-word character @@ -119,4 +119,4 @@ CodeMirrorSpellChecker.typo; // Export -module.exports = CodeMirrorSpellChecker; \ No newline at end of file +module.exports = CodeMirrorSpellChecker; From d484ef65034236a36368680716f5ce89b414329e Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Tue, 24 Jan 2017 18:57:44 -0500 Subject: [PATCH 3/5] run gulp --- debug/spell-checker.debug.js | 442 +++++++++++++++++++++++------------ debug/spell-checker.js | 440 ++++++++++++++++++++++------------ dist/spell-checker.min.js | 3 +- src/js/spell-checker.js | 2 +- 4 files changed, 590 insertions(+), 297 deletions(-) diff --git a/debug/spell-checker.debug.js b/debug/spell-checker.debug.js index 875dfe5..f6db692 100644 --- a/debug/spell-checker.debug.js +++ b/debug/spell-checker.debug.js @@ -7,6 +7,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.CodeMirrorSpellChecker = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { throw new Error('Invalid string. Length must be a multiple of 4') } @@ -40,9 +35,19 @@ function toByteArray (b64) { // represent one byte // if there is only one, then the three characters before it represent 2 bytes // this is just a cheap hack to not do indexOf twice - placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 + return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 +} +function byteLength (b64) { // base64 is 4/3 + up to two characters of the original data + return b64.length * 3 / 4 - placeHoldersCount(b64) +} + +function toByteArray (b64) { + var i, j, l, tmp, placeHolders, arr + var len = b64.length + placeHolders = placeHoldersCount(b64) + arr = new Arr(len * 3 / 4 - placeHolders) // if there are placeholders, only get up to the last complete 4 chars @@ -2006,13 +2011,22 @@ module.exports = Array.isArray || function (arr) { },{}],6:[function(require,module,exports){ (function (Buffer,__dirname){ -'use strict'; +/* globals chrome: false */ +/* globals __dirname: false */ +/* globals require: false */ +/* globals Buffer: false */ +/* globals module: false */ /** * Typo is a JavaScript implementation of a spellchecker using hunspell-style * dictionaries. */ +var Typo; + +(function () { +"use strict"; + /** * Typo constructor. * @@ -2034,14 +2048,18 @@ module.exports = Array.isArray || function (arr) { * {String} [dictionaryPath]: path to load dictionary from in non-chrome * environment. * {Object} [flags]: flag information. - * + * {Boolean} [asyncLoad]: If true, affData and wordsData will be loaded + * asynchronously. + * {Function} [loadedCallback]: Called when both affData and wordsData + * have been loaded. Only used if asyncLoad is set to true. The parameter + * is the instantiated Typo object. * * @returns {Typo} A Typo object. */ -var Typo = function (dictionary, affData, wordsData, settings) { +Typo = function (dictionary, affData, wordsData, settings) { settings = settings || {}; - + this.dictionary = null; this.rules = {}; @@ -2054,76 +2072,137 @@ var Typo = function (dictionary, affData, wordsData, settings) { this.flags = settings.flags || {}; + this.memoized = {}; + + this.loaded = false; + + var self = this; + + var path; + + // Loop-control variables. + var i, j, _len, _jlen; + if (dictionary) { - this.dictionary = dictionary; + self.dictionary = dictionary; - if (typeof window !== 'undefined' && 'chrome' in window && 'extension' in window.chrome && 'getURL' in window.chrome.extension) { - if (!affData) affData = this._readFile(chrome.extension.getURL("lib/typo/dictionaries/" + dictionary + "/" + dictionary + ".aff")); - if (!wordsData) wordsData = this._readFile(chrome.extension.getURL("lib/typo/dictionaries/" + dictionary + "/" + dictionary + ".dic")); - } else { + // If the data is preloaded, just setup the Typo object. + if (affData && wordsData) { + setup(); + } + // Loading data for Chrome extentions. + else if (typeof window !== 'undefined' && 'chrome' in window && 'extension' in window.chrome && 'getURL' in window.chrome.extension) { + if (settings.dictionaryPath) { + path = settings.dictionaryPath; + } + else { + path = "typo/dictionaries"; + } + + if (!affData) readDataFile(chrome.extension.getURL(path + "/" + dictionary + "/" + dictionary + ".aff"), setAffData); + if (!wordsData) readDataFile(chrome.extension.getURL(path + "/" + dictionary + "/" + dictionary + ".dic"), setWordsData); + } + else { if (settings.dictionaryPath) { - var path = settings.dictionaryPath; + path = settings.dictionaryPath; } else if (typeof __dirname !== 'undefined') { - var path = __dirname + '/dictionaries'; + path = __dirname + '/dictionaries'; } else { - var path = './dictionaries'; + path = './dictionaries'; } - if (!affData) affData = this._readFile(path + "/" + dictionary + "/" + dictionary + ".aff"); - if (!wordsData) wordsData = this._readFile(path + "/" + dictionary + "/" + dictionary + ".dic"); + if (!affData) readDataFile(path + "/" + dictionary + "/" + dictionary + ".aff", setAffData); + if (!wordsData) readDataFile(path + "/" + dictionary + "/" + dictionary + ".dic", setWordsData); } + } + + function readDataFile(url, setFunc) { + var response = self._readFile(url, null, settings.asyncLoad); - this.rules = this._parseAFF(affData); + if (settings.asyncLoad) { + response.then(function(data) { + setFunc(data); + }); + } + else { + setFunc(response); + } + } + + function setAffData(data) { + affData = data; + + if (wordsData) { + setup(); + } + } + + function setWordsData(data) { + wordsData = data; + + if (affData) { + setup(); + } + } + + function setup() { + self.rules = self._parseAFF(affData); // Save the rule codes that are used in compound rules. - this.compoundRuleCodes = {}; + self.compoundRuleCodes = {}; - for (var i = 0, _len = this.compoundRules.length; i < _len; i++) { - var rule = this.compoundRules[i]; + for (i = 0, _len = self.compoundRules.length; i < _len; i++) { + var rule = self.compoundRules[i]; - for (var j = 0, _jlen = rule.length; j < _jlen; j++) { - this.compoundRuleCodes[rule[j]] = []; + for (j = 0, _jlen = rule.length; j < _jlen; j++) { + self.compoundRuleCodes[rule[j]] = []; } } - // If we add this ONLYINCOMPOUND flag to this.compoundRuleCodes, then _parseDIC + // If we add this ONLYINCOMPOUND flag to self.compoundRuleCodes, then _parseDIC // will do the work of saving the list of words that are compound-only. - if ("ONLYINCOMPOUND" in this.flags) { - this.compoundRuleCodes[this.flags.ONLYINCOMPOUND] = []; + if ("ONLYINCOMPOUND" in self.flags) { + self.compoundRuleCodes[self.flags.ONLYINCOMPOUND] = []; } - this.dictionaryTable = this._parseDIC(wordsData); + self.dictionaryTable = self._parseDIC(wordsData); // Get rid of any codes from the compound rule codes that are never used // (or that were special regex characters). Not especially necessary... - for (var i in this.compoundRuleCodes) { - if (this.compoundRuleCodes[i].length == 0) { - delete this.compoundRuleCodes[i]; + for (i in self.compoundRuleCodes) { + if (self.compoundRuleCodes[i].length === 0) { + delete self.compoundRuleCodes[i]; } } // Build the full regular expressions for each compound rule. // I have a feeling (but no confirmation yet) that this method of // testing for compound words is probably slow. - for (var i = 0, _len = this.compoundRules.length; i < _len; i++) { - var ruleText = this.compoundRules[i]; + for (i = 0, _len = self.compoundRules.length; i < _len; i++) { + var ruleText = self.compoundRules[i]; var expressionText = ""; - for (var j = 0, _jlen = ruleText.length; j < _jlen; j++) { + for (j = 0, _jlen = ruleText.length; j < _jlen; j++) { var character = ruleText[j]; - if (character in this.compoundRuleCodes) { - expressionText += "(" + this.compoundRuleCodes[character].join("|") + ")"; + if (character in self.compoundRuleCodes) { + expressionText += "(" + self.compoundRuleCodes[character].join("|") + ")"; } else { expressionText += character; } } - this.compoundRules[i] = new RegExp(expressionText, "i"); + self.compoundRules[i] = new RegExp(expressionText, "i"); + } + + self.loaded = true; + + if (settings.asyncLoad && settings.loadedCallback) { + settings.loadedCallback(self); } } @@ -2139,7 +2218,9 @@ Typo.prototype = { load : function (obj) { for (var i in obj) { - this[i] = obj[i]; + if (obj.hasOwnProperty(i)) { + this[i] = obj[i]; + } } return this; @@ -2150,22 +2231,43 @@ Typo.prototype = { * * @param {String} path The path (relative) to the file. * @param {String} [charset="ISO8859-1"] The expected charset of the file - * @returns string The file data. + * @param {Boolean} async If true, the file will be read asynchronously. For node.js this does nothing, all + * files are read synchronously. + * @returns {String} The file data if async is false, otherwise a promise object. If running node.js, the data is + * always returned. */ - _readFile : function (path, charset) { - if (!charset) charset = "utf8"; + _readFile : function (path, charset, async) { + charset = charset || "utf8"; if (typeof XMLHttpRequest !== 'undefined') { + var promise; var req = new XMLHttpRequest(); - req.open("GET", path, false); + req.open("GET", path, async); + + if (async) { + promise = new Promise(function(resolve, reject) { + req.onload = function() { + if (req.status === 200) { + resolve(req.responseText); + } + else { + reject(req.statusText); + } + }; + + req.onerror = function() { + reject(req.statusText); + } + }); + } if (req.overrideMimeType) req.overrideMimeType("text/plain; charset=" + charset); req.send(null); - return req.responseText; + return async ? promise : req.responseText; } else if (typeof require !== 'undefined') { // Node.js @@ -2203,13 +2305,16 @@ Typo.prototype = { _parseAFF : function (data) { var rules = {}; + var line, subline, numEntries, lineParts; + var i, j, _len, _jlen; + // Remove comment lines data = this._removeAffixComments(data); var lines = data.split("\n"); - for (var i = 0, _len = lines.length; i < _len; i++) { - var line = lines[i]; + for (i = 0, _len = lines.length; i < _len; i++) { + line = lines[i]; var definitionParts = line.split(/\s+/); @@ -2218,14 +2323,14 @@ Typo.prototype = { if (ruleType == "PFX" || ruleType == "SFX") { var ruleCode = definitionParts[1]; var combineable = definitionParts[2]; - var numEntries = parseInt(definitionParts[3], 10); + numEntries = parseInt(definitionParts[3], 10); var entries = []; - for (var j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) { - var line = lines[j]; + for (j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) { + subline = lines[j]; - var lineParts = line.split(/\s+/); + lineParts = subline.split(/\s+/); var charactersToRemove = lineParts[2]; var additionParts = lineParts[3].split("/"); @@ -2268,19 +2373,19 @@ Typo.prototype = { i += numEntries; } else if (ruleType === "COMPOUNDRULE") { - var numEntries = parseInt(definitionParts[1], 10); + numEntries = parseInt(definitionParts[1], 10); - for (var j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) { - var line = lines[j]; + for (j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) { + line = lines[j]; - var lineParts = line.split(/\s+/); + lineParts = line.split(/\s+/); this.compoundRules.push(lineParts[1]); } i += numEntries; } else if (ruleType === "REP") { - var lineParts = line.split(/\s+/); + lineParts = line.split(/\s+/); if (lineParts.length === 3) { this.replacementTable.push([ lineParts[1], lineParts[2] ]); @@ -2309,7 +2414,11 @@ Typo.prototype = { _removeAffixComments : function (data) { // Remove comments - data = data.replace(/#.*$/mg, ""); + // This used to remove any string starting with '#' up to the end of the line, + // but some COMPOUNDRULE definitions include '#' as part of the rule. + // I haven't seen any affix files that use comments on the same line as real data, + // so I don't think this will break anything. + data = data.replace(/^\s*#.*$/mg, ""); // Trim each line data = data.replace(/^\s\s*/m, '').replace(/\s\s*$/m, ''); @@ -2339,11 +2448,17 @@ Typo.prototype = { function addWord(word, rules) { // Some dictionaries will list the same word multiple times with different rule sets. - if (!(word in dictionaryTable) || typeof dictionaryTable[word] != 'object') { - dictionaryTable[word] = []; + if (!dictionaryTable.hasOwnProperty(word)) { + dictionaryTable[word] = null; } - dictionaryTable[word].push(rules); + if (rules.length > 0) { + if (dictionaryTable[word] === null) { + dictionaryTable[word] = []; + } + + dictionaryTable[word].push(rules); + } } // The first line is the number of words in the dictionary. @@ -2445,7 +2560,7 @@ Typo.prototype = { return flags; } else if (this.flags.FLAG === "num") { - return textCode.split(","); + return textCodes.split(","); } }, @@ -2514,6 +2629,10 @@ Typo.prototype = { */ check : function (aWord) { + if (!this.loaded) { + throw "Dictionary not loaded."; + } + // Remove leading and trailing whitespace var trimmedWord = aWord.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); @@ -2562,29 +2681,38 @@ Typo.prototype = { */ checkExact : function (word) { + if (!this.loaded) { + throw "Dictionary not loaded."; + } + var ruleCodes = this.dictionaryTable[word]; + var i, _len; + if (typeof ruleCodes === 'undefined') { // Check if this might be a compound word. if ("COMPOUNDMIN" in this.flags && word.length >= this.flags.COMPOUNDMIN) { - for (var i = 0, _len = this.compoundRules.length; i < _len; i++) { + for (i = 0, _len = this.compoundRules.length; i < _len; i++) { if (word.match(this.compoundRules[i])) { return true; } } } - - return false; + } + else if (ruleCodes === null) { + // a null (but not undefined) value for an entry in the dictionary table + // means that the word is in the dictionary but has no flags. + return true; } else if (typeof ruleCodes === 'object') { // this.dictionary['hasOwnProperty'] will be a function. - for (var i = 0, _len = ruleCodes.length; i < _len; i++) { + for (i = 0, _len = ruleCodes.length; i < _len; i++) { if (!this.hasFlag(word, "ONLYINCOMPOUND", ruleCodes[i])) { return true; } } - - return false; } + + return false; }, /** @@ -2596,9 +2724,13 @@ Typo.prototype = { */ hasFlag : function (word, flag, wordFlags) { + if (!this.loaded) { + throw "Dictionary not loaded."; + } + if (flag in this.flags) { if (typeof wordFlags === 'undefined') { - var wordFlags = Array.prototype.concat.apply([], this.dictionaryTable[word]); + wordFlags = Array.prototype.concat.apply([], this.dictionaryTable[word]); } if (wordFlags && wordFlags.indexOf(this.flags[flag]) !== -1) { @@ -2623,7 +2755,21 @@ Typo.prototype = { alphabet : "", suggest : function (word, limit) { - if (!limit) limit = 5; + if (!this.loaded) { + throw "Dictionary not loaded."; + } + + limit = limit || 5; + + if (this.memoized.hasOwnProperty(word)) { + var memoizedLimit = this.memoized[word]['limit']; + + // Only return the cached list if it's big enough or if there weren't enough suggestions + // to fill a smaller limit. + if (limit <= memoizedLimit || this.memoized[word]['suggestions'].length < memoizedLimit) { + return this.memoized[word]['suggestions'].slice(0, limit); + } + } if (this.check(word)) return []; @@ -2667,63 +2813,38 @@ Typo.prototype = { function edits1(words) { var rv = []; - for (var ii = 0, _iilen = words.length; ii < _iilen; ii++) { + var ii, i, j, _iilen, _len, _jlen; + + for (ii = 0, _iilen = words.length; ii < _iilen; ii++) { var word = words[ii]; - var splits = []; - - for (var i = 0, _len = word.length + 1; i < _len; i++) { - splits.push([ word.substring(0, i), word.substring(i, word.length) ]); - } - - var deletes = []; - - for (var i = 0, _len = splits.length; i < _len; i++) { - var s = splits[i]; + for (i = 0, _len = word.length + 1; i < _len; i++) { + var s = [ word.substring(0, i), word.substring(i) ]; if (s[1]) { - deletes.push(s[0] + s[1].substring(1)); + rv.push(s[0] + s[1].substring(1)); } - } - - var transposes = []; - - for (var i = 0, _len = splits.length; i < _len; i++) { - var s = splits[i]; - - if (s[1].length > 1) { - transposes.push(s[0] + s[1][1] + s[1][0] + s[1].substring(2)); + + // Eliminate transpositions of identical letters + if (s[1].length > 1 && s[1][1] !== s[1][0]) { + rv.push(s[0] + s[1][1] + s[1][0] + s[1].substring(2)); } - } - - var replaces = []; - - for (var i = 0, _len = splits.length; i < _len; i++) { - var s = splits[i]; - + if (s[1]) { - for (var j = 0, _jlen = self.alphabet.length; j < _jlen; j++) { - replaces.push(s[0] + self.alphabet[j] + s[1].substring(1)); + for (j = 0, _jlen = self.alphabet.length; j < _jlen; j++) { + // Eliminate replacement of a letter by itself + if (self.alphabet[j] != s[1].substring(0,1)){ + rv.push(s[0] + self.alphabet[j] + s[1].substring(1)); + } } } - } - - var inserts = []; - - for (var i = 0, _len = splits.length; i < _len; i++) { - var s = splits[i]; - + if (s[1]) { - for (var j = 0, _jlen = self.alphabet.length; j < _jlen; j++) { - replaces.push(s[0] + self.alphabet[j] + s[1]); + for (j = 0, _jlen = self.alphabet.length; j < _jlen; j++) { + rv.push(s[0] + self.alphabet[j] + s[1]); } } } - - rv = rv.concat(deletes); - rv = rv.concat(transposes); - rv = rv.concat(replaces); - rv = rv.concat(inserts); } return rv; @@ -2732,7 +2853,7 @@ Typo.prototype = { function known(words) { var rv = []; - for (var i = 0; i < words.length; i++) { + for (var i = 0, _len = words.length; i < _len; i++) { if (self.check(words[i])) { rv.push(words[i]); } @@ -2746,12 +2867,14 @@ Typo.prototype = { var ed1 = edits1([word]); var ed2 = edits1(ed1); - var corrections = known(ed1).concat(known(ed2)); + var corrections = known(ed1.concat(ed2)); + + var i, _len; // Sort the edits based on how many different ways they were created. var weighted_corrections = {}; - for (var i = 0, _len = corrections.length; i < _len; i++) { + for (i = 0, _len = corrections.length; i < _len; i++) { if (!(corrections[i] in weighted_corrections)) { weighted_corrections[corrections[i]] = 1; } @@ -2762,8 +2885,10 @@ Typo.prototype = { var sorted_corrections = []; - for (var i in weighted_corrections) { - sorted_corrections.push([ i, weighted_corrections[i] ]); + for (i in weighted_corrections) { + if (weighted_corrections.hasOwnProperty(i)) { + sorted_corrections.push([ i, weighted_corrections[i] ]); + } } function sorter(a, b) { @@ -2777,8 +2902,24 @@ Typo.prototype = { sorted_corrections.sort(sorter).reverse(); var rv = []; + + var capitalization_scheme = "lowercase"; - for (var i = 0, _len = Math.min(limit, sorted_corrections.length); i < _len; i++) { + if (word.toUpperCase() === word) { + capitalization_scheme = "uppercase"; + } + else if (word.substr(0, 1).toUpperCase() + word.substr(1).toLowerCase() === word) { + capitalization_scheme = "capitalized"; + } + + for (i = 0, _len = Math.min(limit, sorted_corrections.length); i < _len; i++) { + if ("uppercase" === capitalization_scheme) { + sorted_corrections[i][0] = sorted_corrections[i][0].toUpperCase(); + } + else if ("capitalized" === capitalization_scheme) { + sorted_corrections[i][0] = sorted_corrections[i][0].substr(0, 1).toUpperCase() + sorted_corrections[i][0].substr(1); + } + if (!self.hasFlag(sorted_corrections[i][0], "NOSUGGEST")) { rv.push(sorted_corrections[i][0]); } @@ -2787,15 +2928,21 @@ Typo.prototype = { return rv; } - return correct(word); + this.memoized[word] = { + 'suggestions': correct(word), + 'limit': limit + }; + + return this.memoized[word]['suggestions']; } }; +})(); // Support for use as a node.js module. if (typeof module !== 'undefined') { module.exports = Typo; } -}).call(this,require("buffer").Buffer,"/node_modules/typo-js") +}).call(this,require("buffer").Buffer,"/node_modules\\typo-js") },{"buffer":3,"fs":2}],7:[function(require,module,exports){ // Use strict mode (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) @@ -2871,32 +3018,31 @@ function CodeMirrorSpellChecker(options) { // Define what separates a word - var ignores, rx_word = "!\"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ "; + var rx_word = /^[^!\"#$%&()*+,\-./:;<=>?@\[\\\]^_`{|}~\s]+/; - // Get array of ignored words - if(options.ignores && options.ignores instanceof Array) { - ignores = options.ignores || []; + // Ignore words that are just numbers + var rx_ignore = /^[0-9]+$/; + + + // Get array of custom words + var customWords; + + if(options.customWords && options.customWords instanceof Array) { + customWords = options.customWords || []; } // Create the overlay and such var overlay = { token: function(stream) { - var ch = stream.peek(); - var word = ""; - - if(rx_word.includes(ch)) { - stream.next(); - return null; + var word = stream.match(rx_word, true); + if(word) { + word = word[0]; // regex match body + if(!word.match(rx_ignore) && CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word) && !~customWords.indexOf(word)) + return "spell-error"; // CSS class: cm-spell-error + } else { + stream.next(); // skip non-word character } - while((ch = stream.peek()) != null && !rx_word.includes(ch)) { - word += ch; - stream.next(); - } - - if(CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word) && !~ignores.indexOf(word)) - return "spell-error"; // CSS class: cm-spell-error - return null; } }; @@ -2923,4 +3069,4 @@ CodeMirrorSpellChecker.typo; module.exports = CodeMirrorSpellChecker; },{"typo-js":6}]},{},[7])(7) }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJub2RlX21vZHVsZXMvYmFzZTY0LWpzL2xpYi9iNjQuanMiLCJub2RlX21vZHVs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4gICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV1cbiAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAweEMwKSA9PT0gMHg4MCkge1xuICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAweDFGKSA8PCAweDYgfCAoc2Vjb25kQnl0ZSAmIDB4M0YpXG4gICAgICAgICAgICBpZiAodGVtcENvZGVQb2ludCA+IDB4N0YpIHtcbiAgICAgICAgICAgICAgY29kZVBvaW50ID0gdGVtcENvZGVQb2ludFxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBicmVha1xuICAgICAgICBjYXNlIDM6XG4gICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV1cbiAgICAgICAgICB0aGlyZEJ5dGUgPSBidWZbaSArIDJdXG4gICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMHhDMCkgPT09IDB4ODAgJiYgKHRoaXJkQnl0ZSAmIDB4QzApID09PSAweDgwKSB7XG4gICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDB4RikgPDwgMHhDIHwgKHNlY29uZEJ5dGUgJiAweDNGKSA8PCAweDYgfCAodGhpcmRCeXRlICYgMHgzRilcbiAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMHg3RkYgJiYgKHRlbXBDb2RlUG9pbnQgPCAweEQ4MDAgfHwgdGVtcENvZGVQb2ludCA+IDB4REZGRikpIHtcbiAgICAgICAgICAgICAgY29kZVBvaW50ID0gdGVtcENvZGVQb2ludFxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBicmVha1xuICAgICAgICBjYXNlIDQ6XG4gICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV1cbiAgICAgICAgICB0aGlyZEJ5dGUgPSBidWZbaSArIDJdXG4gICAgICAgICAgZm91cnRoQnl0ZSA9IGJ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O1xuQ29kZU1pcnJvclNwZWxsQ2hlY2tlci50eXBvO1xuXG5cbi8vIEV4cG9ydFxubW9kdWxlLmV4cG9ydHMgPSBDb2RlTWlycm9yU3BlbGxDaGVja2VyOyJdfQ== diff --git a/debug/spell-checker.js b/debug/spell-checker.js index 653ea9b..bf8b47a 100644 --- a/debug/spell-checker.js +++ b/debug/spell-checker.js @@ -7,6 +7,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.CodeMirrorSpellChecker = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { throw new Error('Invalid string. Length must be a multiple of 4') } @@ -40,9 +35,19 @@ function toByteArray (b64) { // represent one byte // if there is only one, then the three characters before it represent 2 bytes // this is just a cheap hack to not do indexOf twice - placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 + return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 +} +function byteLength (b64) { // base64 is 4/3 + up to two characters of the original data + return b64.length * 3 / 4 - placeHoldersCount(b64) +} + +function toByteArray (b64) { + var i, j, l, tmp, placeHolders, arr + var len = b64.length + placeHolders = placeHoldersCount(b64) + arr = new Arr(len * 3 / 4 - placeHolders) // if there are placeholders, only get up to the last complete 4 chars @@ -2005,13 +2010,22 @@ module.exports = Array.isArray || function (arr) { },{}],6:[function(require,module,exports){ (function (Buffer,__dirname){ -'use strict'; +/* globals chrome: false */ +/* globals __dirname: false */ +/* globals require: false */ +/* globals Buffer: false */ +/* globals module: false */ /** * Typo is a JavaScript implementation of a spellchecker using hunspell-style * dictionaries. */ +var Typo; + +(function () { +"use strict"; + /** * Typo constructor. * @@ -2033,14 +2047,18 @@ module.exports = Array.isArray || function (arr) { * {String} [dictionaryPath]: path to load dictionary from in non-chrome * environment. * {Object} [flags]: flag information. - * + * {Boolean} [asyncLoad]: If true, affData and wordsData will be loaded + * asynchronously. + * {Function} [loadedCallback]: Called when both affData and wordsData + * have been loaded. Only used if asyncLoad is set to true. The parameter + * is the instantiated Typo object. * * @returns {Typo} A Typo object. */ -var Typo = function (dictionary, affData, wordsData, settings) { +Typo = function (dictionary, affData, wordsData, settings) { settings = settings || {}; - + this.dictionary = null; this.rules = {}; @@ -2053,76 +2071,137 @@ var Typo = function (dictionary, affData, wordsData, settings) { this.flags = settings.flags || {}; + this.memoized = {}; + + this.loaded = false; + + var self = this; + + var path; + + // Loop-control variables. + var i, j, _len, _jlen; + if (dictionary) { - this.dictionary = dictionary; + self.dictionary = dictionary; - if (typeof window !== 'undefined' && 'chrome' in window && 'extension' in window.chrome && 'getURL' in window.chrome.extension) { - if (!affData) affData = this._readFile(chrome.extension.getURL("lib/typo/dictionaries/" + dictionary + "/" + dictionary + ".aff")); - if (!wordsData) wordsData = this._readFile(chrome.extension.getURL("lib/typo/dictionaries/" + dictionary + "/" + dictionary + ".dic")); - } else { + // If the data is preloaded, just setup the Typo object. + if (affData && wordsData) { + setup(); + } + // Loading data for Chrome extentions. + else if (typeof window !== 'undefined' && 'chrome' in window && 'extension' in window.chrome && 'getURL' in window.chrome.extension) { + if (settings.dictionaryPath) { + path = settings.dictionaryPath; + } + else { + path = "typo/dictionaries"; + } + + if (!affData) readDataFile(chrome.extension.getURL(path + "/" + dictionary + "/" + dictionary + ".aff"), setAffData); + if (!wordsData) readDataFile(chrome.extension.getURL(path + "/" + dictionary + "/" + dictionary + ".dic"), setWordsData); + } + else { if (settings.dictionaryPath) { - var path = settings.dictionaryPath; + path = settings.dictionaryPath; } else if (typeof __dirname !== 'undefined') { - var path = __dirname + '/dictionaries'; + path = __dirname + '/dictionaries'; } else { - var path = './dictionaries'; + path = './dictionaries'; } - if (!affData) affData = this._readFile(path + "/" + dictionary + "/" + dictionary + ".aff"); - if (!wordsData) wordsData = this._readFile(path + "/" + dictionary + "/" + dictionary + ".dic"); + if (!affData) readDataFile(path + "/" + dictionary + "/" + dictionary + ".aff", setAffData); + if (!wordsData) readDataFile(path + "/" + dictionary + "/" + dictionary + ".dic", setWordsData); } + } + + function readDataFile(url, setFunc) { + var response = self._readFile(url, null, settings.asyncLoad); - this.rules = this._parseAFF(affData); + if (settings.asyncLoad) { + response.then(function(data) { + setFunc(data); + }); + } + else { + setFunc(response); + } + } + + function setAffData(data) { + affData = data; + + if (wordsData) { + setup(); + } + } + + function setWordsData(data) { + wordsData = data; + + if (affData) { + setup(); + } + } + + function setup() { + self.rules = self._parseAFF(affData); // Save the rule codes that are used in compound rules. - this.compoundRuleCodes = {}; + self.compoundRuleCodes = {}; - for (var i = 0, _len = this.compoundRules.length; i < _len; i++) { - var rule = this.compoundRules[i]; + for (i = 0, _len = self.compoundRules.length; i < _len; i++) { + var rule = self.compoundRules[i]; - for (var j = 0, _jlen = rule.length; j < _jlen; j++) { - this.compoundRuleCodes[rule[j]] = []; + for (j = 0, _jlen = rule.length; j < _jlen; j++) { + self.compoundRuleCodes[rule[j]] = []; } } - // If we add this ONLYINCOMPOUND flag to this.compoundRuleCodes, then _parseDIC + // If we add this ONLYINCOMPOUND flag to self.compoundRuleCodes, then _parseDIC // will do the work of saving the list of words that are compound-only. - if ("ONLYINCOMPOUND" in this.flags) { - this.compoundRuleCodes[this.flags.ONLYINCOMPOUND] = []; + if ("ONLYINCOMPOUND" in self.flags) { + self.compoundRuleCodes[self.flags.ONLYINCOMPOUND] = []; } - this.dictionaryTable = this._parseDIC(wordsData); + self.dictionaryTable = self._parseDIC(wordsData); // Get rid of any codes from the compound rule codes that are never used // (or that were special regex characters). Not especially necessary... - for (var i in this.compoundRuleCodes) { - if (this.compoundRuleCodes[i].length == 0) { - delete this.compoundRuleCodes[i]; + for (i in self.compoundRuleCodes) { + if (self.compoundRuleCodes[i].length === 0) { + delete self.compoundRuleCodes[i]; } } // Build the full regular expressions for each compound rule. // I have a feeling (but no confirmation yet) that this method of // testing for compound words is probably slow. - for (var i = 0, _len = this.compoundRules.length; i < _len; i++) { - var ruleText = this.compoundRules[i]; + for (i = 0, _len = self.compoundRules.length; i < _len; i++) { + var ruleText = self.compoundRules[i]; var expressionText = ""; - for (var j = 0, _jlen = ruleText.length; j < _jlen; j++) { + for (j = 0, _jlen = ruleText.length; j < _jlen; j++) { var character = ruleText[j]; - if (character in this.compoundRuleCodes) { - expressionText += "(" + this.compoundRuleCodes[character].join("|") + ")"; + if (character in self.compoundRuleCodes) { + expressionText += "(" + self.compoundRuleCodes[character].join("|") + ")"; } else { expressionText += character; } } - this.compoundRules[i] = new RegExp(expressionText, "i"); + self.compoundRules[i] = new RegExp(expressionText, "i"); + } + + self.loaded = true; + + if (settings.asyncLoad && settings.loadedCallback) { + settings.loadedCallback(self); } } @@ -2138,7 +2217,9 @@ Typo.prototype = { load : function (obj) { for (var i in obj) { - this[i] = obj[i]; + if (obj.hasOwnProperty(i)) { + this[i] = obj[i]; + } } return this; @@ -2149,22 +2230,43 @@ Typo.prototype = { * * @param {String} path The path (relative) to the file. * @param {String} [charset="ISO8859-1"] The expected charset of the file - * @returns string The file data. + * @param {Boolean} async If true, the file will be read asynchronously. For node.js this does nothing, all + * files are read synchronously. + * @returns {String} The file data if async is false, otherwise a promise object. If running node.js, the data is + * always returned. */ - _readFile : function (path, charset) { - if (!charset) charset = "utf8"; + _readFile : function (path, charset, async) { + charset = charset || "utf8"; if (typeof XMLHttpRequest !== 'undefined') { + var promise; var req = new XMLHttpRequest(); - req.open("GET", path, false); + req.open("GET", path, async); + + if (async) { + promise = new Promise(function(resolve, reject) { + req.onload = function() { + if (req.status === 200) { + resolve(req.responseText); + } + else { + reject(req.statusText); + } + }; + + req.onerror = function() { + reject(req.statusText); + } + }); + } if (req.overrideMimeType) req.overrideMimeType("text/plain; charset=" + charset); req.send(null); - return req.responseText; + return async ? promise : req.responseText; } else if (typeof require !== 'undefined') { // Node.js @@ -2202,13 +2304,16 @@ Typo.prototype = { _parseAFF : function (data) { var rules = {}; + var line, subline, numEntries, lineParts; + var i, j, _len, _jlen; + // Remove comment lines data = this._removeAffixComments(data); var lines = data.split("\n"); - for (var i = 0, _len = lines.length; i < _len; i++) { - var line = lines[i]; + for (i = 0, _len = lines.length; i < _len; i++) { + line = lines[i]; var definitionParts = line.split(/\s+/); @@ -2217,14 +2322,14 @@ Typo.prototype = { if (ruleType == "PFX" || ruleType == "SFX") { var ruleCode = definitionParts[1]; var combineable = definitionParts[2]; - var numEntries = parseInt(definitionParts[3], 10); + numEntries = parseInt(definitionParts[3], 10); var entries = []; - for (var j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) { - var line = lines[j]; + for (j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) { + subline = lines[j]; - var lineParts = line.split(/\s+/); + lineParts = subline.split(/\s+/); var charactersToRemove = lineParts[2]; var additionParts = lineParts[3].split("/"); @@ -2267,19 +2372,19 @@ Typo.prototype = { i += numEntries; } else if (ruleType === "COMPOUNDRULE") { - var numEntries = parseInt(definitionParts[1], 10); + numEntries = parseInt(definitionParts[1], 10); - for (var j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) { - var line = lines[j]; + for (j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) { + line = lines[j]; - var lineParts = line.split(/\s+/); + lineParts = line.split(/\s+/); this.compoundRules.push(lineParts[1]); } i += numEntries; } else if (ruleType === "REP") { - var lineParts = line.split(/\s+/); + lineParts = line.split(/\s+/); if (lineParts.length === 3) { this.replacementTable.push([ lineParts[1], lineParts[2] ]); @@ -2308,7 +2413,11 @@ Typo.prototype = { _removeAffixComments : function (data) { // Remove comments - data = data.replace(/#.*$/mg, ""); + // This used to remove any string starting with '#' up to the end of the line, + // but some COMPOUNDRULE definitions include '#' as part of the rule. + // I haven't seen any affix files that use comments on the same line as real data, + // so I don't think this will break anything. + data = data.replace(/^\s*#.*$/mg, ""); // Trim each line data = data.replace(/^\s\s*/m, '').replace(/\s\s*$/m, ''); @@ -2338,11 +2447,17 @@ Typo.prototype = { function addWord(word, rules) { // Some dictionaries will list the same word multiple times with different rule sets. - if (!(word in dictionaryTable) || typeof dictionaryTable[word] != 'object') { - dictionaryTable[word] = []; + if (!dictionaryTable.hasOwnProperty(word)) { + dictionaryTable[word] = null; } - dictionaryTable[word].push(rules); + if (rules.length > 0) { + if (dictionaryTable[word] === null) { + dictionaryTable[word] = []; + } + + dictionaryTable[word].push(rules); + } } // The first line is the number of words in the dictionary. @@ -2444,7 +2559,7 @@ Typo.prototype = { return flags; } else if (this.flags.FLAG === "num") { - return textCode.split(","); + return textCodes.split(","); } }, @@ -2513,6 +2628,10 @@ Typo.prototype = { */ check : function (aWord) { + if (!this.loaded) { + throw "Dictionary not loaded."; + } + // Remove leading and trailing whitespace var trimmedWord = aWord.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); @@ -2561,29 +2680,38 @@ Typo.prototype = { */ checkExact : function (word) { + if (!this.loaded) { + throw "Dictionary not loaded."; + } + var ruleCodes = this.dictionaryTable[word]; + var i, _len; + if (typeof ruleCodes === 'undefined') { // Check if this might be a compound word. if ("COMPOUNDMIN" in this.flags && word.length >= this.flags.COMPOUNDMIN) { - for (var i = 0, _len = this.compoundRules.length; i < _len; i++) { + for (i = 0, _len = this.compoundRules.length; i < _len; i++) { if (word.match(this.compoundRules[i])) { return true; } } } - - return false; + } + else if (ruleCodes === null) { + // a null (but not undefined) value for an entry in the dictionary table + // means that the word is in the dictionary but has no flags. + return true; } else if (typeof ruleCodes === 'object') { // this.dictionary['hasOwnProperty'] will be a function. - for (var i = 0, _len = ruleCodes.length; i < _len; i++) { + for (i = 0, _len = ruleCodes.length; i < _len; i++) { if (!this.hasFlag(word, "ONLYINCOMPOUND", ruleCodes[i])) { return true; } } - - return false; } + + return false; }, /** @@ -2595,9 +2723,13 @@ Typo.prototype = { */ hasFlag : function (word, flag, wordFlags) { + if (!this.loaded) { + throw "Dictionary not loaded."; + } + if (flag in this.flags) { if (typeof wordFlags === 'undefined') { - var wordFlags = Array.prototype.concat.apply([], this.dictionaryTable[word]); + wordFlags = Array.prototype.concat.apply([], this.dictionaryTable[word]); } if (wordFlags && wordFlags.indexOf(this.flags[flag]) !== -1) { @@ -2622,7 +2754,21 @@ Typo.prototype = { alphabet : "", suggest : function (word, limit) { - if (!limit) limit = 5; + if (!this.loaded) { + throw "Dictionary not loaded."; + } + + limit = limit || 5; + + if (this.memoized.hasOwnProperty(word)) { + var memoizedLimit = this.memoized[word]['limit']; + + // Only return the cached list if it's big enough or if there weren't enough suggestions + // to fill a smaller limit. + if (limit <= memoizedLimit || this.memoized[word]['suggestions'].length < memoizedLimit) { + return this.memoized[word]['suggestions'].slice(0, limit); + } + } if (this.check(word)) return []; @@ -2666,63 +2812,38 @@ Typo.prototype = { function edits1(words) { var rv = []; - for (var ii = 0, _iilen = words.length; ii < _iilen; ii++) { + var ii, i, j, _iilen, _len, _jlen; + + for (ii = 0, _iilen = words.length; ii < _iilen; ii++) { var word = words[ii]; - var splits = []; - - for (var i = 0, _len = word.length + 1; i < _len; i++) { - splits.push([ word.substring(0, i), word.substring(i, word.length) ]); - } - - var deletes = []; - - for (var i = 0, _len = splits.length; i < _len; i++) { - var s = splits[i]; + for (i = 0, _len = word.length + 1; i < _len; i++) { + var s = [ word.substring(0, i), word.substring(i) ]; if (s[1]) { - deletes.push(s[0] + s[1].substring(1)); + rv.push(s[0] + s[1].substring(1)); } - } - - var transposes = []; - - for (var i = 0, _len = splits.length; i < _len; i++) { - var s = splits[i]; - - if (s[1].length > 1) { - transposes.push(s[0] + s[1][1] + s[1][0] + s[1].substring(2)); + + // Eliminate transpositions of identical letters + if (s[1].length > 1 && s[1][1] !== s[1][0]) { + rv.push(s[0] + s[1][1] + s[1][0] + s[1].substring(2)); } - } - - var replaces = []; - - for (var i = 0, _len = splits.length; i < _len; i++) { - var s = splits[i]; - + if (s[1]) { - for (var j = 0, _jlen = self.alphabet.length; j < _jlen; j++) { - replaces.push(s[0] + self.alphabet[j] + s[1].substring(1)); + for (j = 0, _jlen = self.alphabet.length; j < _jlen; j++) { + // Eliminate replacement of a letter by itself + if (self.alphabet[j] != s[1].substring(0,1)){ + rv.push(s[0] + self.alphabet[j] + s[1].substring(1)); + } } } - } - - var inserts = []; - - for (var i = 0, _len = splits.length; i < _len; i++) { - var s = splits[i]; - + if (s[1]) { - for (var j = 0, _jlen = self.alphabet.length; j < _jlen; j++) { - replaces.push(s[0] + self.alphabet[j] + s[1]); + for (j = 0, _jlen = self.alphabet.length; j < _jlen; j++) { + rv.push(s[0] + self.alphabet[j] + s[1]); } } } - - rv = rv.concat(deletes); - rv = rv.concat(transposes); - rv = rv.concat(replaces); - rv = rv.concat(inserts); } return rv; @@ -2731,7 +2852,7 @@ Typo.prototype = { function known(words) { var rv = []; - for (var i = 0; i < words.length; i++) { + for (var i = 0, _len = words.length; i < _len; i++) { if (self.check(words[i])) { rv.push(words[i]); } @@ -2745,12 +2866,14 @@ Typo.prototype = { var ed1 = edits1([word]); var ed2 = edits1(ed1); - var corrections = known(ed1).concat(known(ed2)); + var corrections = known(ed1.concat(ed2)); + + var i, _len; // Sort the edits based on how many different ways they were created. var weighted_corrections = {}; - for (var i = 0, _len = corrections.length; i < _len; i++) { + for (i = 0, _len = corrections.length; i < _len; i++) { if (!(corrections[i] in weighted_corrections)) { weighted_corrections[corrections[i]] = 1; } @@ -2761,8 +2884,10 @@ Typo.prototype = { var sorted_corrections = []; - for (var i in weighted_corrections) { - sorted_corrections.push([ i, weighted_corrections[i] ]); + for (i in weighted_corrections) { + if (weighted_corrections.hasOwnProperty(i)) { + sorted_corrections.push([ i, weighted_corrections[i] ]); + } } function sorter(a, b) { @@ -2776,8 +2901,24 @@ Typo.prototype = { sorted_corrections.sort(sorter).reverse(); var rv = []; + + var capitalization_scheme = "lowercase"; - for (var i = 0, _len = Math.min(limit, sorted_corrections.length); i < _len; i++) { + if (word.toUpperCase() === word) { + capitalization_scheme = "uppercase"; + } + else if (word.substr(0, 1).toUpperCase() + word.substr(1).toLowerCase() === word) { + capitalization_scheme = "capitalized"; + } + + for (i = 0, _len = Math.min(limit, sorted_corrections.length); i < _len; i++) { + if ("uppercase" === capitalization_scheme) { + sorted_corrections[i][0] = sorted_corrections[i][0].toUpperCase(); + } + else if ("capitalized" === capitalization_scheme) { + sorted_corrections[i][0] = sorted_corrections[i][0].substr(0, 1).toUpperCase() + sorted_corrections[i][0].substr(1); + } + if (!self.hasFlag(sorted_corrections[i][0], "NOSUGGEST")) { rv.push(sorted_corrections[i][0]); } @@ -2786,15 +2927,21 @@ Typo.prototype = { return rv; } - return correct(word); + this.memoized[word] = { + 'suggestions': correct(word), + 'limit': limit + }; + + return this.memoized[word]['suggestions']; } }; +})(); // Support for use as a node.js module. if (typeof module !== 'undefined') { module.exports = Typo; } -}).call(this,require("buffer").Buffer,"/node_modules/typo-js") +}).call(this,require("buffer").Buffer,"/node_modules\\typo-js") },{"buffer":3,"fs":2}],7:[function(require,module,exports){ // Use strict mode (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) "use strict"; @@ -2869,32 +3016,31 @@ function CodeMirrorSpellChecker(options) { // Define what separates a word - var ignores, rx_word = "!\"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ "; + var rx_word = /^[^!\"#$%&()*+,\-./:;<=>?@\[\\\]^_`{|}~\s]+/; - // Get array of ignored words - if(options.ignores && options.ignores instanceof Array) { - ignores = options.ignores || []; + // Ignore words that are just numbers + var rx_ignore = /^[0-9]+$/; + + + // Get array of custom words + var customWords; + + if(options.customWords && options.customWords instanceof Array) { + customWords = options.customWords || []; } // Create the overlay and such var overlay = { token: function(stream) { - var ch = stream.peek(); - var word = ""; - - if(rx_word.includes(ch)) { - stream.next(); - return null; + var word = stream.match(rx_word, true); + if(word) { + word = word[0]; // regex match body + if(!word.match(rx_ignore) && CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word) && !~customWords.indexOf(word)) + return "spell-error"; // CSS class: cm-spell-error + } else { + stream.next(); // skip non-word character } - while((ch = stream.peek()) != null && !rx_word.includes(ch)) { - word += ch; - stream.next(); - } - - if(CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word) && !~ignores.indexOf(word)) - return "spell-error"; // CSS class: cm-spell-error - return null; } }; diff --git a/dist/spell-checker.min.js b/dist/spell-checker.min.js index aedbac9..b9c42f3 100644 --- a/dist/spell-checker.min.js +++ b/dist/spell-checker.min.js @@ -4,4 +4,5 @@ * @link https://github.com/NextStepWebs/codemirror-spell-checker * @license MIT */ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.CodeMirrorSpellChecker=t()}}(function(){return function t(e,r,n){function i(s,a){if(!r[s]){if(!e[s]){var f="function"==typeof require&&require;if(!a&&f)return f(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var h=r[s]={exports:{}};e[s][0].call(h.exports,function(t){var r=e[s][1][t];return i(r?r:t)},h,h.exports,t,e,r,n)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;s0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===t[a-2]?2:"="===t[a-1]?1:0,s=new h(3*a/4-o),n=o>0?a-4:a;var f=0;for(e=0,r=0;e>16&255,s[f++]=i>>8&255,s[f++]=255&i;return 2===o?(i=u[t.charCodeAt(e)]<<2|u[t.charCodeAt(e+1)]>>4,s[f++]=255&i):1===o&&(i=u[t.charCodeAt(e)]<<10|u[t.charCodeAt(e+1)]<<4|u[t.charCodeAt(e+2)]>>2,s[f++]=i>>8&255,s[f++]=255&i),s}function o(t){return f[t>>18&63]+f[t>>12&63]+f[t>>6&63]+f[63&t]}function s(t,e,r){for(var n,i=[],s=e;sh?h:u+a));return 1===n?(e=t[r-1],i+=f[e>>2],i+=f[e<<4&63],i+="=="):2===n&&(e=(t[r-2]<<8)+t[r-1],i+=f[e>>10],i+=f[e>>4&63],i+=f[e<<2&63],i+="="),o.push(i),o.join("")}r.toByteArray=i,r.fromByteArray=a;var f=[],u=[],h="undefined"!=typeof Uint8Array?Uint8Array:Array;n()},{}],2:[function(t,e,r){},{}],3:[function(t,e,r){(function(e){"use strict";function n(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}function i(){return s.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(i()=i())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i().toString(16)+" bytes");return 0|t}function y(t){return+t!=t&&(t=0),s.alloc(+t)}function v(t,e){if(s.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return G(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return K(t).length;default:if(n)return G(t).length;e=(""+e).toLowerCase(),n=!0}}function w(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if(r>>>=0,e>>>=0,r<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return I(this,e,r);case"utf8":case"utf-8":return U(this,e,r);case"ascii":return M(this,e,r);case"latin1":case"binary":return x(this,e,r);case"base64":return C(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function m(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function b(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:E(t,e,r,n,i);if("number"==typeof e)return e=255&e,s.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):E(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function E(t,e,r,n,i){function o(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}var s=1,a=t.length,f=e.length;if(void 0!==n&&(n=String(n).toLowerCase(),"ucs2"===n||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,f/=2,r/=2}var u;if(i){var h=-1;for(u=r;ua&&(r=a-f),u=r;u>=0;u--){for(var l=!0,c=0;ci&&(n=i)):n=i;var o=e.length;if(o%2!==0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s239?4:o>223?3:o>191?2:1;if(i+a<=r){var f,u,h,l;switch(a){case 1:o<128&&(s=o);break;case 2:f=t[i+1],128===(192&f)&&(l=(31&o)<<6|63&f,l>127&&(s=l));break;case 3:f=t[i+1],u=t[i+2],128===(192&f)&&128===(192&u)&&(l=(15&o)<<12|(63&f)<<6|63&u,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:f=t[i+1],u=t[i+2],h=t[i+3],128===(192&f)&&128===(192&u)&&128===(192&h)&&(l=(15&o)<<18|(63&f)<<12|(63&u)<<6|63&h,l>65535&&l<1114112&&(s=l))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=a}return B(n)}function B(t){var e=t.length;if(e<=tt)return String.fromCharCode.apply(String,t);for(var r="",n=0;nn)&&(r=n);for(var i="",o=e;or)throw new RangeError("Trying to access beyond buffer length")}function L(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function D(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i>>8*(n?i:1-i)}function N(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i>>8*(n?i:3-i)&255}function k(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function F(t,e,r,n,i){return i||k(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),Q.write(t,e,r,n,23,4),r+4}function j(t,e,r,n,i){return i||k(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),Q.write(t,e,r,n,52,8),r+8}function X(t){if(t=q(t).replace(et,""),t.length<2)return"";for(;t.length%4!==0;)t+="=";return t}function q(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function z(t){return t<16?"0"+t.toString(16):t.toString(16)}function G(t,e){e=e||1/0;for(var r,n=t.length,i=null,o=[],s=0;s55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function $(t){for(var e=[],r=0;r>8,i=r%256,o.push(i),o.push(n);return o}function K(t){return Z.toByteArray(X(t))}function V(t,e,r,n){for(var i=0;i=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function J(t){return t!==t}var Z=t("base64-js"),Q=t("ieee754"),W=t("isarray");r.Buffer=s,r.SlowBuffer=y,r.INSPECT_MAX_BYTES=50,s.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:n(),r.kMaxLength=i(),s.poolSize=8192,s._augment=function(t){return t.__proto__=s.prototype,t},s.from=function(t,e,r){return a(null,t,e,r)},s.TYPED_ARRAY_SUPPORT&&(s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&s[Symbol.species]===s&&Object.defineProperty(s,Symbol.species,{value:null,configurable:!0})),s.alloc=function(t,e,r){return u(null,t,e,r)},s.allocUnsafe=function(t){return h(null,t)},s.allocUnsafeSlow=function(t){return h(null,t)},s.isBuffer=function(t){return!(null==t||!t._isBuffer)},s.compare=function(t,e){if(!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},s.prototype.compare=function(t,e,r,n,i){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(e>>>=0,r>>>=0,n>>>=0,i>>>=0,this===t)return 0;for(var o=i-n,a=r-e,f=Math.min(o,a),u=this.slice(n,i),h=t.slice(e,r),l=0;li)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return _(this,t,e,r);case"utf8":case"utf-8":return R(this,t,e,r);case"ascii":return A(this,t,e,r);case"latin1":case"binary":return T(this,t,e,r);case"base64":return P(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var tt=4096;s.prototype.slice=function(t,e){var r=this.length;t=~~t,e=void 0===e?r:~~e,t<0?(t+=r,t<0&&(t=0)):t>r&&(t=r),e<0?(e+=r,e<0&&(e=0)):e>r&&(e=r),e0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUInt8=function(t,e){return e||Y(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return e||Y(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return e||Y(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return e||Y(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUInt32BE=function(t,e){return e||Y(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,r){t=0|t,e=0|e,r||Y(t,e,this.length);for(var n=this[t],i=1,o=0;++o=i&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t=0|t,e=0|e,r||Y(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return e||Y(t,1,this.length),128&this[t]?(255-this[t]+1)*-1:this[t]},s.prototype.readInt16LE=function(t,e){e||Y(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){e||Y(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return e||Y(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return e||Y(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return e||Y(t,4,this.length),Q.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return e||Y(t,4,this.length),Q.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return e||Y(t,8,this.length),Q.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return e||Y(t,8,this.length),Q.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,r,n){if(t=+t,e=0|e,r=0|r,!n){var i=Math.pow(2,8*r)-1;L(this,t,e,r,i,0)}var o=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+o]=t/s&255;return e+r},s.prototype.writeUInt8=function(t,e,r){return t=+t,e=0|e,r||L(this,t,e,1,255,0),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e=0|e,r||L(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):D(this,t,e,!0),e+2},s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e=0|e,r||L(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):D(this,t,e,!1),e+2},s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e=0|e,r||L(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):N(this,t,e,!0),e+4},s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e=0|e,r||L(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o>0)-a&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);L(this,t,e,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e=0|e,r||L(this,t,e,1,127,-128),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e=0|e,r||L(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):D(this,t,e,!0),e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e=0|e,r||L(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):D(this,t,e,!1),e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e=0|e,r||L(this,t,e,4,2147483647,-2147483648),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):N(this,t,e,!0),e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e=0|e,r||L(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},s.prototype.writeFloatLE=function(t,e,r){return F(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return F(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return j(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return j(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--i)t[i+e]=this[i+r];else if(o<1e3||!s.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,t||(t=0);var o;if("number"==typeof t)for(o=e;o>1,h=-7,l=r?i-1:0,c=r?-1:1,p=t[e+l];for(l+=c,o=p&(1<<-h)-1,p>>=-h,h+=a;h>0;o=256*o+t[e+l],l+=c,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+t[e+l],l+=c,h-=8);if(0===o)o=1-u;else{if(o===f)return s?NaN:(p?-1:1)*(1/0);s+=Math.pow(2,n),o-=u}return(p?-1:1)*s*Math.pow(2,o-n)},r.write=function(t,e,r,n,i,o){var s,a,f,u=8*o-i-1,h=(1<>1,c=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(f=Math.pow(2,-s))<1&&(s--,f*=2),e+=s+l>=1?c/f:c*Math.pow(2,1-l),e*f>=2&&(s++,f/=2),s+l>=h?(a=0,s=h):s+l>=1?(a=(e*f-1)*Math.pow(2,i),s+=l):(a=e*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;t[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<0;t[r+p]=255&s,p+=d,s/=256,u-=8);t[r+p-d]|=128*g}},{}],5:[function(t,e,r){var n={}.toString;e.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},{}],6:[function(t,e,r){(function(r,n){"use strict";var i=function(t,e,r,i){if(i=i||{},this.dictionary=null,this.rules={},this.dictionaryTable={},this.compoundRules=[],this.compoundRuleCodes={},this.replacementTable=[],this.flags=i.flags||{},t){if(this.dictionary=t,"undefined"!=typeof window&&"chrome"in window&&"extension"in window.chrome&&"getURL"in window.chrome.extension)e||(e=this._readFile(chrome.extension.getURL("lib/typo/dictionaries/"+t+"/"+t+".aff"))),r||(r=this._readFile(chrome.extension.getURL("lib/typo/dictionaries/"+t+"/"+t+".dic")));else{if(i.dictionaryPath)var o=i.dictionaryPath;else if("undefined"!=typeof n)var o=n+"/dictionaries";else var o="./dictionaries";e||(e=this._readFile(o+"/"+t+"/"+t+".aff")),r||(r=this._readFile(o+"/"+t+"/"+t+".dic"))}this.rules=this._parseAFF(e),this.compoundRuleCodes={};for(var s=0,a=this.compoundRules.length;s0&&(b.continuationClasses=w),"."!==m&&("SFX"===a?b.match=new RegExp(m+"$"):b.match=new RegExp("^"+m)),"0"!=g&&("SFX"===a?b.remove=new RegExp(g+"$"):b.remove=g),l.push(b)}e[f]={type:a,combineable:"Y"==u,entries:l},n+=h}else if("COMPOUNDRULE"===a){for(var h=parseInt(s[1],10),c=n+1,p=n+1+h;c1){var u=this.parseRuleCodes(a[1]);"NEEDAFFIX"in this.flags&&u.indexOf(this.flags.NEEDAFFIX)!=-1||e(f,u);for(var h=0,l=u.length;h=this.flags.COMPOUNDMIN)for(var r=0,n=this.compoundRules.length;r1&&l.push(h[0]+h[1][1]+h[1][0]+h[1].substring(2))}for(var c=[],s=0,a=o.length;s0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function i(t){return 3*t.length/4-n(t)}function o(t){var e,r,i,o,s,a,u=t.length;s=n(t),a=new l(3*u/4-s),i=s>0?u-4:u;var f=0;for(e=0,r=0;e>16&255,a[f++]=o>>8&255,a[f++]=255&o;return 2===s?(o=h[t.charCodeAt(e)]<<2|h[t.charCodeAt(e+1)]>>4,a[f++]=255&o):1===s&&(o=h[t.charCodeAt(e)]<<10|h[t.charCodeAt(e+1)]<<4|h[t.charCodeAt(e+2)]>>2,a[f++]=o>>8&255,a[f++]=255&o),a}function s(t){return f[t>>18&63]+f[t>>12&63]+f[t>>6&63]+f[63&t]}function a(t,e,r){for(var n,i=[],o=e;oh?h:u+s));return 1===n?(e=t[r-1],i+=f[e>>2],i+=f[e<<4&63],i+="=="):2===n&&(e=(t[r-2]<<8)+t[r-1],i+=f[e>>10],i+=f[e>>4&63],i+=f[e<<2&63],i+="="),o.push(i),o.join("")}r.byteLength=i,r.toByteArray=o,r.fromByteArray=u;for(var f=[],h=[],l="undefined"!=typeof Uint8Array?Uint8Array:Array,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=0,d=c.length;p=i())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i().toString(16)+" bytes");return 0|t}function y(t){return+t!=t&&(t=0),s.alloc(+t)}function v(t,e){if(s.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return $(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return W(t).length;default:if(n)return $(t).length;e=(""+e).toLowerCase(),n=!0}}function w(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if(r>>>=0,e>>>=0,r<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return I(this,e,r);case"utf8":case"utf-8":return S(this,e,r);case"ascii":return x(this,e,r);case"latin1":case"binary":return M(this,e,r);case"base64":return U(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function m(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function b(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:E(t,e,r,n,i);if("number"==typeof e)return e=255&e,s.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):E(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function E(t,e,r,n,i){function o(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}var s=1,a=t.length,u=e.length;if(void 0!==n&&(n=String(n).toLowerCase(),"ucs2"===n||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,r/=2}var f;if(i){var h=-1;for(f=r;fa&&(r=a-u),f=r;f>=0;f--){for(var l=!0,c=0;ci&&(n=i)):n=i;var o=e.length;if(o%2!==0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s239?4:o>223?3:o>191?2:1;if(i+a<=r){var u,f,h,l;switch(a){case 1:o<128&&(s=o);break;case 2:u=t[i+1],128===(192&u)&&(l=(31&o)<<6|63&u,l>127&&(s=l));break;case 3:u=t[i+1],f=t[i+2],128===(192&u)&&128===(192&f)&&(l=(15&o)<<12|(63&u)<<6|63&f,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:u=t[i+1],f=t[i+2],h=t[i+3],128===(192&u)&&128===(192&f)&&128===(192&h)&&(l=(15&o)<<18|(63&u)<<12|(63&f)<<6|63&h,l>65535&&l<1114112&&(s=l))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=a}return B(n)}function B(t){var e=t.length;if(e<=tt)return String.fromCharCode.apply(String,t);for(var r="",n=0;nn)&&(r=n);for(var i="",o=e;or)throw new RangeError("Trying to access beyond buffer length")}function Y(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function D(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i>>8*(n?i:1-i)}function N(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i>>8*(n?i:3-i)&255}function k(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function F(t,e,r,n,i){return i||k(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),Z.write(t,e,r,n,23,4),r+4}function z(t,e,r,n,i){return i||k(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),Z.write(t,e,r,n,52,8),r+8}function j(t){if(t=X(t).replace(et,""),t.length<2)return"";for(;t.length%4!==0;)t+="=";return t}function X(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function q(t){return t<16?"0"+t.toString(16):t.toString(16)}function $(t,e){e=e||1/0;for(var r,n=t.length,i=null,o=[],s=0;s55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function G(t){for(var e=[],r=0;r>8,i=r%256,o.push(i),o.push(n);return o}function W(t){return J.toByteArray(j(t))}function K(t,e,r,n){for(var i=0;i=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function V(t){return t!==t}var J=t("base64-js"),Z=t("ieee754"),Q=t("isarray");r.Buffer=s,r.SlowBuffer=y,r.INSPECT_MAX_BYTES=50,s.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:n(),r.kMaxLength=i(),s.poolSize=8192,s._augment=function(t){return t.__proto__=s.prototype,t},s.from=function(t,e,r){return a(null,t,e,r)},s.TYPED_ARRAY_SUPPORT&&(s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&s[Symbol.species]===s&&Object.defineProperty(s,Symbol.species,{value:null,configurable:!0})),s.alloc=function(t,e,r){return f(null,t,e,r)},s.allocUnsafe=function(t){return h(null,t)},s.allocUnsafeSlow=function(t){return h(null,t)},s.isBuffer=function(t){return!(null==t||!t._isBuffer)},s.compare=function(t,e){if(!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},s.prototype.compare=function(t,e,r,n,i){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(e>>>=0,r>>>=0,n>>>=0,i>>>=0,this===t)return 0;for(var o=i-n,a=r-e,u=Math.min(o,a),f=this.slice(n,i),h=t.slice(e,r),l=0;li)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return R(this,t,e,r);case"utf8":case"utf-8":return _(this,t,e,r);case"ascii":return A(this,t,e,r);case"latin1":case"binary":return P(this,t,e,r);case"base64":return T(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var tt=4096;s.prototype.slice=function(t,e){var r=this.length;t=~~t,e=void 0===e?r:~~e,t<0?(t+=r,t<0&&(t=0)):t>r&&(t=r),e<0?(e+=r,e<0&&(e=0)):e>r&&(e=r),e0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUInt8=function(t,e){return e||L(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return e||L(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return e||L(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return e||L(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUInt32BE=function(t,e){return e||L(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,r){t=0|t,e=0|e,r||L(t,e,this.length);for(var n=this[t],i=1,o=0;++o=i&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t=0|t,e=0|e,r||L(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return e||L(t,1,this.length),128&this[t]?(255-this[t]+1)*-1:this[t]},s.prototype.readInt16LE=function(t,e){e||L(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){e||L(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return e||L(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return e||L(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return e||L(t,4,this.length),Z.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return e||L(t,4,this.length),Z.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return e||L(t,8,this.length),Z.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return e||L(t,8,this.length),Z.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,r,n){if(t=+t,e=0|e,r=0|r,!n){var i=Math.pow(2,8*r)-1;Y(this,t,e,r,i,0)}var o=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+o]=t/s&255;return e+r},s.prototype.writeUInt8=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,1,255,0),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):D(this,t,e,!0),e+2},s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):D(this,t,e,!1),e+2},s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):N(this,t,e,!0),e+4},s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);Y(this,t,e,r,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o>0)-a&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);Y(this,t,e,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,1,127,-128),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):D(this,t,e,!0),e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):D(this,t,e,!1),e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,4,2147483647,-2147483648),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):N(this,t,e,!0),e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},s.prototype.writeFloatLE=function(t,e,r){return F(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return F(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return z(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return z(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--i)t[i+e]=this[i+r];else if(o<1e3||!s.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,t||(t=0);var o;if("number"==typeof t)for(o=e;o>1,h=-7,l=r?i-1:0,c=r?-1:1,p=t[e+l];for(l+=c,o=p&(1<<-h)-1,p>>=-h,h+=a;h>0;o=256*o+t[e+l],l+=c,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+t[e+l],l+=c,h-=8);if(0===o)o=1-f;else{if(o===u)return s?NaN:(p?-1:1)*(1/0);s+=Math.pow(2,n),o-=f}return(p?-1:1)*s*Math.pow(2,o-n)},r.write=function(t,e,r,n,i,o){var s,a,u,f=8*o-i-1,h=(1<>1,c=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),e+=s+l>=1?c/u:c*Math.pow(2,1-l),e*u>=2&&(s++,u/=2),s+l>=h?(a=0,s=h):s+l>=1?(a=(e*u-1)*Math.pow(2,i),s+=l):(a=e*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;t[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<0;t[r+p]=255&s,p+=d,s/=256,f-=8);t[r+p-d]|=128*g}},{}],5:[function(t,e,r){var n={}.toString;e.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},{}],6:[function(t,e,r){(function(r,n){var i;!function(){"use strict";i=function(t,e,r,i){function o(t,e){var r=d._readFile(t,null,i.asyncLoad);i.asyncLoad?r.then(function(t){e(t)}):e(r)}function s(t){e=t,r&&u()}function a(t){r=t,e&&u()}function u(){for(d.rules=d._parseAFF(e),d.compoundRuleCodes={},h=0,c=d.compoundRules.length;h0&&(E.continuationClasses=m),"."!==b&&("SFX"===c?E.match=new RegExp(b+"$"):E.match=new RegExp("^"+b)),"0"!=y&&("SFX"===c?E.remove=new RegExp(y+"$"):E.remove=y),g.push(E)}f[p]={type:c,combineable:"Y"==d,entries:g},o+=n}else if("COMPOUNDRULE"===c){for(n=parseInt(l[1],10),s=o+1,u=o+1+n;s0&&(null===n[t]&&(n[t]=[]),n[t].push(e))}t=this._removeDicComments(t);for(var r=t.split("\n"),n={},i=1,o=r.length;i1){var f=this.parseRuleCodes(a[1]);"NEEDAFFIX"in this.flags&&f.indexOf(this.flags.NEEDAFFIX)!=-1||e(u,f);for(var h=0,l=f.length;h=this.flags.COMPOUNDMIN)for(e=0,r=this.compoundRules.length;e1&&f[1][1]!==f[1][0]&&a.push(f[0]+f[1][1]+f[1][0]+f[1].substring(2)),f[1])for(n=0,s=h.alphabet.length;n?@\[\\\]^_`{|}~\s]+/,u=/^[0-9]+$/;t.customWords&&t.customWords instanceof Array&&(s=t.customWords||[]);var f={token:function(t){var e=t.match(a,!0);if(e){if(e=e[0],!e.match(u)&&n.typo&&!n.typo.check(e)&&!~s.indexOf(e))return"spell-error"}else t.next();return null}},h=t.codeMirrorInstance.getMode(e,e.backdrop||"text/plain");return t.codeMirrorInstance.overlayMode(h,f,!0)}))}var i=t("typo-js");n.num_loaded=0,n.aff_loading=!1,n.dic_loading=!1,n.aff_data="",n.dic_data="",n.typo,e.exports=n},{"typo-js":6}]},{},[7])(7)}); \ No newline at end of file diff --git a/src/js/spell-checker.js b/src/js/spell-checker.js index 5d9d08b..26a6b5a 100644 --- a/src/js/spell-checker.js +++ b/src/js/spell-checker.js @@ -119,4 +119,4 @@ CodeMirrorSpellChecker.typo; // Export -module.exports = CodeMirrorSpellChecker; +module.exports = CodeMirrorSpellChecker; \ No newline at end of file From 6517c3c6fcc60dd76e82e32bcea459fadcf588ae Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Mon, 25 Mar 2019 13:55:51 -0400 Subject: [PATCH 4/5] Specify working version of gulp and get lint to work again --- package.json | 2 +- src/js/spell-checker.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7c3be6e..bb2db6e 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "browserify": "*", "debug": "*", "eslint": "*", - "gulp": "*", + "gulp": "3.9.1", "gulp-clean-css": "*", "gulp-concat": "*", "gulp-debug": "*", diff --git a/src/js/spell-checker.js b/src/js/spell-checker.js index 26a6b5a..97470dd 100644 --- a/src/js/spell-checker.js +++ b/src/js/spell-checker.js @@ -71,7 +71,7 @@ function CodeMirrorSpellChecker(options) { // Define what separates a word - var rx_word = /^[^!\"#$%&()*+,\-./:;<=>?@\[\\\]^_`{|}~\s]+/; + var rx_word = /^[^!"#$%&()*+,\-./:;<=>?@[\\\]^_`{|}~\s]+/; // Ignore words that are just numbers var rx_ignore = /^[0-9]+$/; From 8a1815df7749f0a91fe3960a33e9d57ea1ce7f25 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Mon, 25 Mar 2019 13:56:13 -0400 Subject: [PATCH 5/5] Fix customWords bugs --- debug/spell-checker.debug.js | 777 ++++++++++++++++++----------------- debug/spell-checker.js | 776 +++++++++++++++++----------------- dist/spell-checker.min.js | 3 +- src/js/spell-checker.js | 4 +- 4 files changed, 798 insertions(+), 762 deletions(-) diff --git a/debug/spell-checker.debug.js b/debug/spell-checker.debug.js index f6db692..704dfbc 100644 --- a/debug/spell-checker.debug.js +++ b/debug/spell-checker.debug.js @@ -4,7 +4,7 @@ * @link https://github.com/NextStepWebs/codemirror-spell-checker * @license MIT */ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.CodeMirrorSpellChecker = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { throw new Error('Invalid string. Length must be a multiple of 4') } - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 + // Trim off extra bytes after placeholder bytes are found + // See: https://github.com/beatgammit/base64-js/issues/42 + var validLen = b64.indexOf('=') + if (validLen === -1) validLen = len + + var placeHoldersLen = validLen === len + ? 0 + : 4 - (validLen % 4) + + return [validLen, placeHoldersLen] } +// base64 is 4/3 + up to two characters of the original data function byteLength (b64) { - // base64 is 4/3 + up to two characters of the original data - return b64.length * 3 / 4 - placeHoldersCount(b64) + var lens = getLens(b64) + var validLen = lens[0] + var placeHoldersLen = lens[1] + return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen +} + +function _byteLength (b64, validLen, placeHoldersLen) { + return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen } function toByteArray (b64) { - var i, j, l, tmp, placeHolders, arr - var len = b64.length - placeHolders = placeHoldersCount(b64) + var tmp + var lens = getLens(b64) + var validLen = lens[0] + var placeHoldersLen = lens[1] + + var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) - arr = new Arr(len * 3 / 4 - placeHolders) + var curByte = 0 // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? len - 4 : len + var len = placeHoldersLen > 0 + ? validLen - 4 + : validLen - var L = 0 + for (var i = 0; i < len; i += 4) { + tmp = + (revLookup[b64.charCodeAt(i)] << 18) | + (revLookup[b64.charCodeAt(i + 1)] << 12) | + (revLookup[b64.charCodeAt(i + 2)] << 6) | + revLookup[b64.charCodeAt(i + 3)] + arr[curByte++] = (tmp >> 16) & 0xFF + arr[curByte++] = (tmp >> 8) & 0xFF + arr[curByte++] = tmp & 0xFF + } - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] - arr[L++] = (tmp >> 16) & 0xFF - arr[L++] = (tmp >> 8) & 0xFF - arr[L++] = tmp & 0xFF + if (placeHoldersLen === 2) { + tmp = + (revLookup[b64.charCodeAt(i)] << 2) | + (revLookup[b64.charCodeAt(i + 1)] >> 4) + arr[curByte++] = tmp & 0xFF } - if (placeHolders === 2) { - tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) - arr[L++] = tmp & 0xFF - } else if (placeHolders === 1) { - tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) - arr[L++] = (tmp >> 8) & 0xFF - arr[L++] = tmp & 0xFF + if (placeHoldersLen === 1) { + tmp = + (revLookup[b64.charCodeAt(i)] << 10) | + (revLookup[b64.charCodeAt(i + 1)] << 4) | + (revLookup[b64.charCodeAt(i + 2)] >> 2) + arr[curByte++] = (tmp >> 8) & 0xFF + arr[curByte++] = tmp & 0xFF } return arr } function tripletToBase64 (num) { - return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] + return lookup[num >> 18 & 0x3F] + + lookup[num >> 12 & 0x3F] + + lookup[num >> 6 & 0x3F] + + lookup[num & 0x3F] } function encodeChunk (uint8, start, end) { var tmp var output = [] for (var i = start; i < end; i += 3) { - tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + tmp = + ((uint8[i] << 16) & 0xFF0000) + + ((uint8[i + 1] << 8) & 0xFF00) + + (uint8[i + 2] & 0xFF) output.push(tripletToBase64(tmp)) } return output.join('') @@ -92,42 +126,45 @@ function fromByteArray (uint8) { var tmp var len = uint8.length var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes - var output = '' var parts = [] var maxChunkLength = 16383 // must be multiple of 3 // go through the array every three bytes, we'll deal with trailing stuff later for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) + parts.push(encodeChunk( + uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength) + )) } // pad the end with zeros, but make sure to not forget the extra bytes if (extraBytes === 1) { tmp = uint8[len - 1] - output += lookup[tmp >> 2] - output += lookup[(tmp << 4) & 0x3F] - output += '==' + parts.push( + lookup[tmp >> 2] + + lookup[(tmp << 4) & 0x3F] + + '==' + ) } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) - output += lookup[tmp >> 10] - output += lookup[(tmp >> 4) & 0x3F] - output += lookup[(tmp << 2) & 0x3F] - output += '=' + tmp = (uint8[len - 2] << 8) + uint8[len - 1] + parts.push( + lookup[tmp >> 10] + + lookup[(tmp >> 4) & 0x3F] + + lookup[(tmp << 2) & 0x3F] + + '=' + ) } - parts.push(output) - return parts.join('') } },{}],2:[function(require,module,exports){ },{}],3:[function(require,module,exports){ -(function (global){ +(function (Buffer){ /*! * The buffer module from node.js, for the browser. * - * @author Feross Aboukhadijeh + * @author Feross Aboukhadijeh * @license MIT */ /* eslint-disable no-proto */ @@ -136,80 +173,73 @@ function fromByteArray (uint8) { var base64 = require('base64-js') var ieee754 = require('ieee754') -var isArray = require('isarray') exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer exports.INSPECT_MAX_BYTES = 50 +var K_MAX_LENGTH = 0x7fffffff +exports.kMaxLength = K_MAX_LENGTH + /** * If `Buffer.TYPED_ARRAY_SUPPORT`: * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) + * === false Print warning and recommend using `buffer` v4.x which has an Object + * implementation (most compatible, even IE6) * * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * - * Due to various browser bugs, sometimes the Object implementation will be used even - * when the browser supports typed arrays. - * - * Note: - * - * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. - - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they - * get the Object implementation, which is slower but behaves correctly. + * We report that the browser does not support typed arrays if the are not subclassable + * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` + * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support + * for __proto__ and has a buggy typed array implementation. */ -Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined - ? global.TYPED_ARRAY_SUPPORT - : typedArraySupport() +Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() -/* - * Export kMaxLength after typed array support is determined. - */ -exports.kMaxLength = kMaxLength() +if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && + typeof console.error === 'function') { + console.error( + 'This browser lacks typed array (Uint8Array) support which is required by ' + + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' + ) +} function typedArraySupport () { + // Can typed array instances can be augmented? try { var arr = new Uint8Array(1) - arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} - return arr.foo() === 42 && // typed array instances can be augmented - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } } + return arr.foo() === 42 } catch (e) { return false } } -function kMaxLength () { - return Buffer.TYPED_ARRAY_SUPPORT - ? 0x7fffffff - : 0x3fffffff -} - -function createBuffer (that, length) { - if (kMaxLength() < length) { - throw new RangeError('Invalid typed array length') +Object.defineProperty(Buffer.prototype, 'parent', { + enumerable: true, + get: function () { + if (!Buffer.isBuffer(this)) return undefined + return this.buffer } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = new Uint8Array(length) - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - if (that === null) { - that = new Buffer(length) - } - that.length = length +}) + +Object.defineProperty(Buffer.prototype, 'offset', { + enumerable: true, + get: function () { + if (!Buffer.isBuffer(this)) return undefined + return this.byteOffset } +}) - return that +function createBuffer (length) { + if (length > K_MAX_LENGTH) { + throw new RangeError('The value "' + length + '" is invalid for option "size"') + } + // Return an augmented `Uint8Array` instance + var buf = new Uint8Array(length) + buf.__proto__ = Buffer.prototype + return buf } /** @@ -223,44 +253,77 @@ function createBuffer (that, length) { */ function Buffer (arg, encodingOrOffset, length) { - if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { - return new Buffer(arg, encodingOrOffset, length) - } - // Common case. if (typeof arg === 'number') { if (typeof encodingOrOffset === 'string') { - throw new Error( - 'If encoding is specified then the first argument must be a string' + throw new TypeError( + 'The "string" argument must be of type string. Received type number' ) } - return allocUnsafe(this, arg) + return allocUnsafe(arg) } - return from(this, arg, encodingOrOffset, length) + return from(arg, encodingOrOffset, length) +} + +// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 +if (typeof Symbol !== 'undefined' && Symbol.species != null && + Buffer[Symbol.species] === Buffer) { + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true, + enumerable: false, + writable: false + }) } Buffer.poolSize = 8192 // not used by this implementation -// TODO: Legacy, not needed anymore. Remove in next major version. -Buffer._augment = function (arr) { - arr.__proto__ = Buffer.prototype - return arr -} +function from (value, encodingOrOffset, length) { + if (typeof value === 'string') { + return fromString(value, encodingOrOffset) + } + + if (ArrayBuffer.isView(value)) { + return fromArrayLike(value) + } + + if (value == null) { + throw TypeError( + 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + + 'or Array-like Object. Received type ' + (typeof value) + ) + } + + if (isInstance(value, ArrayBuffer) || + (value && isInstance(value.buffer, ArrayBuffer))) { + return fromArrayBuffer(value, encodingOrOffset, length) + } -function from (that, value, encodingOrOffset, length) { if (typeof value === 'number') { - throw new TypeError('"value" argument must not be a number') + throw new TypeError( + 'The "value" argument must not be of type number. Received type number' + ) } - if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { - return fromArrayBuffer(that, value, encodingOrOffset, length) + var valueOf = value.valueOf && value.valueOf() + if (valueOf != null && valueOf !== value) { + return Buffer.from(valueOf, encodingOrOffset, length) } - if (typeof value === 'string') { - return fromString(that, value, encodingOrOffset) + var b = fromObject(value) + if (b) return b + + if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && + typeof value[Symbol.toPrimitive] === 'function') { + return Buffer.from( + value[Symbol.toPrimitive]('string'), encodingOrOffset, length + ) } - return fromObject(that, value) + throw new TypeError( + 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + + 'or Array-like Object. Received type ' + (typeof value) + ) } /** @@ -272,44 +335,36 @@ function from (that, value, encodingOrOffset, length) { * Buffer.from(arrayBuffer[, byteOffset[, length]]) **/ Buffer.from = function (value, encodingOrOffset, length) { - return from(null, value, encodingOrOffset, length) + return from(value, encodingOrOffset, length) } -if (Buffer.TYPED_ARRAY_SUPPORT) { - Buffer.prototype.__proto__ = Uint8Array.prototype - Buffer.__proto__ = Uint8Array - if (typeof Symbol !== 'undefined' && Symbol.species && - Buffer[Symbol.species] === Buffer) { - // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 - Object.defineProperty(Buffer, Symbol.species, { - value: null, - configurable: true - }) - } -} +// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: +// https://github.com/feross/buffer/pull/148 +Buffer.prototype.__proto__ = Uint8Array.prototype +Buffer.__proto__ = Uint8Array function assertSize (size) { if (typeof size !== 'number') { - throw new TypeError('"size" argument must be a number') + throw new TypeError('"size" argument must be of type number') } else if (size < 0) { - throw new RangeError('"size" argument must not be negative') + throw new RangeError('The value "' + size + '" is invalid for option "size"') } } -function alloc (that, size, fill, encoding) { +function alloc (size, fill, encoding) { assertSize(size) if (size <= 0) { - return createBuffer(that, size) + return createBuffer(size) } if (fill !== undefined) { // Only pay attention to encoding if it's a string. This // prevents accidentally sending in a number that would // be interpretted as a start offset. return typeof encoding === 'string' - ? createBuffer(that, size).fill(fill, encoding) - : createBuffer(that, size).fill(fill) + ? createBuffer(size).fill(fill, encoding) + : createBuffer(size).fill(fill) } - return createBuffer(that, size) + return createBuffer(size) } /** @@ -317,132 +372,114 @@ function alloc (that, size, fill, encoding) { * alloc(size[, fill[, encoding]]) **/ Buffer.alloc = function (size, fill, encoding) { - return alloc(null, size, fill, encoding) + return alloc(size, fill, encoding) } -function allocUnsafe (that, size) { +function allocUnsafe (size) { assertSize(size) - that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < size; ++i) { - that[i] = 0 - } - } - return that + return createBuffer(size < 0 ? 0 : checked(size) | 0) } /** * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. * */ Buffer.allocUnsafe = function (size) { - return allocUnsafe(null, size) + return allocUnsafe(size) } /** * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. */ Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(null, size) + return allocUnsafe(size) } -function fromString (that, string, encoding) { +function fromString (string, encoding) { if (typeof encoding !== 'string' || encoding === '') { encoding = 'utf8' } if (!Buffer.isEncoding(encoding)) { - throw new TypeError('"encoding" must be a valid string encoding') + throw new TypeError('Unknown encoding: ' + encoding) } var length = byteLength(string, encoding) | 0 - that = createBuffer(that, length) + var buf = createBuffer(length) - var actual = that.write(string, encoding) + var actual = buf.write(string, encoding) if (actual !== length) { // Writing a hex string, for example, that contains invalid characters will // cause everything after the first invalid character to be ignored. (e.g. // 'abxxcd' will be treated as 'ab') - that = that.slice(0, actual) + buf = buf.slice(0, actual) } - return that + return buf } -function fromArrayLike (that, array) { +function fromArrayLike (array) { var length = array.length < 0 ? 0 : checked(array.length) | 0 - that = createBuffer(that, length) + var buf = createBuffer(length) for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 + buf[i] = array[i] & 255 } - return that + return buf } -function fromArrayBuffer (that, array, byteOffset, length) { - array.byteLength // this throws if `array` is not a valid ArrayBuffer - +function fromArrayBuffer (array, byteOffset, length) { if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('\'offset\' is out of bounds') + throw new RangeError('"offset" is outside of buffer bounds') } if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('\'length\' is out of bounds') + throw new RangeError('"length" is outside of buffer bounds') } + var buf if (byteOffset === undefined && length === undefined) { - array = new Uint8Array(array) + buf = new Uint8Array(array) } else if (length === undefined) { - array = new Uint8Array(array, byteOffset) + buf = new Uint8Array(array, byteOffset) } else { - array = new Uint8Array(array, byteOffset, length) + buf = new Uint8Array(array, byteOffset, length) } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = array - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - that = fromArrayLike(that, array) - } - return that + // Return an augmented `Uint8Array` instance + buf.__proto__ = Buffer.prototype + return buf } -function fromObject (that, obj) { +function fromObject (obj) { if (Buffer.isBuffer(obj)) { var len = checked(obj.length) | 0 - that = createBuffer(that, len) + var buf = createBuffer(len) - if (that.length === 0) { - return that + if (buf.length === 0) { + return buf } - obj.copy(that, 0, 0, len) - return that + obj.copy(buf, 0, 0, len) + return buf } - if (obj) { - if ((typeof ArrayBuffer !== 'undefined' && - obj.buffer instanceof ArrayBuffer) || 'length' in obj) { - if (typeof obj.length !== 'number' || isnan(obj.length)) { - return createBuffer(that, 0) - } - return fromArrayLike(that, obj) - } - - if (obj.type === 'Buffer' && isArray(obj.data)) { - return fromArrayLike(that, obj.data) + if (obj.length !== undefined) { + if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { + return createBuffer(0) } + return fromArrayLike(obj) } - throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') + if (obj.type === 'Buffer' && Array.isArray(obj.data)) { + return fromArrayLike(obj.data) + } } function checked (length) { - // Note: cannot use `length < kMaxLength()` here because that fails when + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength()) { + if (length >= K_MAX_LENGTH) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength().toString(16) + ' bytes') + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') } return length | 0 } @@ -455,12 +492,17 @@ function SlowBuffer (length) { } Buffer.isBuffer = function isBuffer (b) { - return !!(b != null && b._isBuffer) + return b != null && b._isBuffer === true && + b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false } Buffer.compare = function compare (a, b) { + if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength) + if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength) if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError('Arguments must be Buffers') + throw new TypeError( + 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' + ) } if (a === b) return 0 @@ -501,7 +543,7 @@ Buffer.isEncoding = function isEncoding (encoding) { } Buffer.concat = function concat (list, length) { - if (!isArray(list)) { + if (!Array.isArray(list)) { throw new TypeError('"list" argument must be an Array of Buffers') } @@ -521,6 +563,9 @@ Buffer.concat = function concat (list, length) { var pos = 0 for (i = 0; i < list.length; ++i) { var buf = list[i] + if (isInstance(buf, Uint8Array)) { + buf = Buffer.from(buf) + } if (!Buffer.isBuffer(buf)) { throw new TypeError('"list" argument must be an Array of Buffers') } @@ -534,16 +579,19 @@ function byteLength (string, encoding) { if (Buffer.isBuffer(string)) { return string.length } - if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && - (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { + if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { return string.byteLength } if (typeof string !== 'string') { - string = '' + string + throw new TypeError( + 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + + 'Received type ' + typeof string + ) } var len = string.length - if (len === 0) return 0 + var mustMatch = (arguments.length > 2 && arguments[2] === true) + if (!mustMatch && len === 0) return 0 // Use a for loop to avoid recursion var loweredCase = false @@ -555,7 +603,6 @@ function byteLength (string, encoding) { return len case 'utf8': case 'utf-8': - case undefined: return utf8ToBytes(string).length case 'ucs2': case 'ucs-2': @@ -567,7 +614,9 @@ function byteLength (string, encoding) { case 'base64': return base64ToBytes(string).length default: - if (loweredCase) return utf8ToBytes(string).length // assume utf8 + if (loweredCase) { + return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8 + } encoding = ('' + encoding).toLowerCase() loweredCase = true } @@ -645,8 +694,12 @@ function slowToString (encoding, start, end) { } } -// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect -// Buffer instances. +// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) +// to detect a Buffer instance. It's not possible to use `instanceof Buffer` +// reliably in a browserify context because there could be multiple different +// copies of the 'buffer' package in use. This method works even for Buffer +// instances that were created from another copy of the `buffer` package. +// See: https://github.com/feross/buffer/issues/154 Buffer.prototype._isBuffer = true function swap (b, n, m) { @@ -693,12 +746,14 @@ Buffer.prototype.swap64 = function swap64 () { } Buffer.prototype.toString = function toString () { - var length = this.length | 0 + var length = this.length if (length === 0) return '' if (arguments.length === 0) return utf8Slice(this, 0, length) return slowToString.apply(this, arguments) } +Buffer.prototype.toLocaleString = Buffer.prototype.toString + Buffer.prototype.equals = function equals (b) { if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') if (this === b) return true @@ -708,16 +763,20 @@ Buffer.prototype.equals = function equals (b) { Buffer.prototype.inspect = function inspect () { var str = '' var max = exports.INSPECT_MAX_BYTES - if (this.length > 0) { - str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') - if (this.length > max) str += ' ... ' - } + str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim() + if (this.length > max) str += ' ... ' return '' } Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { + if (isInstance(target, Uint8Array)) { + target = Buffer.from(target, target.offset, target.byteLength) + } if (!Buffer.isBuffer(target)) { - throw new TypeError('Argument must be a Buffer') + throw new TypeError( + 'The "target" argument must be one of type Buffer or Uint8Array. ' + + 'Received type ' + (typeof target) + ) } if (start === undefined) { @@ -796,8 +855,8 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { } else if (byteOffset < -0x80000000) { byteOffset = -0x80000000 } - byteOffset = +byteOffset // Coerce to Number. - if (isNaN(byteOffset)) { + byteOffset = +byteOffset // Coerce to Number. + if (numberIsNaN(byteOffset)) { // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer byteOffset = dir ? 0 : (buffer.length - 1) } @@ -826,8 +885,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { return arrayIndexOf(buffer, val, byteOffset, encoding, dir) } else if (typeof val === 'number') { val = val & 0xFF // Search for a byte value [0-255] - if (Buffer.TYPED_ARRAY_SUPPORT && - typeof Uint8Array.prototype.indexOf === 'function') { + if (typeof Uint8Array.prototype.indexOf === 'function') { if (dir) { return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) } else { @@ -920,16 +978,14 @@ function hexWrite (buf, string, offset, length) { } } - // must be an even number of digits var strLen = string.length - if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') if (length > strLen / 2) { length = strLen / 2 } for (var i = 0; i < length; ++i) { var parsed = parseInt(string.substr(i * 2, 2), 16) - if (isNaN(parsed)) return i + if (numberIsNaN(parsed)) return i buf[offset + i] = parsed } return i @@ -968,15 +1024,14 @@ Buffer.prototype.write = function write (string, offset, length, encoding) { offset = 0 // Buffer#write(string, offset[, length][, encoding]) } else if (isFinite(offset)) { - offset = offset | 0 + offset = offset >>> 0 if (isFinite(length)) { - length = length | 0 + length = length >>> 0 if (encoding === undefined) encoding = 'utf8' } else { encoding = length length = undefined } - // legacy write(string, encoding, offset, length) - remove in v0.13 } else { throw new Error( 'Buffer.write(string, encoding, offset[, length]) is no longer supported' @@ -1052,8 +1107,8 @@ function utf8Slice (buf, start, end) { var codePoint = null var bytesPerSequence = (firstByte > 0xEF) ? 4 : (firstByte > 0xDF) ? 3 - : (firstByte > 0xBF) ? 2 - : 1 + : (firstByte > 0xBF) ? 2 + : 1 if (i + bytesPerSequence <= end) { var secondByte, thirdByte, fourthByte, tempCodePoint @@ -1175,7 +1230,7 @@ function utf16leSlice (buf, start, end) { var bytes = buf.slice(start, end) var res = '' for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) + res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) } return res } @@ -1201,18 +1256,9 @@ Buffer.prototype.slice = function slice (start, end) { if (end < start) end = start - var newBuf - if (Buffer.TYPED_ARRAY_SUPPORT) { - newBuf = this.subarray(start, end) - newBuf.__proto__ = Buffer.prototype - } else { - var sliceLen = end - start - newBuf = new Buffer(sliceLen, undefined) - for (var i = 0; i < sliceLen; ++i) { - newBuf[i] = this[i + start] - } - } - + var newBuf = this.subarray(start, end) + // Return an augmented `Uint8Array` instance + newBuf.__proto__ = Buffer.prototype return newBuf } @@ -1225,8 +1271,8 @@ function checkOffset (offset, ext, length) { } Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var val = this[offset] @@ -1240,8 +1286,8 @@ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) } Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) { checkOffset(offset, byteLength, this.length) } @@ -1256,21 +1302,25 @@ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) } Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 1, this.length) return this[offset] } Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) return this[offset] | (this[offset + 1] << 8) } Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) return (this[offset] << 8) | this[offset + 1] } Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ((this[offset]) | @@ -1280,6 +1330,7 @@ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { } Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset] * 0x1000000) + @@ -1289,8 +1340,8 @@ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { } Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var val = this[offset] @@ -1307,8 +1358,8 @@ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { } Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var i = byteLength @@ -1325,24 +1376,28 @@ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { } Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 1, this.length) if (!(this[offset] & 0x80)) return (this[offset]) return ((0xff - this[offset] + 1) * -1) } Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) var val = this[offset] | (this[offset + 1] << 8) return (val & 0x8000) ? val | 0xFFFF0000 : val } Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) var val = this[offset + 1] | (this[offset] << 8) return (val & 0x8000) ? val | 0xFFFF0000 : val } Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset]) | @@ -1352,6 +1407,7 @@ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { } Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset] << 24) | @@ -1361,21 +1417,25 @@ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { } Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ieee754.read(this, offset, true, 23, 4) } Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ieee754.read(this, offset, false, 23, 4) } Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 8, this.length) return ieee754.read(this, offset, true, 52, 8) } Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 8, this.length) return ieee754.read(this, offset, false, 52, 8) } @@ -1388,8 +1448,8 @@ function checkInt (buf, value, offset, ext, max, min) { Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength) - 1 checkInt(this, value, offset, byteLength, maxBytes, 0) @@ -1407,8 +1467,8 @@ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength) - 1 checkInt(this, value, offset, byteLength, maxBytes, 0) @@ -1426,89 +1486,57 @@ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) this[offset] = (value & 0xff) return offset + 1 } -function objectWriteUInt16 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { - buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8 - } -} - Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) return offset + 2 } Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) return offset + 2 } -function objectWriteUInt32 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffffffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { - buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff - } -} - Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset + 3] = (value >>> 24) - this[offset + 2] = (value >>> 16) - this[offset + 1] = (value >>> 8) - this[offset] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, true) - } + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) return offset + 4 } Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) return offset + 4 } Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + var limit = Math.pow(2, (8 * byteLength) - 1) checkInt(this, value, offset, byteLength, limit - 1, -limit) } @@ -1529,9 +1557,9 @@ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, no Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + var limit = Math.pow(2, (8 * byteLength) - 1) checkInt(this, value, offset, byteLength, limit - 1, -limit) } @@ -1552,9 +1580,8 @@ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, no Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) if (value < 0) value = 0xff + value + 1 this[offset] = (value & 0xff) return offset + 1 @@ -1562,58 +1589,42 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) return offset + 2 } Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) return offset + 2 } Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - this[offset + 2] = (value >>> 16) - this[offset + 3] = (value >>> 24) - } else { - objectWriteUInt32(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) return offset + 4 } Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) if (value < 0) value = 0xffffffff + value + 1 - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) return offset + 4 } @@ -1623,6 +1634,8 @@ function checkIEEE754 (buf, value, offset, ext, max, min) { } function writeFloat (buf, value, offset, littleEndian, noAssert) { + value = +value + offset = offset >>> 0 if (!noAssert) { checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) } @@ -1639,6 +1652,8 @@ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) } function writeDouble (buf, value, offset, littleEndian, noAssert) { + value = +value + offset = offset >>> 0 if (!noAssert) { checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) } @@ -1656,6 +1671,7 @@ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer') if (!start) start = 0 if (!end && end !== 0) end = this.length if (targetStart >= target.length) targetStart = target.length @@ -1670,7 +1686,7 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { if (targetStart < 0) { throw new RangeError('targetStart out of bounds') } - if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') + if (start < 0 || start >= this.length) throw new RangeError('Index out of range') if (end < 0) throw new RangeError('sourceEnd out of bounds') // Are we oob? @@ -1680,22 +1696,19 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { } var len = end - start - var i - if (this === target && start < targetStart && targetStart < end) { + if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { + // Use built-in when available, missing from IE11 + this.copyWithin(targetStart, start, end) + } else if (this === target && start < targetStart && targetStart < end) { // descending copy from end - for (i = len - 1; i >= 0; --i) { - target[i + targetStart] = this[i + start] - } - } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - // ascending copy from start - for (i = 0; i < len; ++i) { + for (var i = len - 1; i >= 0; --i) { target[i + targetStart] = this[i + start] } } else { Uint8Array.prototype.set.call( target, - this.subarray(start, start + len), + this.subarray(start, end), targetStart ) } @@ -1718,18 +1731,20 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { encoding = end end = this.length } - if (val.length === 1) { - var code = val.charCodeAt(0) - if (code < 256) { - val = code - } - } if (encoding !== undefined && typeof encoding !== 'string') { throw new TypeError('encoding must be a string') } if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { throw new TypeError('Unknown encoding: ' + encoding) } + if (val.length === 1) { + var code = val.charCodeAt(0) + if ((encoding === 'utf8' && code < 128) || + encoding === 'latin1') { + // Fast path: If `val` fits into a single byte, use that numeric value. + val = code + } + } } else if (typeof val === 'number') { val = val & 255 } @@ -1756,8 +1771,12 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { } else { var bytes = Buffer.isBuffer(val) ? val - : utf8ToBytes(new Buffer(val, encoding).toString()) + : Buffer.from(val, encoding) var len = bytes.length + if (len === 0) { + throw new TypeError('The value "' + val + + '" is invalid for argument "value"') + } for (i = 0; i < end - start; ++i) { this[i + start] = bytes[i % len] } @@ -1769,11 +1788,13 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { // HELPER FUNCTIONS // ================ -var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g +var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g function base64clean (str) { + // Node takes equal signs as end of the Base64 encoding + str = str.split('=')[0] // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = stringtrim(str).replace(INVALID_BASE64_RE, '') + str = str.trim().replace(INVALID_BASE64_RE, '') // Node converts strings with length < 2 to '' if (str.length < 2) return '' // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not @@ -1783,11 +1804,6 @@ function base64clean (str) { return str } -function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') -} - function toHex (n) { if (n < 16) return '0' + n.toString(16) return n.toString(16) @@ -1910,16 +1926,25 @@ function blitBuffer (src, dst, offset, length) { return i } -function isnan (val) { - return val !== val // eslint-disable-line no-self-compare +// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass +// the `instanceof` check but they should be treated as of that type. +// See: https://github.com/feross/buffer/issues/166 +function isInstance (obj, type) { + return obj instanceof type || + (obj != null && obj.constructor != null && obj.constructor.name != null && + obj.constructor.name === type.name) +} +function numberIsNaN (obj) { + // For IE11 support + return obj !== obj // eslint-disable-line no-self-compare } -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +}).call(this,require("buffer").Buffer) -},{"base64-js":1,"ieee754":4,"isarray":5}],4:[function(require,module,exports){ +},{"base64-js":1,"buffer":3,"ieee754":4}],4:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var nBits = -7 @@ -1932,12 +1957,12 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { e = s & ((1 << (-nBits)) - 1) s >>= (-nBits) nBits += eLen - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} m = e & ((1 << (-nBits)) - 1) e >>= (-nBits) nBits += mLen - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} if (e === 0) { e = 1 - eBias @@ -1952,7 +1977,7 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { var e, m, c - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) @@ -1985,7 +2010,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { m = 0 e = eMax } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen) + m = ((value * c) - 1) * Math.pow(2, mLen) e = e + eBias } else { m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) @@ -2003,13 +2028,6 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { } },{}],5:[function(require,module,exports){ -var toString = {}.toString; - -module.exports = Array.isArray || function (arr) { - return toString.call(arr) == '[object Array]'; -}; - -},{}],6:[function(require,module,exports){ (function (Buffer,__dirname){ /* globals chrome: false */ /* globals __dirname: false */ @@ -2942,9 +2960,9 @@ Typo.prototype = { if (typeof module !== 'undefined') { module.exports = Typo; } -}).call(this,require("buffer").Buffer,"/node_modules\\typo-js") +}).call(this,require("buffer").Buffer,"/node_modules/typo-js") -},{"buffer":3,"fs":2}],7:[function(require,module,exports){ +},{"buffer":3,"fs":2}],6:[function(require,module,exports){ // Use strict mode (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) "use strict"; @@ -3018,17 +3036,17 @@ function CodeMirrorSpellChecker(options) { // Define what separates a word - var rx_word = /^[^!\"#$%&()*+,\-./:;<=>?@\[\\\]^_`{|}~\s]+/; + var rx_word = /^[^!"#$%&()*+,\-./:;<=>?@[\\\]^_`{|}~\s]+/; // Ignore words that are just numbers var rx_ignore = /^[0-9]+$/; // Get array of custom words - var customWords; + var customWords = []; if(options.customWords && options.customWords instanceof Array) { - customWords = options.customWords || []; + customWords = options.customWords; } // Create the overlay and such @@ -3067,6 +3085,7 @@ C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iAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFuZCBUeXBvLmpzIGlzIGJlaW5nIHVzZWQgaW4gYSBDaHJvbWUgZXh0ZW5zaW9uLCB0aGUgLmRpY1xuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaWxlIHdpbGwgYmUgbG9hZGVkIGF1dG9tYXRpY2FsbHkgZnJvbVxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsaWIvdHlwby9kaWN0aW9uYXJpZXMvW2RpY3Rpb25hcnldL1tkaWN0aW9uYXJ5XS5kaWNcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSW4gb3RoZXIgZW52aXJvbm1lbnRzLCBpdCB3aWxsIGJlIGxvYWRlZCBmcm9tXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFtzZXR0aW5ncy5kaWN0aW9uYXJ5UGF0aF0vZGljdGlvbmFyaWVzL1tkaWN0aW9uYXJ5XS9bZGljdGlvbmFyeV0uZGljXG4gKiBAcGFyYW0ge09iamVjdH0gW3NldHRpbmdzXSAgIENvbnN0cnVjdG9yIHNldHRpbmdzLiBBdmFpbGFibGUgcHJvcGVydGllcyBhcmU6XG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHtTdHJpbmd9IFtkaWN0aW9uYXJ5UGF0aF06IHBhdGggdG8gbG9hZCBkaWN0aW9uYXJ5IGZyb20gaW4gbm9uLWNocm9tZVxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbnZpcm9ubWVudC5cbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAge09iamVjdH0gW2ZsYWdzXTogZmxhZyBpbmZvcm1hdGlvbi5cbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAge0Jvb2xlYW59IFthc3luY0xvYWRdOiBJZiB0cnVlLCBhZmZEYXRhIGFuZCB3b3Jkc0RhdGEgd2lsbCBiZSBsb2FkZWRcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgIC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T0gMHg4MCkge1xuICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAweDFGKSA8PCAweDYgfCAoc2Vjb25kQnl0ZSAmIDB4M0YpXG4gICAgICAgICAgICBpZiAodGVtcENvZGVQb2ludCA+IDB4N0YpIHtcbiAgICAgICAgICAgICAgY29kZVBvaW50ID0gdGVtcENvZGVQb2ludFxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBicmVha1xuICAgICAgICBjYXNlIDM6XG4gICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV1cbiAgICAgICAgICB0aGlyZEJ5dGUgPSBidWZbaSArIDJdXG4gICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMHhDMCkgPT09IDB4ODAgJiYgKHRoaXJkQnl0ZSAmIDB4QzApID09PSAweDgwKSB7XG4gICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDB4RikgPDwgMHhDIHwgKHNlY29uZEJ5dGUgJiAweDNGKSA8PCAweDYgfCAodGhpcmRCeXRlICYgMHgzRilcbiAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMHg3RkYgJiYgKHRlbXBDb2RlUG9pbnQgPCAweEQ4MDAgfHwgdGVtcENvZGVQb2ludCA+IDB4REZGRikpIHtcbiAgICAgICAgICAgICAgY29kZVBvaW50ID0gdGVtcENvZGVQb2ludFxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBicmVha1xuICAgICAgICBjYXNlIDQ6XG4gICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV1cbiAgICAgICAgICB0aGlyZEJ5dGUgPSBidWZbaSArIDJdXG4gICAgICAgICAgZm91cnRoQnl0ZSA9IGJ1ZltpICsgM11cbiAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAweEMwKSA9PT0gMHg4MCAmJiAodGhpcmRCeXRlICYgMHhD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cyBiZWluZyB1c2VkIGluIGEgQ2hyb21lIGV4dGVuc2lvbiwgdGhlIC5hZmZcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmlsZSB3aWxsIGJlIGxvYWRlZCBhdXRvbWF0aWNhbGx5IGZyb21cbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGliL3R5cG8vZGljdGlvbmFyaWVzL1tkaWN0aW9uYXJ5XS9bZGljdGlvbmFyeV0uYWZmXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEluIG90aGVyIGVudmlyb25tZW50cywgaXQgd2lsbCBiZSBsb2FkZWQgZnJvbVxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBbc2V0dGluZ3MuZGljdGlvbmFyeVBhdGhdL2RpY3Rpb25hcmllcy9bZGljdGlvbmFyeV0vW2RpY3Rpb25hcnldLmFmZlxuICogQHBhcmFtIHtTdHJpbmd9IFt3b3Jkc0RhdGFdICBUaGUgZGF0YSBmcm9tIHRoZSBkaWN0aW9uYXJ5J3MgLmRpYyBmaWxlLiBJZiBvbWl0dGVkXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFuZCBUeXBvLmpzIGlzIGJlaW5nIHVzZWQgaW4gYSBDaHJvbWUgZXh0ZW5zaW9uLCB0aGUgLmRpY1xuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaWxlIHdpbGwgYmUgbG9hZGVkIGF1dG9tYXRpY2FsbHkgZnJvbVxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsaWIvdHlwby9kaWN0aW9uYXJpZXMvW2RpY3Rpb25hcnldL1tkaWN0aW9uYXJ5XS5kaWNcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSW4gb3RoZXIgZW52aXJvbm1lbnRzLCBpdCB3aWxsIGJlIGxvYWRlZCBmcm9tXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFtzZXR0aW5ncy5kaWN0aW9uYXJ5UGF0aF0vZGljdGlvbmFyaWVzL1tkaWN0aW9uYXJ5XS9bZGljdGlvbmFyeV0uZGljXG4gKiBAcGFyYW0ge09iamVjdH0gW3NldHRpbmdzXSAgIENvbnN0cnVjdG9yIHNldHRpbmdzLiBBdmFpbGFibGUgcHJvcGVydGllcyBhcmU6XG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHtTdHJpbmd9IFtkaWN0aW9uYXJ5UGF0aF06IHBhdGggdG8gbG9hZCBkaWN0aW9uYXJ5IGZyb20gaW4gbm9uLWNocm9tZVxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbnZpcm9ubWVudC5cbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAge09iamVjdH0gW2ZsYWdzXTogZmxhZyBpbmZvcm1hdGlvbi5cbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAge0Jvb2xlYW59IFthc3luY0xvYWRdOiBJZiB0cnVlLCBhZmZEYXRhIGFuZCB3b3Jkc0RhdGEgd2lsbCBiZSBsb2FkZWRcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYXN5bmNocm9ub3VzbHkuXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHtGdW5jdGlvbn0gW2xvYWRlZENhbGxiYWNrXTogQ2FsbGVkIHdoZW4gYm90aCBhZmZEYXRhIGFuZCB3b3Jkc0RhdGFcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaGF2ZSBiZWVuIGxvYWRlZC4gT25seSB1c2VkIGlmIGFzeW5jTG9hZCBpcyBzZXQgdG8gdHJ1ZS4gVGhlIHBhcmFtZXRlclxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpcyB0aGUgaW5zdGFudGlhdGVkIFR5cG8gb2JqZWN0LlxuICpcbiAqIEByZXR1cm5zIHtUeXBvfSBBIFR5cG8gb2JqZWN0LlxuICovXG5cblR5cG8gPSBmdW5jdGlvbiAoZGljdGlvbmFyeSwgYWZmRG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Wlycm9ySW5zdGFuY2Uub3ZlcmxheU1vZGUobW9kZSwgb3ZlcmxheSwgdHJ1ZSk7XG5cdH0pO1xufVxuXG5cbi8vIEluaXRpYWxpemUgZGF0YSBnbG9iYWxseSB0byByZWR1Y2UgbWVtb3J5IGNvbnN1bXB0aW9uXG5Db2RlTWlycm9yU3BlbGxDaGVja2VyLm51bV9sb2FkZWQgPSAwO1xuQ29kZU1pcnJvclNwZWxsQ2hlY2tlci5hZmZfbG9hZGluZyA9IGZhbHNlO1xuQ29kZU1pcnJvclNwZWxsQ2hlY2tlci5kaWNfbG9hZGluZyA9IGZhbHNlO1xuQ29kZU1pcnJvclNwZWxsQ2hlY2tlci5hZmZfZGF0YSA9IFwiXCI7XG5Db2RlTWlycm9yU3BlbGxDaGVja2VyLmRpY19kYXRhID0gXCJcIjtcbkNvZGVNaXJyb3JTcGVsbENoZWNrZXIudHlwbztcblxuXG4vLyBFeHBvcnRcbm1vZHVsZS5leHBvcnRzID0gQ29kZU1pcnJvclNwZWxsQ2hlY2tlcjsiXX0= diff --git a/debug/spell-checker.js b/debug/spell-checker.js index bf8b47a..5921d10 100644 --- a/debug/spell-checker.js +++ b/debug/spell-checker.js @@ -4,7 +4,7 @@ * @link https://github.com/NextStepWebs/codemirror-spell-checker * @license MIT */ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.CodeMirrorSpellChecker = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { throw new Error('Invalid string. Length must be a multiple of 4') } - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 + // Trim off extra bytes after placeholder bytes are found + // See: https://github.com/beatgammit/base64-js/issues/42 + var validLen = b64.indexOf('=') + if (validLen === -1) validLen = len + + var placeHoldersLen = validLen === len + ? 0 + : 4 - (validLen % 4) + + return [validLen, placeHoldersLen] } +// base64 is 4/3 + up to two characters of the original data function byteLength (b64) { - // base64 is 4/3 + up to two characters of the original data - return b64.length * 3 / 4 - placeHoldersCount(b64) + var lens = getLens(b64) + var validLen = lens[0] + var placeHoldersLen = lens[1] + return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen +} + +function _byteLength (b64, validLen, placeHoldersLen) { + return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen } function toByteArray (b64) { - var i, j, l, tmp, placeHolders, arr - var len = b64.length - placeHolders = placeHoldersCount(b64) + var tmp + var lens = getLens(b64) + var validLen = lens[0] + var placeHoldersLen = lens[1] + + var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) - arr = new Arr(len * 3 / 4 - placeHolders) + var curByte = 0 // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? len - 4 : len + var len = placeHoldersLen > 0 + ? validLen - 4 + : validLen - var L = 0 + for (var i = 0; i < len; i += 4) { + tmp = + (revLookup[b64.charCodeAt(i)] << 18) | + (revLookup[b64.charCodeAt(i + 1)] << 12) | + (revLookup[b64.charCodeAt(i + 2)] << 6) | + revLookup[b64.charCodeAt(i + 3)] + arr[curByte++] = (tmp >> 16) & 0xFF + arr[curByte++] = (tmp >> 8) & 0xFF + arr[curByte++] = tmp & 0xFF + } - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] - arr[L++] = (tmp >> 16) & 0xFF - arr[L++] = (tmp >> 8) & 0xFF - arr[L++] = tmp & 0xFF + if (placeHoldersLen === 2) { + tmp = + (revLookup[b64.charCodeAt(i)] << 2) | + (revLookup[b64.charCodeAt(i + 1)] >> 4) + arr[curByte++] = tmp & 0xFF } - if (placeHolders === 2) { - tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) - arr[L++] = tmp & 0xFF - } else if (placeHolders === 1) { - tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) - arr[L++] = (tmp >> 8) & 0xFF - arr[L++] = tmp & 0xFF + if (placeHoldersLen === 1) { + tmp = + (revLookup[b64.charCodeAt(i)] << 10) | + (revLookup[b64.charCodeAt(i + 1)] << 4) | + (revLookup[b64.charCodeAt(i + 2)] >> 2) + arr[curByte++] = (tmp >> 8) & 0xFF + arr[curByte++] = tmp & 0xFF } return arr } function tripletToBase64 (num) { - return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] + return lookup[num >> 18 & 0x3F] + + lookup[num >> 12 & 0x3F] + + lookup[num >> 6 & 0x3F] + + lookup[num & 0x3F] } function encodeChunk (uint8, start, end) { var tmp var output = [] for (var i = start; i < end; i += 3) { - tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + tmp = + ((uint8[i] << 16) & 0xFF0000) + + ((uint8[i + 1] << 8) & 0xFF00) + + (uint8[i + 2] & 0xFF) output.push(tripletToBase64(tmp)) } return output.join('') @@ -92,42 +126,45 @@ function fromByteArray (uint8) { var tmp var len = uint8.length var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes - var output = '' var parts = [] var maxChunkLength = 16383 // must be multiple of 3 // go through the array every three bytes, we'll deal with trailing stuff later for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) + parts.push(encodeChunk( + uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength) + )) } // pad the end with zeros, but make sure to not forget the extra bytes if (extraBytes === 1) { tmp = uint8[len - 1] - output += lookup[tmp >> 2] - output += lookup[(tmp << 4) & 0x3F] - output += '==' + parts.push( + lookup[tmp >> 2] + + lookup[(tmp << 4) & 0x3F] + + '==' + ) } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) - output += lookup[tmp >> 10] - output += lookup[(tmp >> 4) & 0x3F] - output += lookup[(tmp << 2) & 0x3F] - output += '=' + tmp = (uint8[len - 2] << 8) + uint8[len - 1] + parts.push( + lookup[tmp >> 10] + + lookup[(tmp >> 4) & 0x3F] + + lookup[(tmp << 2) & 0x3F] + + '=' + ) } - parts.push(output) - return parts.join('') } },{}],2:[function(require,module,exports){ },{}],3:[function(require,module,exports){ -(function (global){ +(function (Buffer){ /*! * The buffer module from node.js, for the browser. * - * @author Feross Aboukhadijeh + * @author Feross Aboukhadijeh * @license MIT */ /* eslint-disable no-proto */ @@ -136,80 +173,73 @@ function fromByteArray (uint8) { var base64 = require('base64-js') var ieee754 = require('ieee754') -var isArray = require('isarray') exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer exports.INSPECT_MAX_BYTES = 50 +var K_MAX_LENGTH = 0x7fffffff +exports.kMaxLength = K_MAX_LENGTH + /** * If `Buffer.TYPED_ARRAY_SUPPORT`: * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) + * === false Print warning and recommend using `buffer` v4.x which has an Object + * implementation (most compatible, even IE6) * * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * - * Due to various browser bugs, sometimes the Object implementation will be used even - * when the browser supports typed arrays. - * - * Note: - * - * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. - - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they - * get the Object implementation, which is slower but behaves correctly. + * We report that the browser does not support typed arrays if the are not subclassable + * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` + * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support + * for __proto__ and has a buggy typed array implementation. */ -Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined - ? global.TYPED_ARRAY_SUPPORT - : typedArraySupport() +Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() -/* - * Export kMaxLength after typed array support is determined. - */ -exports.kMaxLength = kMaxLength() +if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && + typeof console.error === 'function') { + console.error( + 'This browser lacks typed array (Uint8Array) support which is required by ' + + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' + ) +} function typedArraySupport () { + // Can typed array instances can be augmented? try { var arr = new Uint8Array(1) - arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} - return arr.foo() === 42 && // typed array instances can be augmented - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } } + return arr.foo() === 42 } catch (e) { return false } } -function kMaxLength () { - return Buffer.TYPED_ARRAY_SUPPORT - ? 0x7fffffff - : 0x3fffffff -} - -function createBuffer (that, length) { - if (kMaxLength() < length) { - throw new RangeError('Invalid typed array length') +Object.defineProperty(Buffer.prototype, 'parent', { + enumerable: true, + get: function () { + if (!Buffer.isBuffer(this)) return undefined + return this.buffer } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = new Uint8Array(length) - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - if (that === null) { - that = new Buffer(length) - } - that.length = length +}) + +Object.defineProperty(Buffer.prototype, 'offset', { + enumerable: true, + get: function () { + if (!Buffer.isBuffer(this)) return undefined + return this.byteOffset } +}) - return that +function createBuffer (length) { + if (length > K_MAX_LENGTH) { + throw new RangeError('The value "' + length + '" is invalid for option "size"') + } + // Return an augmented `Uint8Array` instance + var buf = new Uint8Array(length) + buf.__proto__ = Buffer.prototype + return buf } /** @@ -223,44 +253,77 @@ function createBuffer (that, length) { */ function Buffer (arg, encodingOrOffset, length) { - if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { - return new Buffer(arg, encodingOrOffset, length) - } - // Common case. if (typeof arg === 'number') { if (typeof encodingOrOffset === 'string') { - throw new Error( - 'If encoding is specified then the first argument must be a string' + throw new TypeError( + 'The "string" argument must be of type string. Received type number' ) } - return allocUnsafe(this, arg) + return allocUnsafe(arg) } - return from(this, arg, encodingOrOffset, length) + return from(arg, encodingOrOffset, length) +} + +// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 +if (typeof Symbol !== 'undefined' && Symbol.species != null && + Buffer[Symbol.species] === Buffer) { + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true, + enumerable: false, + writable: false + }) } Buffer.poolSize = 8192 // not used by this implementation -// TODO: Legacy, not needed anymore. Remove in next major version. -Buffer._augment = function (arr) { - arr.__proto__ = Buffer.prototype - return arr -} +function from (value, encodingOrOffset, length) { + if (typeof value === 'string') { + return fromString(value, encodingOrOffset) + } + + if (ArrayBuffer.isView(value)) { + return fromArrayLike(value) + } + + if (value == null) { + throw TypeError( + 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + + 'or Array-like Object. Received type ' + (typeof value) + ) + } + + if (isInstance(value, ArrayBuffer) || + (value && isInstance(value.buffer, ArrayBuffer))) { + return fromArrayBuffer(value, encodingOrOffset, length) + } -function from (that, value, encodingOrOffset, length) { if (typeof value === 'number') { - throw new TypeError('"value" argument must not be a number') + throw new TypeError( + 'The "value" argument must not be of type number. Received type number' + ) } - if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { - return fromArrayBuffer(that, value, encodingOrOffset, length) + var valueOf = value.valueOf && value.valueOf() + if (valueOf != null && valueOf !== value) { + return Buffer.from(valueOf, encodingOrOffset, length) } - if (typeof value === 'string') { - return fromString(that, value, encodingOrOffset) + var b = fromObject(value) + if (b) return b + + if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && + typeof value[Symbol.toPrimitive] === 'function') { + return Buffer.from( + value[Symbol.toPrimitive]('string'), encodingOrOffset, length + ) } - return fromObject(that, value) + throw new TypeError( + 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + + 'or Array-like Object. Received type ' + (typeof value) + ) } /** @@ -272,44 +335,36 @@ function from (that, value, encodingOrOffset, length) { * Buffer.from(arrayBuffer[, byteOffset[, length]]) **/ Buffer.from = function (value, encodingOrOffset, length) { - return from(null, value, encodingOrOffset, length) + return from(value, encodingOrOffset, length) } -if (Buffer.TYPED_ARRAY_SUPPORT) { - Buffer.prototype.__proto__ = Uint8Array.prototype - Buffer.__proto__ = Uint8Array - if (typeof Symbol !== 'undefined' && Symbol.species && - Buffer[Symbol.species] === Buffer) { - // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 - Object.defineProperty(Buffer, Symbol.species, { - value: null, - configurable: true - }) - } -} +// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: +// https://github.com/feross/buffer/pull/148 +Buffer.prototype.__proto__ = Uint8Array.prototype +Buffer.__proto__ = Uint8Array function assertSize (size) { if (typeof size !== 'number') { - throw new TypeError('"size" argument must be a number') + throw new TypeError('"size" argument must be of type number') } else if (size < 0) { - throw new RangeError('"size" argument must not be negative') + throw new RangeError('The value "' + size + '" is invalid for option "size"') } } -function alloc (that, size, fill, encoding) { +function alloc (size, fill, encoding) { assertSize(size) if (size <= 0) { - return createBuffer(that, size) + return createBuffer(size) } if (fill !== undefined) { // Only pay attention to encoding if it's a string. This // prevents accidentally sending in a number that would // be interpretted as a start offset. return typeof encoding === 'string' - ? createBuffer(that, size).fill(fill, encoding) - : createBuffer(that, size).fill(fill) + ? createBuffer(size).fill(fill, encoding) + : createBuffer(size).fill(fill) } - return createBuffer(that, size) + return createBuffer(size) } /** @@ -317,132 +372,114 @@ function alloc (that, size, fill, encoding) { * alloc(size[, fill[, encoding]]) **/ Buffer.alloc = function (size, fill, encoding) { - return alloc(null, size, fill, encoding) + return alloc(size, fill, encoding) } -function allocUnsafe (that, size) { +function allocUnsafe (size) { assertSize(size) - that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < size; ++i) { - that[i] = 0 - } - } - return that + return createBuffer(size < 0 ? 0 : checked(size) | 0) } /** * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. * */ Buffer.allocUnsafe = function (size) { - return allocUnsafe(null, size) + return allocUnsafe(size) } /** * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. */ Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(null, size) + return allocUnsafe(size) } -function fromString (that, string, encoding) { +function fromString (string, encoding) { if (typeof encoding !== 'string' || encoding === '') { encoding = 'utf8' } if (!Buffer.isEncoding(encoding)) { - throw new TypeError('"encoding" must be a valid string encoding') + throw new TypeError('Unknown encoding: ' + encoding) } var length = byteLength(string, encoding) | 0 - that = createBuffer(that, length) + var buf = createBuffer(length) - var actual = that.write(string, encoding) + var actual = buf.write(string, encoding) if (actual !== length) { // Writing a hex string, for example, that contains invalid characters will // cause everything after the first invalid character to be ignored. (e.g. // 'abxxcd' will be treated as 'ab') - that = that.slice(0, actual) + buf = buf.slice(0, actual) } - return that + return buf } -function fromArrayLike (that, array) { +function fromArrayLike (array) { var length = array.length < 0 ? 0 : checked(array.length) | 0 - that = createBuffer(that, length) + var buf = createBuffer(length) for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 + buf[i] = array[i] & 255 } - return that + return buf } -function fromArrayBuffer (that, array, byteOffset, length) { - array.byteLength // this throws if `array` is not a valid ArrayBuffer - +function fromArrayBuffer (array, byteOffset, length) { if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('\'offset\' is out of bounds') + throw new RangeError('"offset" is outside of buffer bounds') } if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('\'length\' is out of bounds') + throw new RangeError('"length" is outside of buffer bounds') } + var buf if (byteOffset === undefined && length === undefined) { - array = new Uint8Array(array) + buf = new Uint8Array(array) } else if (length === undefined) { - array = new Uint8Array(array, byteOffset) + buf = new Uint8Array(array, byteOffset) } else { - array = new Uint8Array(array, byteOffset, length) + buf = new Uint8Array(array, byteOffset, length) } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = array - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - that = fromArrayLike(that, array) - } - return that + // Return an augmented `Uint8Array` instance + buf.__proto__ = Buffer.prototype + return buf } -function fromObject (that, obj) { +function fromObject (obj) { if (Buffer.isBuffer(obj)) { var len = checked(obj.length) | 0 - that = createBuffer(that, len) + var buf = createBuffer(len) - if (that.length === 0) { - return that + if (buf.length === 0) { + return buf } - obj.copy(that, 0, 0, len) - return that + obj.copy(buf, 0, 0, len) + return buf } - if (obj) { - if ((typeof ArrayBuffer !== 'undefined' && - obj.buffer instanceof ArrayBuffer) || 'length' in obj) { - if (typeof obj.length !== 'number' || isnan(obj.length)) { - return createBuffer(that, 0) - } - return fromArrayLike(that, obj) - } - - if (obj.type === 'Buffer' && isArray(obj.data)) { - return fromArrayLike(that, obj.data) + if (obj.length !== undefined) { + if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { + return createBuffer(0) } + return fromArrayLike(obj) } - throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') + if (obj.type === 'Buffer' && Array.isArray(obj.data)) { + return fromArrayLike(obj.data) + } } function checked (length) { - // Note: cannot use `length < kMaxLength()` here because that fails when + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength()) { + if (length >= K_MAX_LENGTH) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength().toString(16) + ' bytes') + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') } return length | 0 } @@ -455,12 +492,17 @@ function SlowBuffer (length) { } Buffer.isBuffer = function isBuffer (b) { - return !!(b != null && b._isBuffer) + return b != null && b._isBuffer === true && + b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false } Buffer.compare = function compare (a, b) { + if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength) + if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength) if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError('Arguments must be Buffers') + throw new TypeError( + 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' + ) } if (a === b) return 0 @@ -501,7 +543,7 @@ Buffer.isEncoding = function isEncoding (encoding) { } Buffer.concat = function concat (list, length) { - if (!isArray(list)) { + if (!Array.isArray(list)) { throw new TypeError('"list" argument must be an Array of Buffers') } @@ -521,6 +563,9 @@ Buffer.concat = function concat (list, length) { var pos = 0 for (i = 0; i < list.length; ++i) { var buf = list[i] + if (isInstance(buf, Uint8Array)) { + buf = Buffer.from(buf) + } if (!Buffer.isBuffer(buf)) { throw new TypeError('"list" argument must be an Array of Buffers') } @@ -534,16 +579,19 @@ function byteLength (string, encoding) { if (Buffer.isBuffer(string)) { return string.length } - if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && - (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { + if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { return string.byteLength } if (typeof string !== 'string') { - string = '' + string + throw new TypeError( + 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + + 'Received type ' + typeof string + ) } var len = string.length - if (len === 0) return 0 + var mustMatch = (arguments.length > 2 && arguments[2] === true) + if (!mustMatch && len === 0) return 0 // Use a for loop to avoid recursion var loweredCase = false @@ -555,7 +603,6 @@ function byteLength (string, encoding) { return len case 'utf8': case 'utf-8': - case undefined: return utf8ToBytes(string).length case 'ucs2': case 'ucs-2': @@ -567,7 +614,9 @@ function byteLength (string, encoding) { case 'base64': return base64ToBytes(string).length default: - if (loweredCase) return utf8ToBytes(string).length // assume utf8 + if (loweredCase) { + return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8 + } encoding = ('' + encoding).toLowerCase() loweredCase = true } @@ -645,8 +694,12 @@ function slowToString (encoding, start, end) { } } -// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect -// Buffer instances. +// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) +// to detect a Buffer instance. It's not possible to use `instanceof Buffer` +// reliably in a browserify context because there could be multiple different +// copies of the 'buffer' package in use. This method works even for Buffer +// instances that were created from another copy of the `buffer` package. +// See: https://github.com/feross/buffer/issues/154 Buffer.prototype._isBuffer = true function swap (b, n, m) { @@ -693,12 +746,14 @@ Buffer.prototype.swap64 = function swap64 () { } Buffer.prototype.toString = function toString () { - var length = this.length | 0 + var length = this.length if (length === 0) return '' if (arguments.length === 0) return utf8Slice(this, 0, length) return slowToString.apply(this, arguments) } +Buffer.prototype.toLocaleString = Buffer.prototype.toString + Buffer.prototype.equals = function equals (b) { if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') if (this === b) return true @@ -708,16 +763,20 @@ Buffer.prototype.equals = function equals (b) { Buffer.prototype.inspect = function inspect () { var str = '' var max = exports.INSPECT_MAX_BYTES - if (this.length > 0) { - str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') - if (this.length > max) str += ' ... ' - } + str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim() + if (this.length > max) str += ' ... ' return '' } Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { + if (isInstance(target, Uint8Array)) { + target = Buffer.from(target, target.offset, target.byteLength) + } if (!Buffer.isBuffer(target)) { - throw new TypeError('Argument must be a Buffer') + throw new TypeError( + 'The "target" argument must be one of type Buffer or Uint8Array. ' + + 'Received type ' + (typeof target) + ) } if (start === undefined) { @@ -796,8 +855,8 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { } else if (byteOffset < -0x80000000) { byteOffset = -0x80000000 } - byteOffset = +byteOffset // Coerce to Number. - if (isNaN(byteOffset)) { + byteOffset = +byteOffset // Coerce to Number. + if (numberIsNaN(byteOffset)) { // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer byteOffset = dir ? 0 : (buffer.length - 1) } @@ -826,8 +885,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { return arrayIndexOf(buffer, val, byteOffset, encoding, dir) } else if (typeof val === 'number') { val = val & 0xFF // Search for a byte value [0-255] - if (Buffer.TYPED_ARRAY_SUPPORT && - typeof Uint8Array.prototype.indexOf === 'function') { + if (typeof Uint8Array.prototype.indexOf === 'function') { if (dir) { return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) } else { @@ -920,16 +978,14 @@ function hexWrite (buf, string, offset, length) { } } - // must be an even number of digits var strLen = string.length - if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') if (length > strLen / 2) { length = strLen / 2 } for (var i = 0; i < length; ++i) { var parsed = parseInt(string.substr(i * 2, 2), 16) - if (isNaN(parsed)) return i + if (numberIsNaN(parsed)) return i buf[offset + i] = parsed } return i @@ -968,15 +1024,14 @@ Buffer.prototype.write = function write (string, offset, length, encoding) { offset = 0 // Buffer#write(string, offset[, length][, encoding]) } else if (isFinite(offset)) { - offset = offset | 0 + offset = offset >>> 0 if (isFinite(length)) { - length = length | 0 + length = length >>> 0 if (encoding === undefined) encoding = 'utf8' } else { encoding = length length = undefined } - // legacy write(string, encoding, offset, length) - remove in v0.13 } else { throw new Error( 'Buffer.write(string, encoding, offset[, length]) is no longer supported' @@ -1052,8 +1107,8 @@ function utf8Slice (buf, start, end) { var codePoint = null var bytesPerSequence = (firstByte > 0xEF) ? 4 : (firstByte > 0xDF) ? 3 - : (firstByte > 0xBF) ? 2 - : 1 + : (firstByte > 0xBF) ? 2 + : 1 if (i + bytesPerSequence <= end) { var secondByte, thirdByte, fourthByte, tempCodePoint @@ -1175,7 +1230,7 @@ function utf16leSlice (buf, start, end) { var bytes = buf.slice(start, end) var res = '' for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) + res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) } return res } @@ -1201,18 +1256,9 @@ Buffer.prototype.slice = function slice (start, end) { if (end < start) end = start - var newBuf - if (Buffer.TYPED_ARRAY_SUPPORT) { - newBuf = this.subarray(start, end) - newBuf.__proto__ = Buffer.prototype - } else { - var sliceLen = end - start - newBuf = new Buffer(sliceLen, undefined) - for (var i = 0; i < sliceLen; ++i) { - newBuf[i] = this[i + start] - } - } - + var newBuf = this.subarray(start, end) + // Return an augmented `Uint8Array` instance + newBuf.__proto__ = Buffer.prototype return newBuf } @@ -1225,8 +1271,8 @@ function checkOffset (offset, ext, length) { } Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var val = this[offset] @@ -1240,8 +1286,8 @@ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) } Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) { checkOffset(offset, byteLength, this.length) } @@ -1256,21 +1302,25 @@ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) } Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 1, this.length) return this[offset] } Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) return this[offset] | (this[offset + 1] << 8) } Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) return (this[offset] << 8) | this[offset + 1] } Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ((this[offset]) | @@ -1280,6 +1330,7 @@ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { } Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset] * 0x1000000) + @@ -1289,8 +1340,8 @@ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { } Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var val = this[offset] @@ -1307,8 +1358,8 @@ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { } Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var i = byteLength @@ -1325,24 +1376,28 @@ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { } Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 1, this.length) if (!(this[offset] & 0x80)) return (this[offset]) return ((0xff - this[offset] + 1) * -1) } Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) var val = this[offset] | (this[offset + 1] << 8) return (val & 0x8000) ? val | 0xFFFF0000 : val } Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) var val = this[offset + 1] | (this[offset] << 8) return (val & 0x8000) ? val | 0xFFFF0000 : val } Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset]) | @@ -1352,6 +1407,7 @@ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { } Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset] << 24) | @@ -1361,21 +1417,25 @@ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { } Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ieee754.read(this, offset, true, 23, 4) } Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ieee754.read(this, offset, false, 23, 4) } Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 8, this.length) return ieee754.read(this, offset, true, 52, 8) } Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 8, this.length) return ieee754.read(this, offset, false, 52, 8) } @@ -1388,8 +1448,8 @@ function checkInt (buf, value, offset, ext, max, min) { Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength) - 1 checkInt(this, value, offset, byteLength, maxBytes, 0) @@ -1407,8 +1467,8 @@ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) { var maxBytes = Math.pow(2, 8 * byteLength) - 1 checkInt(this, value, offset, byteLength, maxBytes, 0) @@ -1426,89 +1486,57 @@ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) this[offset] = (value & 0xff) return offset + 1 } -function objectWriteUInt16 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { - buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8 - } -} - Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) return offset + 2 } Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) return offset + 2 } -function objectWriteUInt32 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffffffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { - buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff - } -} - Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset + 3] = (value >>> 24) - this[offset + 2] = (value >>> 16) - this[offset + 1] = (value >>> 8) - this[offset] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, true) - } + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) return offset + 4 } Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) return offset + 4 } Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + var limit = Math.pow(2, (8 * byteLength) - 1) checkInt(this, value, offset, byteLength, limit - 1, -limit) } @@ -1529,9 +1557,9 @@ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, no Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + var limit = Math.pow(2, (8 * byteLength) - 1) checkInt(this, value, offset, byteLength, limit - 1, -limit) } @@ -1552,9 +1580,8 @@ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, no Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) if (value < 0) value = 0xff + value + 1 this[offset] = (value & 0xff) return offset + 1 @@ -1562,58 +1589,42 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) return offset + 2 } Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) return offset + 2 } Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - this[offset + 2] = (value >>> 16) - this[offset + 3] = (value >>> 24) - } else { - objectWriteUInt32(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) return offset + 4 } Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) if (value < 0) value = 0xffffffff + value + 1 - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) return offset + 4 } @@ -1623,6 +1634,8 @@ function checkIEEE754 (buf, value, offset, ext, max, min) { } function writeFloat (buf, value, offset, littleEndian, noAssert) { + value = +value + offset = offset >>> 0 if (!noAssert) { checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) } @@ -1639,6 +1652,8 @@ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) } function writeDouble (buf, value, offset, littleEndian, noAssert) { + value = +value + offset = offset >>> 0 if (!noAssert) { checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) } @@ -1656,6 +1671,7 @@ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer') if (!start) start = 0 if (!end && end !== 0) end = this.length if (targetStart >= target.length) targetStart = target.length @@ -1670,7 +1686,7 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { if (targetStart < 0) { throw new RangeError('targetStart out of bounds') } - if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') + if (start < 0 || start >= this.length) throw new RangeError('Index out of range') if (end < 0) throw new RangeError('sourceEnd out of bounds') // Are we oob? @@ -1680,22 +1696,19 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { } var len = end - start - var i - if (this === target && start < targetStart && targetStart < end) { + if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { + // Use built-in when available, missing from IE11 + this.copyWithin(targetStart, start, end) + } else if (this === target && start < targetStart && targetStart < end) { // descending copy from end - for (i = len - 1; i >= 0; --i) { - target[i + targetStart] = this[i + start] - } - } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - // ascending copy from start - for (i = 0; i < len; ++i) { + for (var i = len - 1; i >= 0; --i) { target[i + targetStart] = this[i + start] } } else { Uint8Array.prototype.set.call( target, - this.subarray(start, start + len), + this.subarray(start, end), targetStart ) } @@ -1718,18 +1731,20 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { encoding = end end = this.length } - if (val.length === 1) { - var code = val.charCodeAt(0) - if (code < 256) { - val = code - } - } if (encoding !== undefined && typeof encoding !== 'string') { throw new TypeError('encoding must be a string') } if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { throw new TypeError('Unknown encoding: ' + encoding) } + if (val.length === 1) { + var code = val.charCodeAt(0) + if ((encoding === 'utf8' && code < 128) || + encoding === 'latin1') { + // Fast path: If `val` fits into a single byte, use that numeric value. + val = code + } + } } else if (typeof val === 'number') { val = val & 255 } @@ -1756,8 +1771,12 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { } else { var bytes = Buffer.isBuffer(val) ? val - : utf8ToBytes(new Buffer(val, encoding).toString()) + : Buffer.from(val, encoding) var len = bytes.length + if (len === 0) { + throw new TypeError('The value "' + val + + '" is invalid for argument "value"') + } for (i = 0; i < end - start; ++i) { this[i + start] = bytes[i % len] } @@ -1769,11 +1788,13 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { // HELPER FUNCTIONS // ================ -var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g +var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g function base64clean (str) { + // Node takes equal signs as end of the Base64 encoding + str = str.split('=')[0] // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = stringtrim(str).replace(INVALID_BASE64_RE, '') + str = str.trim().replace(INVALID_BASE64_RE, '') // Node converts strings with length < 2 to '' if (str.length < 2) return '' // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not @@ -1783,11 +1804,6 @@ function base64clean (str) { return str } -function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') -} - function toHex (n) { if (n < 16) return '0' + n.toString(16) return n.toString(16) @@ -1910,15 +1926,24 @@ function blitBuffer (src, dst, offset, length) { return i } -function isnan (val) { - return val !== val // eslint-disable-line no-self-compare +// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass +// the `instanceof` check but they should be treated as of that type. +// See: https://github.com/feross/buffer/issues/166 +function isInstance (obj, type) { + return obj instanceof type || + (obj != null && obj.constructor != null && obj.constructor.name != null && + obj.constructor.name === type.name) +} +function numberIsNaN (obj) { + // For IE11 support + return obj !== obj // eslint-disable-line no-self-compare } -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"base64-js":1,"ieee754":4,"isarray":5}],4:[function(require,module,exports){ +}).call(this,require("buffer").Buffer) +},{"base64-js":1,"buffer":3,"ieee754":4}],4:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var nBits = -7 @@ -1931,12 +1956,12 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { e = s & ((1 << (-nBits)) - 1) s >>= (-nBits) nBits += eLen - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} m = e & ((1 << (-nBits)) - 1) e >>= (-nBits) nBits += mLen - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} if (e === 0) { e = 1 - eBias @@ -1951,7 +1976,7 @@ exports.read = function (buffer, offset, isLE, mLen, nBytes) { exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { var e, m, c - var eLen = nBytes * 8 - mLen - 1 + var eLen = (nBytes * 8) - mLen - 1 var eMax = (1 << eLen) - 1 var eBias = eMax >> 1 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) @@ -1984,7 +2009,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { m = 0 e = eMax } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen) + m = ((value * c) - 1) * Math.pow(2, mLen) e = e + eBias } else { m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) @@ -2002,13 +2027,6 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { } },{}],5:[function(require,module,exports){ -var toString = {}.toString; - -module.exports = Array.isArray || function (arr) { - return toString.call(arr) == '[object Array]'; -}; - -},{}],6:[function(require,module,exports){ (function (Buffer,__dirname){ /* globals chrome: false */ /* globals __dirname: false */ @@ -2941,8 +2959,8 @@ Typo.prototype = { if (typeof module !== 'undefined') { module.exports = Typo; } -}).call(this,require("buffer").Buffer,"/node_modules\\typo-js") -},{"buffer":3,"fs":2}],7:[function(require,module,exports){ +}).call(this,require("buffer").Buffer,"/node_modules/typo-js") +},{"buffer":3,"fs":2}],6:[function(require,module,exports){ // Use strict mode (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) "use strict"; @@ -3016,17 +3034,17 @@ function CodeMirrorSpellChecker(options) { // Define what separates a word - var rx_word = /^[^!\"#$%&()*+,\-./:;<=>?@\[\\\]^_`{|}~\s]+/; + var rx_word = /^[^!"#$%&()*+,\-./:;<=>?@[\\\]^_`{|}~\s]+/; // Ignore words that are just numbers var rx_ignore = /^[0-9]+$/; // Get array of custom words - var customWords; + var customWords = []; if(options.customWords && options.customWords instanceof Array) { - customWords = options.customWords || []; + customWords = options.customWords; } // Create the overlay and such @@ -3065,5 +3083,5 @@ CodeMirrorSpellChecker.typo; // Export module.exports = CodeMirrorSpellChecker; -},{"typo-js":6}]},{},[7])(7) -}); \ No newline at end of file +},{"typo-js":5}]},{},[6])(6) +}); diff --git a/dist/spell-checker.min.js b/dist/spell-checker.min.js index b9c42f3..332372c 100644 --- a/dist/spell-checker.min.js +++ b/dist/spell-checker.min.js @@ -4,5 +4,4 @@ * @link https://github.com/NextStepWebs/codemirror-spell-checker * @license MIT */ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.CodeMirrorSpellChecker=t()}}(function(){return function t(e,r,n){function i(s,a){if(!r[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var h=r[s]={exports:{}};e[s][0].call(h.exports,function(t){var r=e[s][1][t];return i(r?r:t)},h,h.exports,t,e,r,n)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;s0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function i(t){return 3*t.length/4-n(t)}function o(t){var e,r,i,o,s,a,u=t.length;s=n(t),a=new l(3*u/4-s),i=s>0?u-4:u;var f=0;for(e=0,r=0;e>16&255,a[f++]=o>>8&255,a[f++]=255&o;return 2===s?(o=h[t.charCodeAt(e)]<<2|h[t.charCodeAt(e+1)]>>4,a[f++]=255&o):1===s&&(o=h[t.charCodeAt(e)]<<10|h[t.charCodeAt(e+1)]<<4|h[t.charCodeAt(e+2)]>>2,a[f++]=o>>8&255,a[f++]=255&o),a}function s(t){return f[t>>18&63]+f[t>>12&63]+f[t>>6&63]+f[63&t]}function a(t,e,r){for(var n,i=[],o=e;oh?h:u+s));return 1===n?(e=t[r-1],i+=f[e>>2],i+=f[e<<4&63],i+="=="):2===n&&(e=(t[r-2]<<8)+t[r-1],i+=f[e>>10],i+=f[e>>4&63],i+=f[e<<2&63],i+="="),o.push(i),o.join("")}r.byteLength=i,r.toByteArray=o,r.fromByteArray=u;for(var f=[],h=[],l="undefined"!=typeof Uint8Array?Uint8Array:Array,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=0,d=c.length;p=i())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i().toString(16)+" bytes");return 0|t}function y(t){return+t!=t&&(t=0),s.alloc(+t)}function v(t,e){if(s.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return $(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return W(t).length;default:if(n)return $(t).length;e=(""+e).toLowerCase(),n=!0}}function w(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if(r>>>=0,e>>>=0,r<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return I(this,e,r);case"utf8":case"utf-8":return S(this,e,r);case"ascii":return x(this,e,r);case"latin1":case"binary":return M(this,e,r);case"base64":return U(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function m(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function b(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:E(t,e,r,n,i);if("number"==typeof e)return e=255&e,s.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):E(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function E(t,e,r,n,i){function o(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}var s=1,a=t.length,u=e.length;if(void 0!==n&&(n=String(n).toLowerCase(),"ucs2"===n||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,r/=2}var f;if(i){var h=-1;for(f=r;fa&&(r=a-u),f=r;f>=0;f--){for(var l=!0,c=0;ci&&(n=i)):n=i;var o=e.length;if(o%2!==0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s239?4:o>223?3:o>191?2:1;if(i+a<=r){var u,f,h,l;switch(a){case 1:o<128&&(s=o);break;case 2:u=t[i+1],128===(192&u)&&(l=(31&o)<<6|63&u,l>127&&(s=l));break;case 3:u=t[i+1],f=t[i+2],128===(192&u)&&128===(192&f)&&(l=(15&o)<<12|(63&u)<<6|63&f,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:u=t[i+1],f=t[i+2],h=t[i+3],128===(192&u)&&128===(192&f)&&128===(192&h)&&(l=(15&o)<<18|(63&u)<<12|(63&f)<<6|63&h,l>65535&&l<1114112&&(s=l))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=a}return B(n)}function B(t){var e=t.length;if(e<=tt)return String.fromCharCode.apply(String,t);for(var r="",n=0;nn)&&(r=n);for(var i="",o=e;or)throw new RangeError("Trying to access beyond buffer length")}function Y(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function D(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i>>8*(n?i:1-i)}function N(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i>>8*(n?i:3-i)&255}function k(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function F(t,e,r,n,i){return i||k(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),Z.write(t,e,r,n,23,4),r+4}function z(t,e,r,n,i){return i||k(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),Z.write(t,e,r,n,52,8),r+8}function j(t){if(t=X(t).replace(et,""),t.length<2)return"";for(;t.length%4!==0;)t+="=";return t}function X(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function q(t){return t<16?"0"+t.toString(16):t.toString(16)}function $(t,e){e=e||1/0;for(var r,n=t.length,i=null,o=[],s=0;s55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function G(t){for(var e=[],r=0;r>8,i=r%256,o.push(i),o.push(n);return o}function W(t){return J.toByteArray(j(t))}function K(t,e,r,n){for(var i=0;i=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function V(t){return t!==t}var J=t("base64-js"),Z=t("ieee754"),Q=t("isarray");r.Buffer=s,r.SlowBuffer=y,r.INSPECT_MAX_BYTES=50,s.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:n(),r.kMaxLength=i(),s.poolSize=8192,s._augment=function(t){return t.__proto__=s.prototype,t},s.from=function(t,e,r){return a(null,t,e,r)},s.TYPED_ARRAY_SUPPORT&&(s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&s[Symbol.species]===s&&Object.defineProperty(s,Symbol.species,{value:null,configurable:!0})),s.alloc=function(t,e,r){return f(null,t,e,r)},s.allocUnsafe=function(t){return h(null,t)},s.allocUnsafeSlow=function(t){return h(null,t)},s.isBuffer=function(t){return!(null==t||!t._isBuffer)},s.compare=function(t,e){if(!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},s.prototype.compare=function(t,e,r,n,i){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(e>>>=0,r>>>=0,n>>>=0,i>>>=0,this===t)return 0;for(var o=i-n,a=r-e,u=Math.min(o,a),f=this.slice(n,i),h=t.slice(e,r),l=0;li)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return R(this,t,e,r);case"utf8":case"utf-8":return _(this,t,e,r);case"ascii":return A(this,t,e,r);case"latin1":case"binary":return P(this,t,e,r);case"base64":return T(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var tt=4096;s.prototype.slice=function(t,e){var r=this.length;t=~~t,e=void 0===e?r:~~e,t<0?(t+=r,t<0&&(t=0)):t>r&&(t=r),e<0?(e+=r,e<0&&(e=0)):e>r&&(e=r),e0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUInt8=function(t,e){return e||L(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return e||L(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return e||L(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return e||L(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUInt32BE=function(t,e){return e||L(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,r){t=0|t,e=0|e,r||L(t,e,this.length);for(var n=this[t],i=1,o=0;++o=i&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t=0|t,e=0|e,r||L(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return e||L(t,1,this.length),128&this[t]?(255-this[t]+1)*-1:this[t]},s.prototype.readInt16LE=function(t,e){e||L(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){e||L(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return e||L(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return e||L(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return e||L(t,4,this.length),Z.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return e||L(t,4,this.length),Z.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return e||L(t,8,this.length),Z.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return e||L(t,8,this.length),Z.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,r,n){if(t=+t,e=0|e,r=0|r,!n){var i=Math.pow(2,8*r)-1;Y(this,t,e,r,i,0)}var o=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+o]=t/s&255;return e+r},s.prototype.writeUInt8=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,1,255,0),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):D(this,t,e,!0),e+2},s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):D(this,t,e,!1),e+2},s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):N(this,t,e,!0),e+4},s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);Y(this,t,e,r,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o>0)-a&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);Y(this,t,e,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,1,127,-128),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):D(this,t,e,!0),e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):D(this,t,e,!1),e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,4,2147483647,-2147483648),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):N(this,t,e,!0),e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e=0|e,r||Y(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},s.prototype.writeFloatLE=function(t,e,r){return F(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return F(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return z(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return z(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--i)t[i+e]=this[i+r];else if(o<1e3||!s.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,t||(t=0);var o;if("number"==typeof t)for(o=e;o>1,h=-7,l=r?i-1:0,c=r?-1:1,p=t[e+l];for(l+=c,o=p&(1<<-h)-1,p>>=-h,h+=a;h>0;o=256*o+t[e+l],l+=c,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+t[e+l],l+=c,h-=8);if(0===o)o=1-f;else{if(o===u)return s?NaN:(p?-1:1)*(1/0);s+=Math.pow(2,n),o-=f}return(p?-1:1)*s*Math.pow(2,o-n)},r.write=function(t,e,r,n,i,o){var s,a,u,f=8*o-i-1,h=(1<>1,c=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),e+=s+l>=1?c/u:c*Math.pow(2,1-l),e*u>=2&&(s++,u/=2),s+l>=h?(a=0,s=h):s+l>=1?(a=(e*u-1)*Math.pow(2,i),s+=l):(a=e*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;t[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<0;t[r+p]=255&s,p+=d,s/=256,f-=8);t[r+p-d]|=128*g}},{}],5:[function(t,e,r){var n={}.toString;e.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},{}],6:[function(t,e,r){(function(r,n){var i;!function(){"use strict";i=function(t,e,r,i){function o(t,e){var r=d._readFile(t,null,i.asyncLoad);i.asyncLoad?r.then(function(t){e(t)}):e(r)}function s(t){e=t,r&&u()}function a(t){r=t,e&&u()}function u(){for(d.rules=d._parseAFF(e),d.compoundRuleCodes={},h=0,c=d.compoundRules.length;h0&&(E.continuationClasses=m),"."!==b&&("SFX"===c?E.match=new RegExp(b+"$"):E.match=new RegExp("^"+b)),"0"!=y&&("SFX"===c?E.remove=new RegExp(y+"$"):E.remove=y),g.push(E)}f[p]={type:c,combineable:"Y"==d,entries:g},o+=n}else if("COMPOUNDRULE"===c){for(n=parseInt(l[1],10),s=o+1,u=o+1+n;s0&&(null===n[t]&&(n[t]=[]),n[t].push(e))}t=this._removeDicComments(t);for(var r=t.split("\n"),n={},i=1,o=r.length;i1){var f=this.parseRuleCodes(a[1]);"NEEDAFFIX"in this.flags&&f.indexOf(this.flags.NEEDAFFIX)!=-1||e(u,f);for(var h=0,l=f.length;h=this.flags.COMPOUNDMIN)for(e=0,r=this.compoundRules.length;e1&&f[1][1]!==f[1][0]&&a.push(f[0]+f[1][1]+f[1][0]+f[1].substring(2)),f[1])for(n=0,s=h.alphabet.length;n?@\[\\\]^_`{|}~\s]+/,u=/^[0-9]+$/;t.customWords&&t.customWords instanceof Array&&(s=t.customWords||[]);var f={token:function(t){var e=t.match(a,!0);if(e){if(e=e[0],!e.match(u)&&n.typo&&!n.typo.check(e)&&!~s.indexOf(e))return"spell-error"}else t.next();return null}},h=t.codeMirrorInstance.getMode(e,e.backdrop||"text/plain");return t.codeMirrorInstance.overlayMode(h,f,!0)}))}var i=t("typo-js");n.num_loaded=0,n.aff_loading=!1,n.dic_loading=!1,n.aff_data="",n.dic_data="",n.typo,e.exports=n},{"typo-js":6}]},{},[7])(7)}); \ No newline at end of file +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).CodeMirrorSpellChecker=t()}}(function(){return function i(s,f,u){function a(e,t){if(!f[e]){if(!s[e]){var r="function"==typeof require&&require;if(!t&&r)return r(e,!0);if(h)return h(e,!0);var n=new Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}var o=f[e]={exports:{}};s[e][0].call(o.exports,function(t){return a(s[e][1][t]||t)},o,o.exports,i,s,f,u)}return f[e].exports}for(var h="function"==typeof require&&require,t=0;t>16&255,i[s++]=e>>8&255,i[s++]=255&e;2===o&&(e=a[t.charCodeAt(u)]<<2|a[t.charCodeAt(u+1)]>>4,i[s++]=255&e);1===o&&(e=a[t.charCodeAt(u)]<<10|a[t.charCodeAt(u+1)]<<4|a[t.charCodeAt(u+2)]>>2,i[s++]=e>>8&255,i[s++]=255&e);return i},r.fromByteArray=function(t){for(var e,r=t.length,n=r%3,o=[],i=0,s=r-n;i>2]+f[e<<4&63]+"==")):2==n&&(e=(t[r-2]<<8)+t[r-1],o.push(f[e>>10]+f[e>>4&63]+f[e<<2&63]+"="));return o.join("")};for(var f=[],a=[],h="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,i=n.length;o>18&63]+f[o>>12&63]+f[o>>6&63]+f[63&o]);return i.join("")}a["-".charCodeAt(0)]=62,a["_".charCodeAt(0)]=63},{}],2:[function(t,e,r){},{}],3:[function(t,e,N){(function(l){"use strict";var n=t("base64-js"),i=t("ieee754");N.Buffer=l,N.SlowBuffer=function(t){+t!=t&&(t=0);return l.alloc(+t)},N.INSPECT_MAX_BYTES=50;var r=2147483647;function s(t){if(r>>1;case"base64":return M(t).length;default:if(o)return n?-1:S(t).length;e=(""+e).toLowerCase(),o=!0}}function p(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function d(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):2147483647=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=l.from(e,n)),l.isBuffer(e))return 0===e.length?-1:g(t,e,r,n,o);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):g(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function g(t,e,r,n,o){var i,s=1,f=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;f/=s=2,u/=2,r/=2}function a(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){var h=-1;for(i=r;i>>10&1023|55296),h=56320|1023&h),n.push(h),o+=l}return function(t){var e=t.length;if(e<=b)return String.fromCharCode.apply(String,t);var r="",n=0;for(;nthis.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return C(this,e,r);case"utf8":case"utf-8":return w(this,e,r);case"ascii":return E(this,e,r);case"latin1":case"binary":return A(this,e,r);case"base64":return m(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},l.prototype.equals=function(t){if(!l.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===l.compare(this,t)},l.prototype.inspect=function(){var t="",e=N.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),""},l.prototype.compare=function(t,e,r,n,o){if(O(t,Uint8Array)&&(t=l.from(t,t.offset,t.byteLength)),!l.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(o<=n&&r<=e)return 0;if(o<=n)return-1;if(r<=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),f=Math.min(i,s),u=this.slice(n,o),a=t.slice(e,r),h=0;h>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-e;if((void 0===r||othis.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i,s,f,u,a,h,l,c,p,d=!1;;)switch(n){case"hex":return y(this,t,e,r);case"utf8":case"utf-8":return c=e,p=r,L(S(t,(l=this).length-c),l,c,p);case"ascii":return v(this,t,e,r);case"latin1":case"binary":return v(this,t,e,r);case"base64":return u=this,a=e,h=r,L(M(t),u,a,h);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return s=e,f=r,L(function(t,e){for(var r,n,o,i=[],s=0;s>8,o=r%256,i.push(o),i.push(n);return i}(t,(i=this).length-s),i,s,f);default:if(d)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),d=!0}},l.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var b=4096;function E(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;ot.length)throw new RangeError("Index out of range")}function U(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function x(t,e,r,n,o){return e=+e,r>>>=0,o||U(t,0,r,4),i.write(t,e,r,n,23,4),r+4}function T(t,e,r,n,o){return e=+e,r>>>=0,o||U(t,0,r,8),i.write(t,e,r,n,52,8),r+8}l.prototype.slice=function(t,e){var r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):r>>=0,e>>>=0,r||B(t,e,this.length);for(var n=this[t],o=1,i=0;++i>>=0,e>>>=0,r||B(t,e,this.length);for(var n=this[t+--e],o=1;0>>=0,e||B(t,1,this.length),this[t]},l.prototype.readUInt16LE=function(t,e){return t>>>=0,e||B(t,2,this.length),this[t]|this[t+1]<<8},l.prototype.readUInt16BE=function(t,e){return t>>>=0,e||B(t,2,this.length),this[t]<<8|this[t+1]},l.prototype.readUInt32LE=function(t,e){return t>>>=0,e||B(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},l.prototype.readUInt32BE=function(t,e){return t>>>=0,e||B(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},l.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||B(t,e,this.length);for(var n=this[t],o=1,i=0;++i>>=0,e>>>=0,r||B(t,e,this.length);for(var n=e,o=1,i=this[t+--n];0>>=0,e||B(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},l.prototype.readInt16LE=function(t,e){t>>>=0,e||B(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},l.prototype.readInt16BE=function(t,e){t>>>=0,e||B(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},l.prototype.readInt32LE=function(t,e){return t>>>=0,e||B(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},l.prototype.readInt32BE=function(t,e){return t>>>=0,e||B(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},l.prototype.readFloatLE=function(t,e){return t>>>=0,e||B(t,4,this.length),i.read(this,t,!0,23,4)},l.prototype.readFloatBE=function(t,e){return t>>>=0,e||B(t,4,this.length),i.read(this,t,!1,23,4)},l.prototype.readDoubleLE=function(t,e){return t>>>=0,e||B(t,8,this.length),i.read(this,t,!0,52,8)},l.prototype.readDoubleBE=function(t,e){return t>>>=0,e||B(t,8,this.length),i.read(this,t,!1,52,8)},l.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e>>>=0,r>>>=0,n)||R(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[e]=255&t;++i>>=0,r>>>=0,n)||R(this,t,e,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[e+o]=255&t;0<=--o&&(i*=256);)this[e+o]=t/i&255;return e+r},l.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,1,255,0),this[e]=255&t,e+1},l.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},l.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},l.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},l.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},l.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var o=Math.pow(2,8*r-1);R(this,t,e,r,o-1,-o)}var i=0,s=1,f=0;for(this[e]=255&t;++i>0)-f&255;return e+r},l.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var o=Math.pow(2,8*r-1);R(this,t,e,r,o-1,-o)}var i=r-1,s=1,f=0;for(this[e+i]=255&t;0<=--i&&(s*=256);)t<0&&0===f&&0!==this[e+i+1]&&(f=1),this[e+i]=(t/s>>0)-f&255;return e+r},l.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},l.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},l.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},l.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},l.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},l.prototype.writeFloatLE=function(t,e,r){return x(this,t,e,!0,r)},l.prototype.writeFloatBE=function(t,e,r){return x(this,t,e,!1,r)},l.prototype.writeDoubleLE=function(t,e,r){return T(this,t,e,!0,r)},l.prototype.writeDoubleBE=function(t,e,r){return T(this,t,e,!1,r)},l.prototype.copy=function(t,e,r,n){if(!l.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),0=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function M(t){return n.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(e,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function L(t,e,r,n){for(var o=0;o=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function O(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function k(t){return t!=t}}).call(this,t("buffer").Buffer)},{"base64-js":1,buffer:3,ieee754:4}],4:[function(t,e,r){r.read=function(t,e,r,n,o){var i,s,f=8*o-n-1,u=(1<>1,h=-7,l=r?o-1:0,c=r?-1:1,p=t[e+l];for(l+=c,i=p&(1<<-h)-1,p>>=-h,h+=f;0>=-h,h+=n;0>1,c=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,d=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(f=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),2<=(e+=1<=s+l?c/u:c*Math.pow(2,1-l))*u&&(s++,u/=2),h<=s+l?(f=0,s=h):1<=s+l?(f=(e*u-1)*Math.pow(2,o),s+=l):(f=e*Math.pow(2,l-1)*Math.pow(2,o),s=0));8<=o;t[r+p]=255&f,p+=d,f/=256,o-=8);for(s=s<=this.flags.COMPOUNDMIN)for(e=0,r=this.compoundRules.length;e?@[\\\]^_`{|}~\s]+/,o=/^[0-9]+$/,i=[];u.customWords&&u.customWords instanceof Array&&(i=u.customWords);var s={token:function(t){var e=t.match(n,!0);if(e){if(!(e=e[0]).match(o)&&h.typo&&!h.typo.check(e)&&!~i.indexOf(e))return"spell-error"}else t.next();return null}},f=u.codeMirrorInstance.getMode(t,t.backdrop||"text/plain");return u.codeMirrorInstance.overlayMode(f,s,!0)})):console.log("CodeMirror Spell Checker: You must provide an instance of CodeMirror via the option `codeMirrorInstance`")}h.num_loaded=0,h.aff_loading=!1,h.dic_loading=!1,h.aff_data="",h.dic_data="",e.exports=h},{"typo-js":5}]},{},[6])(6)}); \ No newline at end of file diff --git a/src/js/spell-checker.js b/src/js/spell-checker.js index 97470dd..ea76907 100644 --- a/src/js/spell-checker.js +++ b/src/js/spell-checker.js @@ -78,10 +78,10 @@ function CodeMirrorSpellChecker(options) { // Get array of custom words - var customWords; + var customWords = []; if(options.customWords && options.customWords instanceof Array) { - customWords = options.customWords || []; + customWords = options.customWords; } // Create the overlay and such