ziggurat.js
Version:
a tiny modular js library for templates and other shorthands
62 lines (48 loc) • 1.26 kB
JavaScript
// Generated by CoffeeScript 2.7.0
var create_math_function, fun, i, key, len, ref;
Number.prototype.nanos = function() {
return this.micros() / 1000;
};
Number.prototype.micros = function() {
return this.millis() / 1000;
};
Number.prototype.millis = function() {
return this.seconds() / 1000;
};
Number.prototype.seconds = function() {
return this;
};
Number.prototype.minutes = function() {
return this.seconds() * 60;
};
Number.prototype.hours = function() {
return this.minutes() * 60;
};
Number.prototype.days = function() {
return this.hours() * 24;
};
Number.prototype.months = function() {
return this.days() * 30.43684914;
};
Number.prototype.years = function() {
return this.months() * 12;
};
Number.prototype.ago = function() {
return new Date(Date.now() - this * 1000);
};
Number.prototype.fromnow = function() {
return new Date(Date.now() + this * 1000);
};
create_math_function = function(name) {
return function() {
return this(Math[name]);
};
};
ref = Object.getOwnPropertyNames(Math);
for (i = 0, len = ref.length; i < len; i++) {
key = ref[i];
fun = Math[key];
if (fun.length === 1 && typeof fun === "function") {
eval(`Number.prototype.${key} = function() {return Math.${key}(this)}`);
}
}