pvutils
Advanced tools
Comparing version 1.0.2 to 1.0.4
@@ -19,4 +19,4 @@ { | ||
"name": "pvutils", | ||
"version": "1.0.2", | ||
"version": "1.0.4", | ||
"license": "MIT" | ||
} |
@@ -20,2 +20,5 @@ //************************************************************************************** | ||
{ | ||
if((parameters instanceof Object) === false) | ||
return defaultValue; | ||
if(name in parameters) | ||
@@ -30,7 +33,7 @@ return parameters[name]; | ||
* @param {ArrayBuffer} inputBuffer | ||
* @param {number} inputOffset | ||
* @param {number} inputLength | ||
* @param {number} [inputOffset=0] | ||
* @param {number} [inputLength=inputBuffer.byteLength] | ||
* @returns {string} | ||
*/ | ||
export function bufferToHexCodes(inputBuffer, inputOffset, inputLength) | ||
export function bufferToHexCodes(inputBuffer, inputOffset = 0, inputLength = inputBuffer.byteLength) | ||
{ | ||
@@ -398,6 +401,7 @@ let result = ""; | ||
* @param {string} input | ||
* @param {boolean} useUrlTemplate If "true" then output would be encoded using "base64url" | ||
* @param {boolean} [useUrlTemplate=false] If "true" then output would be encoded using "base64url" | ||
* @param {boolean} [cutTailZeros=false] If "true" then cut tailing zeroz from function result | ||
* @returns {string} | ||
*/ | ||
export function fromBase64(input, useUrlTemplate = false) | ||
export function fromBase64(input, useUrlTemplate = false, cutTailZeros = false) | ||
{ | ||
@@ -448,2 +452,20 @@ const template = (useUrlTemplate) ? base64UrlTemplate : base64Template; | ||
if(cutTailZeros) | ||
{ | ||
const outputLength = output.length; | ||
let nonZeroStart = (-1); | ||
for(let i = (outputLength - 1); i >= 0; i--) | ||
{ | ||
if(output.charCodeAt(i) !== 0) | ||
{ | ||
nonZeroStart = i; | ||
break; | ||
} | ||
} | ||
if(nonZeroStart !== (-1)) | ||
output = output.slice(0, nonZeroStart + 1); | ||
} | ||
return output; | ||
@@ -476,1 +498,18 @@ } | ||
//************************************************************************************** | ||
const log2 = Math.log(2); | ||
//************************************************************************************** | ||
/** | ||
* Get nearest to input length power of 2 | ||
* @param {number} length Current length of existing array | ||
* @returns {number} | ||
*/ | ||
export function nearestPowerOf2(length) | ||
{ | ||
const base = (Math.log(length) / log2); | ||
const floor = Math.floor(base); | ||
const round = Math.round(base); | ||
return ((floor === round) ? floor : round); | ||
} | ||
//************************************************************************************** |
14534
427