<commit_before>import { get } from '../util';
import { Observable } from 'rxjs/Observable';

declare var window;
declare var Promise;

/**
 * @private
 * @param pluginRef
 * @returns {null|*}
 */
export const getPlugin = function(pluginRef: string): any {
  return get(window, pluginRef);
};

/**
 * @private
 * @param pluginObj
 * @param method
 */
export const pluginWarn = function(pluginObj: any, method?: string) {
  let pluginName = pluginObj.name, plugin = pluginObj.plugin;
  if (method) {
    console.warn('Native: tried calling ' + pluginName + '.' + method + ', but the ' + pluginName + ' plugin is not installed.');
  } else {
    console.warn('Native: tried accessing the ' + pluginName + ' plugin but it\'s not installed.');
  }
  console.warn('Install the ' + pluginName + ' plugin: \'ionic plugin add ' + plugin + '\'');
};

/**
 * @private
 * @param pluginName
 * @param method
 */
export const cordovaWarn = function(pluginName: string, method: string) {
  if (method) {
    console.warn('Native: tried calling ' + pluginName + '.' + method + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
  } else {
    console.warn('Native: tried accessing the ' + pluginName + ' plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
  }
};
function setIndex(args: any[], opts: any = {}, resolve?: Function, reject?: Function): any {
  // If the plugin method expects myMethod(success, err, options)
  if (opts.callbackOrder === 'reverse') {
    // Get those arguments in the order [resolve, reject, ...restOfArgs]
    args.unshift(reject);
    args.unshift(resolve);
  } else if (opts.callbackStyle === 'node') {
    args.push((err, result) => {
      if (err) {
        reject(err);
      } else {
        resolve(result);
      }
    });
  } else if (opts.callbackStyle === 'object' && opts.successName && opts.errorName) {
    let obj: any = {};
    obj[opts.successName] = resolve;
    obj[opts.errorName] = reject;
    args.push(obj);
  } else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') {
    // If we've specified a success/error index

    if (opts.successIndex > args.length) {
      args[opts.successIndex] = resolve;
    } else {
      args.splice(opts.successIndex, 0, resolve);
    }

    // We don't want that the reject cb gets spliced into the position of an optional argument that has not been defined and thus causing non expected behaviour.
    if (opts.errorIndex > args.length) {
      args[opts.errorIndex] = reject; // insert the reject fn at the correct specific index
    } else {
      args.splice(opts.errorIndex, 0, reject); // otherwise just splice it into the array
    }
  } else {
    // Otherwise, let's tack them on to the end of the argument list
    // which is 90% of cases
    args.push(resolve);
    args.push(reject);
  }
  return args;<commit_msg>fix google maps setPadding not working issue #573 (#654)<commit_after>import { get } from '../util';
import { Observable } from 'rxjs/Observable';

declare var window;
declare var Promise;

/**
 * @private
 * @param pluginRef
 * @returns {null|*}
 */
export const getPlugin = function(pluginRef: string): any {
  return get(window, pluginRef);
};

/**
 * @private
 * @param pluginObj
 * @param method
 */
export const pluginWarn = function(pluginObj: any, method?: string) {
  let pluginName = pluginObj.name, plugin = pluginObj.plugin;
  if (method) {
    console.warn('Native: tried calling ' + pluginName + '.' + method + ', but the ' + pluginName + ' plugin is not installed.');
  } else {
    console.warn('Native: tried accessing the ' + pluginName + ' plugin but it\'s not installed.');
  }
  console.warn('Install the ' + pluginName + ' plugin: \'ionic plugin add ' + plugin + '\'');
};

/**
 * @private
 * @param pluginName
 * @param method
 */
export const cordovaWarn = function(pluginName: string, method: string) {
  if (method) {
    console.warn('Native: tried calling ' + pluginName + '.' + method + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
  } else {
    console.warn('Native: tried accessing the ' + pluginName + ' plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
  }
};
function setIndex(args: any[], opts: any = {}, resolve?: Function, reject?: Function): any {
  // If the plugin method expects myMethod(success, err, options)
  if (opts.callbackOrder === 'reverse') {
    // Get those arguments in the order [resolve, reject, ...restOfArgs]
    args.unshift(reject);
    args.unshift(resolve);
  } else if (opts.callbackStyle === 'node') {
    args.push((err, result) => {
      if (err) {
        reject(err);
      } else {
        resolve(result);
      }
    });
  } else if (opts.callbackStyle === 'object' && opts.successName && opts.errorName) {
    let obj: any = {};
    obj[opts.successName] = resolve;
    obj[opts.errorName] = reject;
    args.push(obj);
  } else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') {
    // If we've specified a success/error index

    if (opts.successIndex > args.length) {
      args[opts.successIndex] = resolve;
    } else {
      args.splice(opts.successIndex, 0, resolve);
    }

    // We don't want that the reject cb gets spliced into the position of an optional argument that has not been defined and thus causing non expected behaviour.
    if (opts.errorIndex > args.length) {
      args[opts.errorIndex] = reject; // insert the reject fn at the correct specific index
    } else {
      args.splice(opts.errorIndex, 0, reject); // otherwise just splice it into the array
    }
  } else {
    // Otherwise, let's tack them on to the end of the argument list
    // which is 90% of cases
    if (!opts.sync) {
      args.push(resolve);
      args.push(reject);
    }
  }
  return args;
{'fraction_non_alphanumeric': 0.13730439172135286, 'fraction_numerical': 0.002355712603062426, 'mean_word_length': 3.1859154929577467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7111388', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1732, 'n_words': 585}