{"size": 3067, "ext": "js", "max_stars_repo_path": "src/components/Blockly/generator/text.js", "max_stars_repo_name": "section77/React-Ardublockly", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/Blockly/generator/text.js", "max_issues_repo_name": "section77/React-Ardublockly", "max_issues_repo_issues_event_min_datetime": "2020-09-17T13:26:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T07:58:29.000Z", "max_forks_repo_path": "src/components/Blockly/generator/text.js", "max_forks_repo_name": "section77/React-Ardublockly", "max_forks_repo_forks_event_min_datetime": "2021-02-03T17:41:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T20:21:21.000Z"}
{"max_stars_count": null, "max_issues_count": 64, "max_forks_count": 3, "avg_line_length": 30.9797979798, "max_line_length": 77, "alphanum_fraction": 0.6322138898}
import * as Blockly from "blockly/core";

/**
 * Code generator for a literal String (X).
 * Arduino code: loop { "X" }
 * @param {!Blockly.Block} block Block to generate the code from.
 * @return {array} Completed code with order of operation.
 */
Blockly.Arduino["text"] = function (block) {
  var code = Blockly.Arduino.quote_(block.getFieldValue("TEXT"));
  return [code, Blockly.Arduino.ORDER_ATOMIC];
};

/**
 * Code generator for a String concatenation (X...Y). This string can be made
 * up of any number of elements of any type.
 * This block uses a mutator.
 * String construction info: http://arduino.cc/en/Reference/StringConstructor
 * Arduino code: loop { "String(X)" + ... + "String(Y)" }
 * @param {!Blockly.Block} block Block to generate the code from.
 * @return {array} Completed code with order of operation.
 */
Blockly.Arduino["text_join"] = function (block) {
  var code;
  if (block.itemCount_ === 0) {
    return ['""', Blockly.Arduino.ORDER_ATOMIC];
  } else if (block.itemCount_ === 1) {
    var argument0 =
      Blockly.Arduino.valueToCode(
        block,
        "ADD0",
        Blockly.Arduino.ORDER_UNARY_POSTFIX
      ) || '""';
    code = "String(" + argument0 + ")";
    return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX];
  } else {
    var argument;
    code = [];
    for (var n = 0; n < block.itemCount_; n++) {
      argument = Blockly.Arduino.valueToCode(
        block,
        "ADD" + n,
        Blockly.Arduino.ORDER_NONE
      );
      if (argument === "") {
        code[n] = '""';
      } else {
        code[n] = "String(" + argument + ")";
      }
    }
    code = code.join(" + ");
    return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX];
  }
};

/**
 * Code generator for appending text (Y) to a variable in place (X).
 * String constructor info: http://arduino.cc/en/Reference/StringConstructor
 * Arduino code: loop { X += String(Y) }
 * @param {!Blockly.Block} block Block to generate the code from.
 * @return {string} Completed code.
 */
Blockly.Arduino["text_append"] = function (block) {
  // Append to a variable in place.
  var varName = Blockly.Arduino.nameDB_.getName(
    block.getFieldValue("VAR"),
    Blockly.Variables.NAME_TYPE
  );
  var argument0 = Blockly.Arduino.valueToCode(
    block,
    "TEXT",
    Blockly.Arduino.ORDER_UNARY_POSTFIX
  );
  if (argument0 === "") {
    argument0 = '""';
  } else {
    argument0 = "String(" + argument0 + ")";
  }
  return varName + " += " + argument0 + ";\n";
};

/**
 * Code generator to get the length of a string (X).
 * String length info: http://arduino.cc/en/Reference/StringLength
 * Arduino code: loop { String(X).length() }
 * @param {!Blockly.Block} block Block to generate the code from.
 * @return {array} Completed code with order of operation.
 */
Blockly.Arduino["text_length"] = function (block) {
  var argument0 =
    Blockly.Arduino.valueToCode(
      block,
      "VALUE",
      Blockly.Arduino.ORDER_UNARY_POSTFIX
    ) || '""';
  var code = "String(" + argument0 + ").length()";
  return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX];
};
