Skip to content

Commit

Permalink
fix: const & let to var
Browse files Browse the repository at this point in the history
  • Loading branch information
风棋 committed Nov 11, 2020
1 parent 806f6c1 commit 83f04b0
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ exports.byteLength = byteLength
exports.toByteArray = toByteArray
exports.fromByteArray = fromByteArray

const lookup = []
const revLookup = []
const Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
var lookup = []
var revLookup = []
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array

const code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
for (let i = 0, len = code.length; i < len; ++i) {
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
for (var i = 0, len = code.length; i < len; ++i) {
lookup[i] = code[i]
revLookup[code.charCodeAt(i)] = i
}
Expand All @@ -20,18 +20,18 @@ revLookup['-'.charCodeAt(0)] = 62
revLookup['_'.charCodeAt(0)] = 63

function getLens (b64) {
const len = b64.length
var len = b64.length

if (len % 4 > 0) {
throw new Error('Invalid string. Length must be a multiple of 4')
}

// Trim off extra bytes after placeholder bytes are found
// See: https://github.com/beatgammit/base64-js/issues/42
let validLen = b64.indexOf('=')
var validLen = b64.indexOf('=')
if (validLen === -1) validLen = len

const placeHoldersLen = validLen === len
var placeHoldersLen = validLen === len
? 0
: 4 - (validLen % 4)

Expand All @@ -40,9 +40,9 @@ function getLens (b64) {

// base64 is 4/3 + up to two characters of the original data
function byteLength (b64) {
const lens = getLens(b64)
const validLen = lens[0]
const placeHoldersLen = lens[1]
var lens = getLens(b64)
var validLen = lens[0]
var placeHoldersLen = lens[1]
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
}

Expand All @@ -51,21 +51,21 @@ function _byteLength (b64, validLen, placeHoldersLen) {
}

function toByteArray (b64) {
let tmp
const lens = getLens(b64)
const validLen = lens[0]
const placeHoldersLen = lens[1]
var tmp
var lens = getLens(b64)
var validLen = lens[0]
var placeHoldersLen = lens[1]

const arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))

let curByte = 0
var curByte = 0

// if there are placeholders, only get up to the last complete 4 chars
const len = placeHoldersLen > 0
var len = placeHoldersLen > 0
? validLen - 4
: validLen

let i
var i
for (i = 0; i < len; i += 4) {
tmp =
(revLookup[b64.charCodeAt(i)] << 18) |
Expand Down Expand Up @@ -104,9 +104,9 @@ function tripletToBase64 (num) {
}

function encodeChunk (uint8, start, end) {
let tmp
const output = []
for (let i = start; i < end; i += 3) {
var tmp
var output = []
for (var i = start; i < end; i += 3) {
tmp =
((uint8[i] << 16) & 0xFF0000) +
((uint8[i + 1] << 8) & 0xFF00) +
Expand All @@ -117,14 +117,14 @@ function encodeChunk (uint8, start, end) {
}

function fromByteArray (uint8) {
let tmp
const len = uint8.length
const extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
const parts = []
const maxChunkLength = 16383 // must be multiple of 3
var tmp
var len = uint8.length
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
var parts = []
var maxChunkLength = 16383 // must be multiple of 3

// go through the array every three bytes, we'll deal with trailing stuff later
for (let i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
}

Expand Down

0 comments on commit 83f04b0

Please sign in to comment.