Comparing version 1.2.2 to 1.3.0
@@ -1,15 +0,36 @@ | ||
/** | ||
* Copyright (c) 2020, Peculiar Ventures, All rights reserved. | ||
/*! | ||
* MIT License | ||
* | ||
* Copyright (c) 2017-2022 Peculiar Ventures, LLC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
const ARRAY_BUFFER_NAME = "[object ArrayBuffer]"; | ||
class BufferSourceConverter { | ||
static isArrayBuffer(data) { | ||
return Object.prototype.toString.call(data) === '[object ArrayBuffer]'; | ||
return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME; | ||
} | ||
static toArrayBuffer(data) { | ||
const buf = this.toUint8Array(data); | ||
if (buf.byteOffset || buf.length) { | ||
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length); | ||
if (this.isArrayBuffer(data)) { | ||
return data; | ||
} | ||
return buf.buffer; | ||
return this.toUint8Array(data).slice().buffer; | ||
} | ||
@@ -20,5 +41,2 @@ static toUint8Array(data) { | ||
static toView(data, type) { | ||
if (typeof Buffer !== "undefined" && typeof Buffer.isBuffer === "function" && Buffer.isBuffer(data)) { | ||
return new type(data.buffer, data.byteOffset, data.byteLength); | ||
} | ||
if (this.isArrayBuffer(data)) { | ||
@@ -25,0 +43,0 @@ return new type(data); |
@@ -1,340 +0,352 @@ | ||
/** | ||
* Copyright (c) 2020, Peculiar Ventures, All rights reserved. | ||
/*! | ||
* MIT License | ||
* | ||
* Copyright (c) 2017-2022 Peculiar Ventures, LLC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pvtsutils = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
'use strict'; | ||
class BufferSourceConverter { | ||
static isArrayBuffer(data) { | ||
return Object.prototype.toString.call(data) === '[object ArrayBuffer]'; | ||
} | ||
static toArrayBuffer(data) { | ||
const buf = this.toUint8Array(data); | ||
if (buf.byteOffset || buf.length) { | ||
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length); | ||
} | ||
return buf.buffer; | ||
} | ||
static toUint8Array(data) { | ||
return this.toView(data, Uint8Array); | ||
} | ||
static toView(data, type) { | ||
if (typeof Buffer !== "undefined" && typeof Buffer.isBuffer === "function" && Buffer.isBuffer(data)) { | ||
return new type(data.buffer, data.byteOffset, data.byteLength); | ||
} | ||
if (this.isArrayBuffer(data)) { | ||
return new type(data); | ||
} | ||
if (this.isArrayBufferView(data)) { | ||
return new type(data.buffer, data.byteOffset, data.byteLength); | ||
} | ||
throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'"); | ||
} | ||
static isBufferSource(data) { | ||
return this.isArrayBufferView(data) | ||
|| this.isArrayBuffer(data); | ||
} | ||
static isArrayBufferView(data) { | ||
return ArrayBuffer.isView(data) | ||
|| (data && this.isArrayBuffer(data.buffer)); | ||
} | ||
static isEqual(a, b) { | ||
const aView = BufferSourceConverter.toUint8Array(a); | ||
const bView = BufferSourceConverter.toUint8Array(b); | ||
if (aView.length !== bView.byteLength) { | ||
return false; | ||
} | ||
for (let i = 0; i < aView.length; i++) { | ||
if (aView[i] !== bView[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
class Utf8Converter { | ||
static fromString(text) { | ||
const s = unescape(encodeURIComponent(text)); | ||
const uintArray = new Uint8Array(s.length); | ||
for (let i = 0; i < s.length; i++) { | ||
uintArray[i] = s.charCodeAt(i); | ||
} | ||
return uintArray.buffer; | ||
} | ||
static toString(buffer) { | ||
const buf = BufferSourceConverter.toUint8Array(buffer); | ||
let encodedString = ""; | ||
for (let i = 0; i < buf.length; i++) { | ||
encodedString += String.fromCharCode(buf[i]); | ||
} | ||
const decodedString = decodeURIComponent(escape(encodedString)); | ||
return decodedString; | ||
} | ||
} | ||
class Utf16Converter { | ||
static toString(buffer, littleEndian = false) { | ||
const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer); | ||
const dataView = new DataView(arrayBuffer); | ||
let res = ""; | ||
for (let i = 0; i < arrayBuffer.byteLength; i += 2) { | ||
const code = dataView.getUint16(i, littleEndian); | ||
res += String.fromCharCode(code); | ||
} | ||
return res; | ||
} | ||
static fromString(text, littleEndian = false) { | ||
const res = new ArrayBuffer(text.length * 2); | ||
const dataView = new DataView(res); | ||
for (let i = 0; i < text.length; i++) { | ||
dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian); | ||
} | ||
return res; | ||
} | ||
} | ||
class Convert { | ||
static isHex(data) { | ||
return typeof data === "string" | ||
&& /^[a-z0-9]+$/i.test(data); | ||
} | ||
static isBase64(data) { | ||
return typeof data === "string" | ||
&& /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data); | ||
} | ||
static isBase64Url(data) { | ||
return typeof data === "string" | ||
&& /^[a-zA-Z0-9-_]+$/i.test(data); | ||
} | ||
static ToString(buffer, enc = "utf8") { | ||
const buf = BufferSourceConverter.toUint8Array(buffer); | ||
switch (enc.toLowerCase()) { | ||
case "utf8": | ||
return this.ToUtf8String(buf); | ||
case "binary": | ||
return this.ToBinary(buf); | ||
case "hex": | ||
return this.ToHex(buf); | ||
case "base64": | ||
return this.ToBase64(buf); | ||
case "base64url": | ||
return this.ToBase64Url(buf); | ||
case "utf16le": | ||
return Utf16Converter.toString(buf, true); | ||
case "utf16": | ||
case "utf16be": | ||
return Utf16Converter.toString(buf); | ||
default: | ||
throw new Error(`Unknown type of encoding '${enc}'`); | ||
} | ||
} | ||
static FromString(str, enc = "utf8") { | ||
if (!str) { | ||
return new ArrayBuffer(0); | ||
} | ||
switch (enc.toLowerCase()) { | ||
case "utf8": | ||
return this.FromUtf8String(str); | ||
case "binary": | ||
return this.FromBinary(str); | ||
case "hex": | ||
return this.FromHex(str); | ||
case "base64": | ||
return this.FromBase64(str); | ||
case "base64url": | ||
return this.FromBase64Url(str); | ||
case "utf16le": | ||
return Utf16Converter.fromString(str, true); | ||
case "utf16": | ||
case "utf16be": | ||
return Utf16Converter.fromString(str); | ||
default: | ||
throw new Error(`Unknown type of encoding '${enc}'`); | ||
} | ||
} | ||
static ToBase64(buffer) { | ||
const buf = BufferSourceConverter.toUint8Array(buffer); | ||
if (typeof btoa !== "undefined") { | ||
const binary = this.ToString(buf, "binary"); | ||
return btoa(binary); | ||
} | ||
else { | ||
return Buffer.from(buf).toString("base64"); | ||
} | ||
} | ||
static FromBase64(base64) { | ||
const formatted = this.formatString(base64); | ||
if (!formatted) { | ||
return new ArrayBuffer(0); | ||
} | ||
if (!Convert.isBase64(formatted)) { | ||
throw new TypeError("Argument 'base64Text' is not Base64 encoded"); | ||
} | ||
if (typeof atob !== "undefined") { | ||
return this.FromBinary(atob(formatted)); | ||
} | ||
else { | ||
return new Uint8Array(Buffer.from(formatted, "base64")).buffer; | ||
} | ||
} | ||
static FromBase64Url(base64url) { | ||
const formatted = this.formatString(base64url); | ||
if (!formatted) { | ||
return new ArrayBuffer(0); | ||
} | ||
if (!Convert.isBase64Url(formatted)) { | ||
throw new TypeError("Argument 'base64url' is not Base64Url encoded"); | ||
} | ||
return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/"))); | ||
} | ||
static ToBase64Url(data) { | ||
return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, ""); | ||
} | ||
static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) { | ||
switch (encoding) { | ||
case "ascii": | ||
return this.FromBinary(text); | ||
case "utf8": | ||
return Utf8Converter.fromString(text); | ||
case "utf16": | ||
case "utf16be": | ||
return Utf16Converter.fromString(text); | ||
case "utf16le": | ||
case "usc2": | ||
return Utf16Converter.fromString(text, true); | ||
default: | ||
throw new Error(`Unknown type of encoding '${encoding}'`); | ||
} | ||
} | ||
static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) { | ||
switch (encoding) { | ||
case "ascii": | ||
return this.ToBinary(buffer); | ||
case "utf8": | ||
return Utf8Converter.toString(buffer); | ||
case "utf16": | ||
case "utf16be": | ||
return Utf16Converter.toString(buffer); | ||
case "utf16le": | ||
case "usc2": | ||
return Utf16Converter.toString(buffer, true); | ||
default: | ||
throw new Error(`Unknown type of encoding '${encoding}'`); | ||
} | ||
} | ||
static FromBinary(text) { | ||
const stringLength = text.length; | ||
const resultView = new Uint8Array(stringLength); | ||
for (let i = 0; i < stringLength; i++) { | ||
resultView[i] = text.charCodeAt(i); | ||
} | ||
return resultView.buffer; | ||
} | ||
static ToBinary(buffer) { | ||
const buf = BufferSourceConverter.toUint8Array(buffer); | ||
let res = ""; | ||
for (let i = 0; i < buf.length; i++) { | ||
res += String.fromCharCode(buf[i]); | ||
} | ||
return res; | ||
} | ||
static ToHex(buffer) { | ||
const buf = BufferSourceConverter.toUint8Array(buffer); | ||
const splitter = ""; | ||
const res = []; | ||
const len = buf.length; | ||
for (let i = 0; i < len; i++) { | ||
const char = buf[i].toString(16).padStart(2, "0"); | ||
res.push(char); | ||
} | ||
return res.join(splitter); | ||
} | ||
static FromHex(hexString) { | ||
let formatted = this.formatString(hexString); | ||
if (!formatted) { | ||
return new ArrayBuffer(0); | ||
} | ||
if (!Convert.isHex(formatted)) { | ||
throw new TypeError("Argument 'hexString' is not HEX encoded"); | ||
} | ||
if (formatted.length % 2) { | ||
formatted = `0${formatted}`; | ||
} | ||
const res = new Uint8Array(formatted.length / 2); | ||
for (let i = 0; i < formatted.length; i = i + 2) { | ||
const c = formatted.slice(i, i + 2); | ||
res[i / 2] = parseInt(c, 16); | ||
} | ||
return res.buffer; | ||
} | ||
static ToUtf16String(buffer, littleEndian = false) { | ||
return Utf16Converter.toString(buffer, littleEndian); | ||
} | ||
static FromUtf16String(text, littleEndian = false) { | ||
return Utf16Converter.fromString(text, littleEndian); | ||
} | ||
static Base64Padding(base64) { | ||
const padCount = 4 - (base64.length % 4); | ||
if (padCount < 4) { | ||
for (let i = 0; i < padCount; i++) { | ||
base64 += "="; | ||
} | ||
} | ||
return base64; | ||
} | ||
static formatString(data) { | ||
return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || ""; | ||
} | ||
} | ||
Convert.DEFAULT_UTF8_ENCODING = "utf8"; | ||
const ARRAY_BUFFER_NAME = "[object ArrayBuffer]"; | ||
class BufferSourceConverter { | ||
static isArrayBuffer(data) { | ||
return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME; | ||
} | ||
static toArrayBuffer(data) { | ||
if (this.isArrayBuffer(data)) { | ||
return data; | ||
} | ||
return this.toUint8Array(data).slice().buffer; | ||
} | ||
static toUint8Array(data) { | ||
return this.toView(data, Uint8Array); | ||
} | ||
static toView(data, type) { | ||
if (this.isArrayBuffer(data)) { | ||
return new type(data); | ||
} | ||
if (this.isArrayBufferView(data)) { | ||
return new type(data.buffer, data.byteOffset, data.byteLength); | ||
} | ||
throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'"); | ||
} | ||
static isBufferSource(data) { | ||
return this.isArrayBufferView(data) | ||
|| this.isArrayBuffer(data); | ||
} | ||
static isArrayBufferView(data) { | ||
return ArrayBuffer.isView(data) | ||
|| (data && this.isArrayBuffer(data.buffer)); | ||
} | ||
static isEqual(a, b) { | ||
const aView = BufferSourceConverter.toUint8Array(a); | ||
const bView = BufferSourceConverter.toUint8Array(b); | ||
if (aView.length !== bView.byteLength) { | ||
return false; | ||
} | ||
for (let i = 0; i < aView.length; i++) { | ||
if (aView[i] !== bView[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
function assign(target, ...sources) { | ||
const res = arguments[0]; | ||
for (let i = 1; i < arguments.length; i++) { | ||
const obj = arguments[i]; | ||
for (const prop in obj) { | ||
res[prop] = obj[prop]; | ||
} | ||
} | ||
return res; | ||
} | ||
function combine(...buf) { | ||
const totalByteLength = buf.map((item) => item.byteLength).reduce((prev, cur) => prev + cur); | ||
const res = new Uint8Array(totalByteLength); | ||
let currentPos = 0; | ||
buf.map((item) => new Uint8Array(item)).forEach((arr) => { | ||
for (const item2 of arr) { | ||
res[currentPos++] = item2; | ||
} | ||
}); | ||
return res.buffer; | ||
} | ||
function isEqual(bytes1, bytes2) { | ||
if (!(bytes1 && bytes2)) { | ||
return false; | ||
} | ||
if (bytes1.byteLength !== bytes2.byteLength) { | ||
return false; | ||
} | ||
const b1 = new Uint8Array(bytes1); | ||
const b2 = new Uint8Array(bytes2); | ||
for (let i = 0; i < bytes1.byteLength; i++) { | ||
if (b1[i] !== b2[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
class Utf8Converter { | ||
static fromString(text) { | ||
const s = unescape(encodeURIComponent(text)); | ||
const uintArray = new Uint8Array(s.length); | ||
for (let i = 0; i < s.length; i++) { | ||
uintArray[i] = s.charCodeAt(i); | ||
} | ||
return uintArray.buffer; | ||
} | ||
static toString(buffer) { | ||
const buf = BufferSourceConverter.toUint8Array(buffer); | ||
let encodedString = ""; | ||
for (let i = 0; i < buf.length; i++) { | ||
encodedString += String.fromCharCode(buf[i]); | ||
} | ||
const decodedString = decodeURIComponent(escape(encodedString)); | ||
return decodedString; | ||
} | ||
} | ||
class Utf16Converter { | ||
static toString(buffer, littleEndian = false) { | ||
const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer); | ||
const dataView = new DataView(arrayBuffer); | ||
let res = ""; | ||
for (let i = 0; i < arrayBuffer.byteLength; i += 2) { | ||
const code = dataView.getUint16(i, littleEndian); | ||
res += String.fromCharCode(code); | ||
} | ||
return res; | ||
} | ||
static fromString(text, littleEndian = false) { | ||
const res = new ArrayBuffer(text.length * 2); | ||
const dataView = new DataView(res); | ||
for (let i = 0; i < text.length; i++) { | ||
dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian); | ||
} | ||
return res; | ||
} | ||
} | ||
class Convert { | ||
static isHex(data) { | ||
return typeof data === "string" | ||
&& /^[a-z0-9]+$/i.test(data); | ||
} | ||
static isBase64(data) { | ||
return typeof data === "string" | ||
&& /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data); | ||
} | ||
static isBase64Url(data) { | ||
return typeof data === "string" | ||
&& /^[a-zA-Z0-9-_]+$/i.test(data); | ||
} | ||
static ToString(buffer, enc = "utf8") { | ||
const buf = BufferSourceConverter.toUint8Array(buffer); | ||
switch (enc.toLowerCase()) { | ||
case "utf8": | ||
return this.ToUtf8String(buf); | ||
case "binary": | ||
return this.ToBinary(buf); | ||
case "hex": | ||
return this.ToHex(buf); | ||
case "base64": | ||
return this.ToBase64(buf); | ||
case "base64url": | ||
return this.ToBase64Url(buf); | ||
case "utf16le": | ||
return Utf16Converter.toString(buf, true); | ||
case "utf16": | ||
case "utf16be": | ||
return Utf16Converter.toString(buf); | ||
default: | ||
throw new Error(`Unknown type of encoding '${enc}'`); | ||
} | ||
} | ||
static FromString(str, enc = "utf8") { | ||
if (!str) { | ||
return new ArrayBuffer(0); | ||
} | ||
switch (enc.toLowerCase()) { | ||
case "utf8": | ||
return this.FromUtf8String(str); | ||
case "binary": | ||
return this.FromBinary(str); | ||
case "hex": | ||
return this.FromHex(str); | ||
case "base64": | ||
return this.FromBase64(str); | ||
case "base64url": | ||
return this.FromBase64Url(str); | ||
case "utf16le": | ||
return Utf16Converter.fromString(str, true); | ||
case "utf16": | ||
case "utf16be": | ||
return Utf16Converter.fromString(str); | ||
default: | ||
throw new Error(`Unknown type of encoding '${enc}'`); | ||
} | ||
} | ||
static ToBase64(buffer) { | ||
const buf = BufferSourceConverter.toUint8Array(buffer); | ||
if (typeof btoa !== "undefined") { | ||
const binary = this.ToString(buf, "binary"); | ||
return btoa(binary); | ||
} | ||
else { | ||
return Buffer.from(buf).toString("base64"); | ||
} | ||
} | ||
static FromBase64(base64) { | ||
const formatted = this.formatString(base64); | ||
if (!formatted) { | ||
return new ArrayBuffer(0); | ||
} | ||
if (!Convert.isBase64(formatted)) { | ||
throw new TypeError("Argument 'base64Text' is not Base64 encoded"); | ||
} | ||
if (typeof atob !== "undefined") { | ||
return this.FromBinary(atob(formatted)); | ||
} | ||
else { | ||
return new Uint8Array(Buffer.from(formatted, "base64")).buffer; | ||
} | ||
} | ||
static FromBase64Url(base64url) { | ||
const formatted = this.formatString(base64url); | ||
if (!formatted) { | ||
return new ArrayBuffer(0); | ||
} | ||
if (!Convert.isBase64Url(formatted)) { | ||
throw new TypeError("Argument 'base64url' is not Base64Url encoded"); | ||
} | ||
return this.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/"))); | ||
} | ||
static ToBase64Url(data) { | ||
return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, ""); | ||
} | ||
static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) { | ||
switch (encoding) { | ||
case "ascii": | ||
return this.FromBinary(text); | ||
case "utf8": | ||
return Utf8Converter.fromString(text); | ||
case "utf16": | ||
case "utf16be": | ||
return Utf16Converter.fromString(text); | ||
case "utf16le": | ||
case "usc2": | ||
return Utf16Converter.fromString(text, true); | ||
default: | ||
throw new Error(`Unknown type of encoding '${encoding}'`); | ||
} | ||
} | ||
static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) { | ||
switch (encoding) { | ||
case "ascii": | ||
return this.ToBinary(buffer); | ||
case "utf8": | ||
return Utf8Converter.toString(buffer); | ||
case "utf16": | ||
case "utf16be": | ||
return Utf16Converter.toString(buffer); | ||
case "utf16le": | ||
case "usc2": | ||
return Utf16Converter.toString(buffer, true); | ||
default: | ||
throw new Error(`Unknown type of encoding '${encoding}'`); | ||
} | ||
} | ||
static FromBinary(text) { | ||
const stringLength = text.length; | ||
const resultView = new Uint8Array(stringLength); | ||
for (let i = 0; i < stringLength; i++) { | ||
resultView[i] = text.charCodeAt(i); | ||
} | ||
return resultView.buffer; | ||
} | ||
static ToBinary(buffer) { | ||
const buf = BufferSourceConverter.toUint8Array(buffer); | ||
let res = ""; | ||
for (let i = 0; i < buf.length; i++) { | ||
res += String.fromCharCode(buf[i]); | ||
} | ||
return res; | ||
} | ||
static ToHex(buffer) { | ||
const buf = BufferSourceConverter.toUint8Array(buffer); | ||
const splitter = ""; | ||
const res = []; | ||
const len = buf.length; | ||
for (let i = 0; i < len; i++) { | ||
const char = buf[i].toString(16).padStart(2, "0"); | ||
res.push(char); | ||
} | ||
return res.join(splitter); | ||
} | ||
static FromHex(hexString) { | ||
let formatted = this.formatString(hexString); | ||
if (!formatted) { | ||
return new ArrayBuffer(0); | ||
} | ||
if (!Convert.isHex(formatted)) { | ||
throw new TypeError("Argument 'hexString' is not HEX encoded"); | ||
} | ||
if (formatted.length % 2) { | ||
formatted = `0${formatted}`; | ||
} | ||
const res = new Uint8Array(formatted.length / 2); | ||
for (let i = 0; i < formatted.length; i = i + 2) { | ||
const c = formatted.slice(i, i + 2); | ||
res[i / 2] = parseInt(c, 16); | ||
} | ||
return res.buffer; | ||
} | ||
static ToUtf16String(buffer, littleEndian = false) { | ||
return Utf16Converter.toString(buffer, littleEndian); | ||
} | ||
static FromUtf16String(text, littleEndian = false) { | ||
return Utf16Converter.fromString(text, littleEndian); | ||
} | ||
static Base64Padding(base64) { | ||
const padCount = 4 - (base64.length % 4); | ||
if (padCount < 4) { | ||
for (let i = 0; i < padCount; i++) { | ||
base64 += "="; | ||
} | ||
} | ||
return base64; | ||
} | ||
static formatString(data) { | ||
return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || ""; | ||
} | ||
} | ||
Convert.DEFAULT_UTF8_ENCODING = "utf8"; | ||
exports.BufferSourceConverter = BufferSourceConverter; | ||
exports.Convert = Convert; | ||
exports.assign = assign; | ||
exports.combine = combine; | ||
exports.isEqual = isEqual; | ||
function assign(target, ...sources) { | ||
const res = arguments[0]; | ||
for (let i = 1; i < arguments.length; i++) { | ||
const obj = arguments[i]; | ||
for (const prop in obj) { | ||
res[prop] = obj[prop]; | ||
} | ||
} | ||
return res; | ||
} | ||
function combine(...buf) { | ||
const totalByteLength = buf.map((item) => item.byteLength).reduce((prev, cur) => prev + cur); | ||
const res = new Uint8Array(totalByteLength); | ||
let currentPos = 0; | ||
buf.map((item) => new Uint8Array(item)).forEach((arr) => { | ||
for (const item2 of arr) { | ||
res[currentPos++] = item2; | ||
} | ||
}); | ||
return res.buffer; | ||
} | ||
function isEqual(bytes1, bytes2) { | ||
if (!(bytes1 && bytes2)) { | ||
return false; | ||
} | ||
if (bytes1.byteLength !== bytes2.byteLength) { | ||
return false; | ||
} | ||
const b1 = new Uint8Array(bytes1); | ||
const b2 = new Uint8Array(bytes2); | ||
for (let i = 0; i < bytes1.byteLength; i++) { | ||
if (b1[i] !== b2[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
exports.BufferSourceConverter = BufferSourceConverter; | ||
exports.Convert = Convert; | ||
exports.assign = assign; | ||
exports.combine = combine; | ||
exports.isEqual = isEqual; |
{ | ||
"name": "pvtsutils", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "pvtsutils is a set of common utility functions used in various Peculiar Ventures TypeScript based projects.", | ||
@@ -8,3 +8,3 @@ "main": "build/index.js", | ||
"browser": "build/index.js", | ||
"types": "build/types/index.d.ts", | ||
"types": "build/index.d.ts", | ||
"files": [ | ||
@@ -16,9 +16,6 @@ "build/**/*.{ts,js}", | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"test": "mocha", | ||
"build": "npm run build:module && npm run build:types", | ||
"clear": "rimraf build/*", | ||
"rebuild": "npm run clear && npm run build", | ||
"build:module": "rollup -c", | ||
"build:types": "tsc -p tsconfig.types.json", | ||
"build": "rollup -c", | ||
"lint": "tslint -p .", | ||
@@ -62,42 +59,18 @@ "lint:fix": "tslint --fix -p .", | ||
"dependencies": { | ||
"tslib": "^2.3.1" | ||
"tslib": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^14.17.19", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^17.0.31", | ||
"coveralls": "^3.1.1", | ||
"mocha": "^9.2.0", | ||
"mocha": "^10.0.0", | ||
"nyc": "^15.1.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.67.3", | ||
"rollup": "^2.71.1", | ||
"rollup-plugin-dts": "^4.2.1", | ||
"rollup-plugin-typescript2": "^0.31.2", | ||
"ts-node": "^10.5.0", | ||
"ts-node": "^10.7.0", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.5.5" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts", | ||
".tsx" | ||
], | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"**/*.d.ts" | ||
], | ||
"reporter": [ | ||
"text-summary", | ||
"html" | ||
] | ||
}, | ||
"mocha": { | ||
"require": "ts-node/register", | ||
"extension": [ | ||
"ts" | ||
], | ||
"watch-files": [ | ||
"test/**/*.ts" | ||
] | ||
"typescript": "^4.6.4" | ||
} | ||
} |
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) | ||
[![Coverage Status](https://coveralls.io/repos/github/PeculiarVentures/pvtsutils/badge.svg?branch=master)](https://coveralls.io/github/PeculiarVentures/pvtsutils?branch=master) | ||
[![CircleCI](https://circleci.com/gh/PeculiarVentures/pvtsutils.svg?style=svg)](https://circleci.com/gh/PeculiarVentures/pvtsutils) | ||
[![Test](https://github.com/PeculiarVentures/pvtsutils/actions/workflows/test.yml/badge.svg)](https://github.com/PeculiarVentures/pvtsutils/actions/workflows/test.yml) | ||
@@ -5,0 +5,0 @@ # pvtsutils |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35508
821
12
6
Updatedtslib@^2.4.0