检查用户输入的csv

时间:2018-12-23 13:27:40

标签: node.js csv express

我当前正在工作的项目是用户放置csv文件,并通过应用程序的后端检查标头的存在,标头是否存在不存在,但如果不存在则将添加可选标头(像#)。

现在我需要检查解析为json字符串的csv,并设计了正则表达式(Regex)像这样的/(')(.*)(')\w/g来处理字符串具有类似以下字符串的行为:“ str,abc”,city,0,alpha' 我需要检查'的存在,如果存在,请更改它*并转到字符串的末尾,最后将其重新显示为普通

我已经附加了已经完成的代码,但是目前无法正常工作,我正在寻找解决问题的建议

var canvas = document.getElementById('canvas'),
  ctx = canvas.getContext('2d'),
  ball = {
    radius: 10,
    speed: 2,
    direction: 1,
    x: 10,
    y: 20
  };

animationLoop();

document.getElementById('btn-speed-down').addEventListener('click', speedDown);
document.getElementById('btn-speed-up').addEventListener('click', speedUp);

function speedDown() {
  ball.speed = Math.max(-50, ball.speed - 1);
  document.getElementById('speed').textContent = ball.speed;
}

function speedUp() {
  ball.speed = Math.min(50, ball.speed + 1);
  document.getElementById('speed').textContent = ball.speed;
}

function animationLoop() {
  ball.x += ball.speed * ball.direction;
  if (ball.x >= canvas.width - ball.radius) {
    ball.x = canvas.width - ball.radius;
    ball.direction = -ball.direction;
  } else if(ball.x <= ball.radius){
    ball.x = ball.radius;
    ball.direction = -ball.direction;
  }
  renderCanvas();
  requestAnimationFrame(animationLoop);
}

function renderCanvas() {
  renderBackground();
  renderBall();
}

function renderBackground(){
  ctx.fillStyle = "#2e3033";
  ctx.fillRect(0, 0, canvas.width, canvas.height);
}

function renderBall() {
  ctx.beginPath();
  ctx.arc(ball.x, ball.y, ball.radius, 0, Math.PI * 2);
  ctx.fillStyle = "#0095DD";
  ctx.fill();
  ctx.closePath();
}

0 个答案:

没有答案