stubby
Version:
a lightweight server for stubbing external systems and endpoints
47 lines (34 loc) • 875 B
JavaScript
;
/* eslint-disable no-extend-native */
function noop () {}
Object.defineProperty(Number.prototype, 'times', {
configurable: true,
value: function (fn) {
let i;
if (fn == null) { fn = noop; }
if (this <= 0) { return this; }
for (i = 1; i <= this; i++) { fn(); }
return parseFloat(this);
}
});
Object.defineProperty(String.prototype, 'times', {
configurable: true,
value: function (num) {
let i;
let result = '';
const self = this;
if (num == null) { num = 1; }
if (num < 1) { return ''; }
for (i = 1; i <= num; i++) { result += self; }
return result;
}
});
module.exports = function (left, right) {
if (typeof left !== 'number') { return null; }
if (typeof right === 'function') {
return left.times(right);
}
if (typeof right === 'string') {
return right.times(left);
}
};