{"size": 1093, "ext": "js", "max_stars_repo_path": "src/helpers.js", "max_stars_repo_name": "nicer00ster/lofimedia", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/helpers.js", "max_issues_repo_name": "nicer00ster/lofimedia", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/helpers.js", "max_forks_repo_name": "nicer00ster/lofimedia", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.5405405405, "max_line_length": 103, "alphanum_fraction": 0.6230558097}
export const checkObject = object => Object.keys(object).length === 0 && object.constructor === Object;

export function pad(n, width, z = 0) {
  n += '';
  return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}

export const minutesAndSeconds = position => ([
  pad(Math.floor(position / 60), 2),
  pad(position % 60, 2),
]);

export const objToArray = obj => Array.from(Object.keys(obj), key => obj[key]);

export const filterObject = (obj, query) => {
  const arr = Array.from(Object.keys(obj), key => obj[key]);
  return new Promise((resolve, reject) => {
    if (query.length === 0) return resolve();
    const results = arr.filter(item => item.title.includes(query) || item.artist.includes(query));
    return resolve(results);
  })
    .catch(error => {
      reject(error);
    });
};

export const removeByKey = (obj, delKey) => Object.keys(obj)
  .filter(key => key !== delKey)
  .reduce((result, current) => {
    result[current] = obj[current];
    return result;
  }, {});

export const delay = ms => new Promise(resolve => {
  setTimeout(resolve, ms);
});
