util.js 705 字节
Newer Older
J
Jason Park 已提交
1 2 3 4 5 6 7 8
const classes = (...arr) => arr.filter(v => v).join(' ');

const distance = (a, b) => {
  const dx = a.x - b.x;
  const dy = a.y - b.y;
  return Math.sqrt(dx * dx + dy * dy);
};

J
Jason Park 已提交
9 10
const extension = fileName => /(?:\.([^.]+))?$/.exec(fileName)[1];

J
Jason Park 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23
const refineGist = gist => {
  const gistId = gist.id;
  const titles = ['Scratch Paper', gist.description];
  delete gist.files['algorithm-visualizer'];
  const { login, avatar_url } = gist.owner;
  const files = Object.values(gist.files).map(file => ({
    name: file.filename,
    content: file.content,
    contributors: [{ login, avatar_url }],
  }));
  return { gistId, titles, files };
};

J
Jason Park 已提交
24 25 26
export {
  classes,
  distance,
J
Jason Park 已提交
27
  extension,
J
Jason Park 已提交
28
  refineGist,
J
Jason Park 已提交
29
};