rainge
Version:
Generate accurate date ranges for copyrights
14 lines (10 loc) • 396 B
JavaScript
;
module.exports = function (input) {
const inputType = typeof input;
// validate arguments
if (inputType !== 'string' && inputType !== 'number') {
throw new TypeError(`Expected a string, got ${typeof input}`);
}
const currentYear = (new Date()).getFullYear().toString();
return input.toString() === currentYear ? `${currentYear}` : `${input} - ${currentYear}`;
};