dont modify string prototype

This commit is contained in:
Michael Barrett 2016-01-15 15:51:48 +00:00
parent 090220d0db
commit 8099cf427b
2 changed files with 0 additions and 25 deletions

View File

@ -98,14 +98,3 @@ Timestring.prototype.parse = function parse(string, returnUnit) {
convert.call(this, totalSeconds, returnUnit) : convert.call(this, totalSeconds, returnUnit) :
totalSeconds; totalSeconds;
}; };
/**
* Parse a timestring
*
* @param {string} unit
* @param {Object} opts
* @return {string}
*/
String.prototype.parseTime = function parseTime(unit, opts) {
return (new Timestring(opts)).parse(this, unit);
};

14
test.js
View File

@ -46,18 +46,4 @@ describe('timestring', function() {
it('can parse a messy time string', function() { it('can parse a messy time string', function() {
expect((new timestring()).parse('5 D a YS 4 h 2 0 mI nS')).to.equal(447600); expect((new timestring()).parse('5 D a YS 4 h 2 0 mI nS')).to.equal(447600);
}); });
it('should expose a method on String.prototype that will parse the string as a timestring', function(){
var str = '1min';
// no arguments passed
expect(str.parseTime()).to.equal(60);
// units argument passed
expect(str.parseTime('m')).to.equal(1);
// units + options argument passed
str = '5h';
expect(str.parseTime('d', { hoursPerDay: 5 })).to.equal(1);
});
}); });