polyfill Mobile Safari's missing slice

This commit is contained in:
AJ ONeal 2015-10-23 03:13:27 -07:00
parent 952531809b
commit ea400ab670
1 changed files with 4 additions and 4 deletions

View File

@ -131,11 +131,11 @@ exports.base32ToBuffer = function(encoded) {
throw new Error('Invalid input - it is not base32 encoded string');
}
}
if (decoded.slice) {
if (decoded.slice) { // Array or TypedArray
return decoded.slice(0, plainPos);
} else {
// Mobile Safari's Uint8Array doesn't have slice
return Array.prototype.slice.call(decoded, 0, plainPos);
} else { // Mobile Safari TypedArray
return new Uint8Array(Array.prototype.slice.call(decoded, 0, plainPos));
}
};