src/js/extensions/chart/chart.js
function parseCode2ChartOption(optionCode) {
  const reservedKeys = ['type', 'url'];
  let options = {};
  if (util.isUndefined(optionCode)) {
    return options;
  }

  const optionLines = optionCode.split(REGEX_LINE_ENDING);
  optionLines.forEach(line => {
    let [keyString, ...values] = line.split(OPTION_DELIMITER);
    let value = values.join(OPTION_DELIMITER);
    keyString = keyString.trim();
    if (value.length === 0) {
      return;
    }

    try {
      value = JSON.parse(value.trim());
    } catch (e) {
      value = value.trim();
    }

    // parse keys
    let [...keys] = keyString.split('.');
    let topKey = keys[0];
    if (util.inArray(topKey, reservedKeys) >= 0) {
      // reserved keys for chart plugin option
      keys.unshift('editorChart');
    } else if (keys.length === 1) {
      // short names for `chart`
      keys.unshift('chart');
    } else if (topKey === 'x' || topKey === 'y') {
      // short-handed keys
      keys[0] = `${topKey}Axis`;
    }

    let option = options;
    for (let i = 0; i < keys.length; i += 1) {
      let key = keys[i];
      option[key] = option[key] || (keys.length - 1 === i ? value : {});
      option = option[key];
    }
  });

  return options;
}
function parseCode2ChartOption(optionCode) {
  const reservedKeys = ['type', 'url'];
  let options = {};
  if (util.isUndefined(optionCode)) {
    return options;
  }

  const optionLines = optionCode.split(REGEX_LINE_ENDING);
  optionLines.forEach(line => {
    let [keyString, ...values] = line.split(OPTION_DELIMITER);
    let value = values.join(OPTION_DELIMITER);
    keyString = keyString.trim();
    if (value.length === 0) {
      return;
    }

    try {
      value = JSON.parse(value.trim());
    } catch (e) {
      value = value.trim();
    }

    // parse keys
    let [...keys] = keyString.split('.');
    let topKey = keys[0];
    if (util.inArray(topKey, reservedKeys) >= 0) {
      // reserved keys for chart plugin option
      keys.unshift('editorChart');
    } else if (keys.length === 1) {
      // short names for `chart`
      keys.unshift('chart');
    } else if (topKey === 'x' || topKey === 'y') {
      // short-handed keys
      keys[0] = `${topKey}Axis`;
    }

    let option = options;
    for (let i = 0; i < keys.length; i += 1) {
      let key = keys[i];
      option[key] = option[key] || (keys.length - 1 === i ? value : {});
      option = option[key];
    }
  });

  return options;
}
function parseCode2ChartOption ( optionCode ) { const reservedKeys = [ 'type' , 'url' ] ; let options = { } ; if ( util . isUndefined ( optionCode ) ) { return options ; } const optionLines = optionCode . split ( REGEX_LINE_ENDING ) ; optionLines . forEach ( line => { let [ keyString , ... values ] = line . split ( OPTION_DELIMITER ) ; let value = values . join ( OPTION_DELIMITER ) ; keyString = keyString . trim ( ) ; if ( value . length === 0 ) { return ; } try { value = JSON . parse ( value . trim ( ) ) ; } catch ( e ) { value = value . trim ( ) ; } // parse keys let [ ... keys ] = keyString . split ( '.' ) ; let topKey = keys [ 0 ] ; if ( util . inArray ( topKey , reservedKeys ) >= 0 ) { // reserved keys for chart plugin option keys . unshift ( 'editorChart' ) ; } else if ( keys . length === 1 ) { // short names for `chart` keys . unshift ( 'chart' ) ; } else if ( topKey === 'x' || topKey === 'y' ) { // short-handed keys keys [ 0 ] = ` ${ topKey } ` ; } let option = options ; for ( let i = 0 ; i < keys . length ; i += 1 ) { let key = keys [ i ] ; option [ key ] = option [ key ] || ( keys . length - 1 === i ? value : { } ) ; option = option [ key ] ; } } ) ; return options ; }
parse option code
@param {string} optionCode - option code
@returns {Object} - tui.chart option string
@see https://nhn.github.io/tui.chart/latest/tui.chart.html
@ignore
parse option code