Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pvtsutils

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pvtsutils - npm Package Compare versions

Comparing version 1.0.11 to 1.0.12

59

build/index.es.js

@@ -5,2 +5,32 @@ /**

class BufferSourceConverter {
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) {
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
return new Uint8Array(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
}
static isBufferSource(data) {
return this.isArrayBufferView(data)
|| data instanceof ArrayBuffer;
}
static isArrayBufferView(data) {
return ArrayBuffer.isView(data)
|| (data && data.buffer instanceof ArrayBuffer);
}
}
function PrepareBuffer(buffer) {

@@ -10,3 +40,3 @@ if (typeof Buffer !== "undefined" && Buffer.isBuffer(buffer)) {

}
else if (ArrayBuffer.isView(buffer)) {
else if (BufferSourceConverter.isArrayBufferView(buffer)) {
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);

@@ -138,29 +168,2 @@ }

class BufferSourceConverter {
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) {
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
return new Uint8Array(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
}
static isBufferSource(data) {
return ArrayBuffer.isView(data)
|| data instanceof ArrayBuffer
|| (data && data.buffer instanceof ArrayBuffer);
}
}
function assign(target, ...sources) {

@@ -167,0 +170,0 @@ const res = arguments[0];

@@ -6,211 +6,214 @@ /**

(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 = {}));
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';
function PrepareBuffer(buffer) {
if (typeof Buffer !== "undefined" && Buffer.isBuffer(buffer)) {
return new Uint8Array(buffer);
}
else if (ArrayBuffer.isView(buffer)) {
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
}
else {
return new Uint8Array(buffer);
}
}
class Convert {
static ToString(buffer, enc = "utf8") {
const buf = PrepareBuffer(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);
default:
throw new Error(`Unknown type of encoding '${enc}'`);
}
}
static FromString(str, enc = "utf8") {
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);
default:
throw new Error(`Unknown type of encoding '${enc}'`);
}
}
static ToBase64(buffer) {
const buf = PrepareBuffer(buffer);
if (typeof btoa !== "undefined") {
const binary = this.ToString(buf, "binary");
return btoa(binary);
}
else {
return Buffer.from(buf).toString("base64");
}
}
static FromBase64(base64Text) {
base64Text = base64Text.replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").replace(/\s/g, "");
if (typeof atob !== "undefined") {
return this.FromBinary(atob(base64Text));
}
else {
return new Uint8Array(Buffer.from(base64Text, "base64")).buffer;
}
}
static FromBase64Url(base64url) {
return this.FromBase64(this.Base64Padding(base64url.replace(/\-/g, "+").replace(/\_/g, "/")));
}
static ToBase64Url(data) {
return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
}
static FromUtf8String(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 ToUtf8String(buffer) {
const buf = PrepareBuffer(buffer);
const encodedString = String.fromCharCode.apply(null, buf);
const decodedString = decodeURIComponent(escape(encodedString));
return decodedString;
}
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 = PrepareBuffer(buffer);
let resultString = "";
const len = buf.length;
for (let i = 0; i < len; i++) {
resultString = resultString + String.fromCharCode(buf[i]);
}
return resultString;
}
static ToHex(buffer) {
const buf = PrepareBuffer(buffer);
const splitter = "";
const res = [];
const len = buf.length;
for (let i = 0; i < len; i++) {
const char = buf[i].toString(16);
res.push(char.length === 1 ? "0" + char : char);
}
return res.join(splitter);
}
static FromHex(hexString) {
const res = new Uint8Array(hexString.length / 2);
for (let i = 0; i < hexString.length; i = i + 2) {
const c = hexString.slice(i, i + 2);
res[i / 2] = parseInt(c, 16);
}
return res.buffer;
}
static Base64Padding(base64) {
const padCount = 4 - (base64.length % 4);
if (padCount < 4) {
for (let i = 0; i < padCount; i++) {
base64 += "=";
}
}
return base64;
}
}
class BufferSourceConverter {
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) {
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
return new Uint8Array(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
}
static isBufferSource(data) {
return this.isArrayBufferView(data)
|| data instanceof ArrayBuffer;
}
static isArrayBufferView(data) {
return ArrayBuffer.isView(data)
|| (data && data.buffer instanceof ArrayBuffer);
}
}
class BufferSourceConverter {
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) {
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
return new Uint8Array(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
}
static isBufferSource(data) {
return ArrayBuffer.isView(data)
|| data instanceof ArrayBuffer
|| (data && data.buffer instanceof ArrayBuffer);
}
}
function PrepareBuffer(buffer) {
if (typeof Buffer !== "undefined" && Buffer.isBuffer(buffer)) {
return new Uint8Array(buffer);
}
else if (BufferSourceConverter.isArrayBufferView(buffer)) {
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
}
else {
return new Uint8Array(buffer);
}
}
class Convert {
static ToString(buffer, enc = "utf8") {
const buf = PrepareBuffer(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);
default:
throw new Error(`Unknown type of encoding '${enc}'`);
}
}
static FromString(str, enc = "utf8") {
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);
default:
throw new Error(`Unknown type of encoding '${enc}'`);
}
}
static ToBase64(buffer) {
const buf = PrepareBuffer(buffer);
if (typeof btoa !== "undefined") {
const binary = this.ToString(buf, "binary");
return btoa(binary);
}
else {
return Buffer.from(buf).toString("base64");
}
}
static FromBase64(base64Text) {
base64Text = base64Text.replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").replace(/\s/g, "");
if (typeof atob !== "undefined") {
return this.FromBinary(atob(base64Text));
}
else {
return new Uint8Array(Buffer.from(base64Text, "base64")).buffer;
}
}
static FromBase64Url(base64url) {
return this.FromBase64(this.Base64Padding(base64url.replace(/\-/g, "+").replace(/\_/g, "/")));
}
static ToBase64Url(data) {
return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
}
static FromUtf8String(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 ToUtf8String(buffer) {
const buf = PrepareBuffer(buffer);
const encodedString = String.fromCharCode.apply(null, buf);
const decodedString = decodeURIComponent(escape(encodedString));
return decodedString;
}
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 = PrepareBuffer(buffer);
let resultString = "";
const len = buf.length;
for (let i = 0; i < len; i++) {
resultString = resultString + String.fromCharCode(buf[i]);
}
return resultString;
}
static ToHex(buffer) {
const buf = PrepareBuffer(buffer);
const splitter = "";
const res = [];
const len = buf.length;
for (let i = 0; i < len; i++) {
const char = buf[i].toString(16);
res.push(char.length === 1 ? "0" + char : char);
}
return res.join(splitter);
}
static FromHex(hexString) {
const res = new Uint8Array(hexString.length / 2);
for (let i = 0; i < hexString.length; i = i + 2) {
const c = hexString.slice(i, i + 2);
res[i / 2] = parseInt(c, 16);
}
return res.buffer;
}
static Base64Padding(base64) {
const padCount = 4 - (base64.length % 4);
if (padCount < 4) {
for (let i = 0; i < padCount; i++) {
base64 += "=";
}
}
return base64;
}
}
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;
}
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;
}
exports.BufferSourceConverter = BufferSourceConverter;
exports.Convert = Convert;
exports.assign = assign;
exports.combine = combine;
exports.isEqual = isEqual;
exports.BufferSourceConverter = BufferSourceConverter;
exports.Convert = Convert;
exports.assign = assign;
exports.combine = combine;
exports.isEqual = isEqual;
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
})));

@@ -5,2 +5,3 @@ export declare class BufferSourceConverter {

static isBufferSource(data: any): data is BufferSource;
static isArrayBufferView(data: any): data is ArrayBufferView;
}
{
"name": "pvtsutils",
"version": "1.0.11",
"version": "1.0.12",
"description": "pvtsutils is a set of common utility functions used in various Peculiar Ventures TypeScript based projects.",

@@ -52,15 +52,17 @@ "main": "build/index.js",

"homepage": "https://github.com/PeculiarVentures/pvtsutils#readme",
"dependencies": {},
"dependencies": {
"tslib": "^2.0.1"
},
"devDependencies": {
"@types/mocha": "^8.0.0",
"@types/node": "^12.12.18",
"@types/mocha": "^8.0.3",
"@types/node": "^12.12.55",
"coveralls": "^3.1.0",
"mocha": "^8.1.0",
"mocha": "^8.1.3",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"rollup": "^2.23.0",
"rollup-plugin-typescript2": "^0.27.1",
"ts-node": "^8.10.2",
"tslib": "^2.0.0",
"typescript": "^3.9.7"
"rollup": "^2.26.9",
"rollup-plugin-typescript2": "^0.27.2",
"ts-node": "^9.0.0",
"tslint": "^6.1.3",
"typescript": "^4.0.2"
},

@@ -67,0 +69,0 @@ "nyc": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc