quick tweaks to clamp.

This commit is contained in:
Chris Talkington 2014-01-06 02:33:14 -06:00
parent 4d31ce9d77
commit a606c781a7
2 changed files with 18 additions and 18 deletions

View file

@ -2,15 +2,15 @@ var ZEROS = '0000000000000000000';
var ZERO_OFFSET = '0'.charCodeAt(0);
var USTAR = 'ustar00';
function clamp(index, len, defaultValue) {
if (typeof index !== 'number') return defaultValue;
index = ~~index; // Coerce to integer.
if (index >= len) return len;
if (index >= 0) return index;
index += len;
if (index >= 0) return index;
return 0;
}
var clamp = function(index, len, defaultValue) {
if (typeof index !== 'number') return defaultValue;
index = ~~index; // Coerce to integer.
if (index >= len) return len;
if (index >= 0) return index;
index += len;
if (index >= 0) return index;
return 0;
};
var toType = function(flag) {
switch (flag) {

View file

@ -4,15 +4,15 @@ var fixtures = require('./fixtures');
var concat = require('concat-stream');
var fs = require('fs');
function clamp(index, len, defaultValue) {
if (typeof index !== 'number') return defaultValue;
index = ~~index; // Coerce to integer.
if (index >= len) return len;
if (index >= 0) return index;
index += len;
if (index >= 0) return index;
return 0;
}
var clamp = function(index, len, defaultValue) {
if (typeof index !== 'number') return defaultValue;
index = ~~index; // Coerce to integer.
if (index >= len) return len;
if (index >= 0) return index;
index += len;
if (index >= 0) return index;
return 0;
};
test('one-file', function(t) {
t.plan(3);