{"size": 713, "ext": "js", "max_stars_repo_path": "modal/node_modules/@webassemblyjs/utf8/src/encoder.js", "max_stars_repo_name": "maze-runnar/modal-component", "max_stars_repo_stars_event_min_datetime": "2020-04-03T02:57:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T08:44:08.000Z", "max_issues_repo_path": "modal/node_modules/@webassemblyjs/utf8/src/encoder.js", "max_issues_repo_name": "maze-runnar/modal-component", "max_issues_repo_issues_event_min_datetime": "2020-07-13T08:47:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-13T02:57:52.000Z", "max_forks_repo_path": "modal/node_modules/@webassemblyjs/utf8/src/encoder.js", "max_forks_repo_name": "maze-runnar/modal-component", "max_forks_repo_forks_event_min_datetime": "2020-09-24T23:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-31T13:24:30.000Z"}
{"max_stars_count": 943, "max_issues_count": 553, "max_forks_count": 481, "avg_line_length": 15.8444444444, "max_line_length": 69, "alphanum_fraction": 0.4600280505}
function con(n) {
  return 0x80 | (n & 0x3f);
}

export function encode(str) {
  const arr = str.split("").map(x => x.charCodeAt(0));
  return _encode(arr);
}

function _encode(arr) {
  if (arr.length === 0) {
    return [];
  }

  const [n, ...ns] = arr;

  if (n < 0) {
    throw new Error("utf8");
  }

  if (n < 0x80) {
    return [n, ..._encode(ns)];
  }

  if (n < 0x800) {
    return [0xc0 | (n >>> 6), con(n), ..._encode(ns)];
  }

  if (n < 0x10000) {
    return [0xe0 | (n >>> 12), con(n >>> 6), con(n), ..._encode(ns)];
  }

  if (n < 0x110000) {
    return [
      0xf0 | (n >>> 18),
      con(n >>> 12),
      con(n >>> 6),
      con(n),
      ..._encode(ns)
    ];
  }

  throw new Error("utf8");
}
