<commit_before>/**
 * 每位工程师都有保持代码优雅的义务
 * Each engineer has a duty to keep the code elegant
**/

'use strict';

const _ = require('underscore');

module.exports = function(AV) {

  // 挂载一些配置
  let AVConfig = AV._config;

  _.extend(AVConfig, {

    // 服务器请求的节点 host
    apiHost : {
      cn: 'https://api.leancloud.cn',
      us: 'https://us-api.leancloud.cn'
    },

    // 服务器节点地区，默认中国大陆
    region: 'cn'
  });

  /**
   * Contains all AV API classes and functions.
   * @name AV
   * @namespace
   *
   * Contains all AV API classes and functions.
   */

  // Check whether we are running in Node.js.
  if (typeof(process) !== 'undefined' && process.versions && process.versions.node) {
    AVConfig.isNode = true;
  }

  // Helpers
  // -------

  // Shared empty constructor function to aid in prototype-chain creation.
  var EmptyConstructor = function() {};


  // Helper function to correctly set up the prototype chain, for subclasses.
  // Similar to `goog.inherits`, but uses a hash of prototype properties and
  // class properties to be extended.
  var inherits = function(parent, protoProps, staticProps) {
    var child;

    // The constructor function for the new subclass is either defined by you
    // (the "constructor" property in your `extend` definition), or defaulted
    // by us to simply call the parent's constructor.
    if (protoProps && protoProps.hasOwnProperty('constructor')) {
      child = protoProps.constructor;
    } else {
      /** @ignore */
      child = function(){ parent.apply(this, arguments); };
    }

    // Inherit class (static) properties from parent.
    _.extend(child, parent);

    // Set the prototype chain to inherit from `parent`, without calling
    // `parent`'s constructor function.
    EmptyConstructor.prototype = parent.prototype;
    child.prototype = new EmptyConstructor();

    // Add prototype properties (instance properties) to the subclass,
    // if supplied.
    if (protoProps) {
      _.extend(child.prototype, protoProps);
    }

    // Add static properties to the constructor function, if supplied.
    if (staticProps) {
      _.extend(child, staticProps);
    }

    // Correctly set child's `prototype.constructor`.
    child.prototype.constructor = child;

    // Set a convenience property in case the parent's prototype is
    // needed later.
    child.__super__ = parent.prototype;

    return child;
  };

  /**
   * Call this method first to set up authentication tokens for AV.
   * This method is for AV's own private use.
   * @param {String} applicationId Your AV Application ID.
   * @param {String} applicationKey Your AV Application Key
   */
   const initialize = (applicationId, applicationKey, masterKey) => {
    if (AV.applicationId !== undefined &&
        applicationId !== AV.applicationId  &&
        applicationKey !== AV.applicationKey &&
        masterKey !== AV.masterKey) {
      console.warn('LeanCloud SDK is already initialized, please don\'t reinitialize it.');
    }
    AV.applicationId = applicationId;
    AV.applicationKey = applicationKey;
    AV.masterKey = masterKey;
    AV._useMasterKey = false;
  };

  /**
    * Call this method first to set up your authentication tokens for AV.
    * You can get your app keys from the LeanCloud dashboard on http://leancloud.cn .
    * @function AV.init
    * @param args initialize options.
    * @param args.appId application id
    * @param args.appKey application key
    * @param args.masterKey application master key
  */

  AV.init = (...args) => {
    switch (args.length) {
      case 1:
        const options = args[0];
        if (typeof options === 'object') {
          if (!AVConfig.isNode && options.masterKey) {
            throw new Error('AV.init(): Master Key is only used in Node.js.');
          }
          initialize(options.appId, options.appKey, options.masterKey);

          // 服务器地区选项，默认为中国大陆
          switch (options.region) {
            case 'us':
              AVConfig.region = 'us';
            break;
          }
        } else {
          throw new Error('AV.init(): Parameter is not correct.');<commit_msg>utils 中提出 setRegion 方法<commit_after>/**
 * 每位工程师都有保持代码优雅的义务
 * Each engineer has a duty to keep the code elegant
**/

'use strict';

const _ = require('underscore');

module.exports = function(AV) {

  // 挂载一些配置
  let AVConfig = AV._config;

  _.extend(AVConfig, {

    // 服务器请求的节点 host
    apiHost : {
      cn: 'https://api.leancloud.cn',
      us: 'https://us-api.leancloud.cn'
    },

    // 服务器节点地区，默认中国大陆
    region: 'cn'
  });

  /**
   * Contains all AV API classes and functions.
   * @name AV
   * @namespace
   *
   * Contains all AV API classes and functions.
   */

  // Check whether we are running in Node.js.
  if (typeof(process) !== 'undefined' && process.versions && process.versions.node) {
    AVConfig.isNode = true;
  }

  // Helpers
  // -------

  // Shared empty constructor function to aid in prototype-chain creation.
  var EmptyConstructor = function() {};


  // Helper function to correctly set up the prototype chain, for subclasses.
  // Similar to `goog.inherits`, but uses a hash of prototype properties and
  // class properties to be extended.
  var inherits = function(parent, protoProps, staticProps) {
    var child;

    // The constructor function for the new subclass is either defined by you
    // (the "constructor" property in your `extend` definition), or defaulted
    // by us to simply call the parent's constructor.
    if (protoProps && protoProps.hasOwnProperty('constructor')) {
      child = protoProps.constructor;
    } else {
      /** @ignore */
      child = function(){ parent.apply(this, arguments); };
    }

    // Inherit class (static) properties from parent.
    _.extend(child, parent);

    // Set the prototype chain to inherit from `parent`, without calling
    // `parent`'s constructor function.
    EmptyConstructor.prototype = parent.prototype;
    child.prototype = new EmptyConstructor();

    // Add prototype properties (instance properties) to the subclass,
    // if supplied.
    if (protoProps) {
      _.extend(child.prototype, protoProps);
    }

    // Add static properties to the constructor function, if supplied.
    if (staticProps) {
      _.extend(child, staticProps);
    }

    // Correctly set child's `prototype.constructor`.
    child.prototype.constructor = child;

    // Set a convenience property in case the parent's prototype is
    // needed later.
    child.__super__ = parent.prototype;

    return child;
  };

  /**
   * Call this method first to set up authentication tokens for AV.
   * This method is for AV's own private use.
   * @param {String} applicationId Your AV Application ID.
   * @param {String} applicationKey Your AV Application Key
   */
   const initialize = (applicationId, applicationKey, masterKey) => {
    if (AV.applicationId !== undefined &&
        applicationId !== AV.applicationId  &&
        applicationKey !== AV.applicationKey &&
        masterKey !== AV.masterKey) {
      console.warn('LeanCloud SDK is already initialized, please don\'t reinitialize it.');
    }
    AV.applicationId = applicationId;
    AV.applicationKey = applicationKey;
    AV.masterKey = masterKey;
    AV._useMasterKey = false;
  };

  const setRegion = (region) => {
    // 服务器地区选项，默认为中国大陆
    switch (region) {
      case 'cn':
        AVConfig.region = 'cn';
      break;
      case 'us':
        AVConfig.region = 'us';
      break;
    }
  };

  /**
    * Call this method first to set up your authentication tokens for AV.
    * You can get your app keys from the LeanCloud dashboard on http://leancloud.cn .
    * @function AV.init
    * @param args initialize options.
    * @param args.appId application id
    * @param args.appKey application key
    * @param args.masterKey application master key
  */

  AV.init = (...args) => {
    switch (args.length) {
      case 1:
        const options = args[0];
        if (typeof options === 'object') {
          if (!AVConfig.isNode && options.masterKey) {
            throw new Error('AV.init(): Master Key is only used in Node.js.');
          }
          initialize(options.appId, options.appKey, options.masterKey);
          setRegion(options.region);
        } else {
          throw new Error('AV.init(): Parameter is not correct.');
{'fraction_non_alphanumeric': 0.11507507507507507, 'fraction_numerical': 0.00048048048048048047, 'mean_word_length': 2.553563807084934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 4, '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': '7504882', 'n_tokens_mistral': 2421, 'n_tokens_neox': 2391, 'n_words': 767}