quick tweaks to clamp.
This commit is contained in:
parent
4d31ce9d77
commit
a606c781a7
2 changed files with 18 additions and 18 deletions
|
@ -2,7 +2,7 @@ var ZEROS = '0000000000000000000';
|
||||||
var ZERO_OFFSET = '0'.charCodeAt(0);
|
var ZERO_OFFSET = '0'.charCodeAt(0);
|
||||||
var USTAR = 'ustar00';
|
var USTAR = 'ustar00';
|
||||||
|
|
||||||
function clamp(index, len, defaultValue) {
|
var clamp = function(index, len, defaultValue) {
|
||||||
if (typeof index !== 'number') return defaultValue;
|
if (typeof index !== 'number') return defaultValue;
|
||||||
index = ~~index; // Coerce to integer.
|
index = ~~index; // Coerce to integer.
|
||||||
if (index >= len) return len;
|
if (index >= len) return len;
|
||||||
|
@ -10,7 +10,7 @@ function clamp(index, len, defaultValue) {
|
||||||
index += len;
|
index += len;
|
||||||
if (index >= 0) return index;
|
if (index >= 0) return index;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
var toType = function(flag) {
|
var toType = function(flag) {
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ var fixtures = require('./fixtures');
|
||||||
var concat = require('concat-stream');
|
var concat = require('concat-stream');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
function clamp(index, len, defaultValue) {
|
var clamp = function(index, len, defaultValue) {
|
||||||
if (typeof index !== 'number') return defaultValue;
|
if (typeof index !== 'number') return defaultValue;
|
||||||
index = ~~index; // Coerce to integer.
|
index = ~~index; // Coerce to integer.
|
||||||
if (index >= len) return len;
|
if (index >= len) return len;
|
||||||
|
@ -12,7 +12,7 @@ function clamp(index, len, defaultValue) {
|
||||||
index += len;
|
index += len;
|
||||||
if (index >= 0) return index;
|
if (index >= 0) return index;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
test('one-file', function(t) {
|
test('one-file', function(t) {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
|
|
Loading…
Reference in a new issue