New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

durational

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

durational - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.jshintrc

34

lib/index.js

@@ -8,4 +8,4 @@ var FORMAT_REGEXP = /^PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$/;

exports.fromSeconds = function(seconds){
if(typeof seconds !== "number"){
throw new TypeError("Argument `seconds` must be a number");
if(typeof seconds !== 'number'){
throw new TypeError('Argument `seconds` must be a number');
}

@@ -20,4 +20,4 @@

seconds: fullSeconds
}
}
};
};

@@ -29,5 +29,5 @@ exports.fromString = function(string){

var matches = string.match(FORMAT_REGEXP)
var matches = string.match(FORMAT_REGEXP);
if(matches === null || (matches[1] === undefined && matches[2] === undefined && matches[3] === undefined)){
throw new Error('Could not parse "' + string + '" as a duration.')
throw new Error('Could not parse "' + string + '" as a duration.');
}

@@ -39,4 +39,4 @@

seconds: matchToInteger(matches[3])
}
}
};
};

@@ -48,12 +48,12 @@ exports.toString = function(duration) {

var result = "PT";
var result = 'PT';
if(duration.hours > 0){
result += duration.hours + "H";
result += duration.hours + 'H';
}
if(duration.minutes > 0){
result += duration.minutes + "M";
result += duration.minutes + 'M';
}
if(duration.seconds > 0){
result += duration.seconds + "S";
result += duration.seconds + 'S';
}

@@ -67,1 +67,11 @@

};
exports.toSeconds = function(stringOrDuration) {
var duration = stringOrDuration;
if(typeof stringOrDuration === 'string') {
duration = exports.fromString(stringOrDuration);
}
return duration.hours * 3600 + duration.minutes * 60 + duration.seconds;
};
{
"name": "durational",
"version": "1.0.0",
"version": "1.1.0",
"description": "Small library for dealing with Durations",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/miksago/durational",

@@ -26,7 +26,7 @@ var Lab = require('lab');

expect(function(){
durational.fromSeconds(15650)
durational.fromSeconds(15650);
}).to.not.throw();
expect(function(){
durational.fromSeconds("15650")
durational.fromSeconds('15650');
}).to.throw();

@@ -113,3 +113,3 @@

expect(function() {
durational.fromString(string)
durational.fromString(string);
}).to.throw();

@@ -132,7 +132,25 @@ });

it('should convert from a number', function(done) {
expect(durational.toString(4220)).to.equal('PT1H10M20S')
expect(durational.toString(4220)).to.equal('PT1H10M20S');
done();
});
})
})
});
describe('toSeconds', function() {
it('should convert from string', function(done) {
expect(durational.toSeconds('PT1H10M20S')).to.equal(4220);
done();
});
it('should convert from a duration object', function(done) {
expect(durational.toSeconds({
hours: 1,
minutes: 10,
seconds: 21
})).to.equal(4221);
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc