src/misspellings.js
function correct(str, options, callback) {
  if (typeof options === "function") {
    callback = options;
    options = {};
  }
  const {caseSensitive, overrideCases} = options || {};

  str = String(str || "");
  const dic = dict({ lowerCase: true });
  const re  = regexp(caseSensitive ? "g" : "ig");
  return str.replace(re, (misspell) => {
    const csv = dic[misspell.toLowerCase()];
    if (!csv) return misspell;

    const corrects = csv.split(",");
    let corrected;
    if (callback) {
      corrected = callback(misspell, corrects);
      if (typeof corrected === "undefined" || corrected === null) return misspell;
      corrected = String(corrected);
    } else {
      corrected = corrects[0];
    }

    if (!overrideCases) {
      corrected = mapCases(misspell, corrected);
    }

    return corrected;
  });
}
function correct(str, options, callback) {
  if (typeof options === "function") {
    callback = options;
    options = {};
  }
  const {caseSensitive, overrideCases} = options || {};

  str = String(str || "");
  const dic = dict({ lowerCase: true });
  const re  = regexp(caseSensitive ? "g" : "ig");
  return str.replace(re, (misspell) => {
    const csv = dic[misspell.toLowerCase()];
    if (!csv) return misspell;

    const corrects = csv.split(",");
    let corrected;
    if (callback) {
      corrected = callback(misspell, corrects);
      if (typeof corrected === "undefined" || corrected === null) return misspell;
      corrected = String(corrected);
    } else {
      corrected = corrects[0];
    }

    if (!overrideCases) {
      corrected = mapCases(misspell, corrected);
    }

    return corrected;
  });
}
function correct ( str , options , callback ) { if ( typeof options === "function" ) { callback = options ; options = { } ; } const { caseSensitive , overrideCases } = options || { } ; str = String ( str || "" ) ; const dic = dict ( { lowerCase : true } ) ; const re = regexp ( caseSensitive ? "g" : "ig" ) ; return str . replace ( re , ( misspell ) => { const csv = dic [ misspell . toLowerCase ( ) ] ; if ( ! csv ) return misspell ; const corrects = csv . split ( "," ) ; let corrected ; if ( callback ) { corrected = callback ( misspell , corrects ) ; if ( typeof corrected === "undefined" || corrected === null ) return misspell ; corrected = String ( corrected ) ; } else { corrected = corrects [ 0 ] ; } if ( ! overrideCases ) { corrected = mapCases ( misspell , corrected ) ; } return corrected ; } ) ; }
Correct all misspellings in a string.

It is case-insensitive by default, but it tries to keep cases
(upper to upper, lower to lower) after misspellings corrected.

You can skip options and call in `correct(str, callback)` form.

@param {string} str  A target string.
@param {Object} [options]  Options.
@param {Boolean} [options.caseSensitive=false]
If `true`, do case-sensitive search for misspellings.
@param {Boolean} [options.overrideCases=false]
If `true`, skip mapping cases and always use an exact word
in the dictionary.
@param {correct~correctCallback} [callback]
A callback function to be called each time misspellings found.
@return {string}
Corrected string
Correct all misspellings in a string .