"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app.asar.unpacked/node_modules/spellchecker/lib/spellchecker.js" (7 Feb 2017, 2183 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var path = require('path');
    2 var bindings = require('../build/Release/spellchecker.node');
    3 
    4 var Spellchecker = bindings.Spellchecker;
    5 
    6 var defaultSpellcheck = null;
    7 
    8 var setDictionary = function(lang, dictPath) {
    9   defaultSpellcheck = new Spellchecker();
   10   // NB: Windows 8 uses *dashes* to set the language (i.e. en-US), so if we fail
   11   // to set the language, try the Windows 8 way
   12   lang = lang.replace('_', '-');
   13   if (!defaultSpellcheck.setDictionary(lang, dictPath)) {
   14     lang = lang.replace('-', '_');
   15     defaultSpellcheck.setDictionary(lang, dictPath);
   16   }
   17 };
   18 
   19 var ensureDefaultSpellCheck = function() {
   20   if (defaultSpellcheck) {
   21     return;
   22   }
   23 
   24   var lang = process.env.LANG;
   25   lang = lang ? lang.split('.')[0] : 'en_US';
   26   setDictionary(lang, getDictionaryPath());
   27 };
   28 
   29 var isMisspelled = function() {
   30   ensureDefaultSpellCheck();
   31 
   32   return defaultSpellcheck.isMisspelled.apply(defaultSpellcheck, arguments);
   33 };
   34 
   35 var checkSpelling = function() {
   36   ensureDefaultSpellCheck();
   37 
   38   return defaultSpellcheck.checkSpelling.apply(defaultSpellcheck, arguments);
   39 };
   40 
   41 var add = function() {
   42   ensureDefaultSpellCheck();
   43 
   44   defaultSpellcheck.add.apply(defaultSpellcheck, arguments);
   45 };
   46 
   47 var getCorrectionsForMisspelling = function() {
   48   ensureDefaultSpellCheck();
   49 
   50   return defaultSpellcheck.getCorrectionsForMisspelling.apply(defaultSpellcheck, arguments);
   51 };
   52 
   53 var getAvailableDictionaries = function() {
   54   ensureDefaultSpellCheck();
   55 
   56   return defaultSpellcheck.getAvailableDictionaries.apply(defaultSpellcheck, arguments);
   57 };
   58 
   59 var getDictionaryPath = function() {
   60   var dict = path.join(__dirname, '..', 'vendor', 'hunspell_dictionaries');
   61   try {
   62     // HACK: Special case being in an asar archive
   63     var unpacked = dict.replace('.asar' + path.sep, '.asar.unpacked' + path.sep);
   64     if (require('fs').statSyncNoException(unpacked)) {
   65       dict = unpacked;
   66     }
   67   } catch (error) {
   68   }
   69   return dict;
   70 }
   71 
   72 module.exports = {
   73   setDictionary: setDictionary,
   74   add: add,
   75   isMisspelled: isMisspelled,
   76   checkSpelling: checkSpelling,
   77   getAvailableDictionaries: getAvailableDictionaries,
   78   getCorrectionsForMisspelling: getCorrectionsForMisspelling,
   79   Spellchecker: Spellchecker
   80 };