Comparing version 1.0.3 to 1.0.4
@@ -9,8 +9,5 @@ function PrepareBuffer(buffer) { | ||
} | ||
var Convert = (function () { | ||
function Convert() { | ||
} | ||
Convert.ToString = function (buffer, enc) { | ||
if (enc === void 0) { enc = "utf8"; } | ||
var buf = PrepareBuffer(buffer); | ||
class Convert { | ||
static ToString(buffer, enc = "utf8") { | ||
const buf = PrepareBuffer(buffer); | ||
switch (enc.toLowerCase()) { | ||
@@ -28,7 +25,6 @@ case "utf8": | ||
default: | ||
throw new Error("Unknown type of encoding '" + enc + "'"); | ||
throw new Error(`Unknown type of encoding '${enc}'`); | ||
} | ||
}; | ||
Convert.FromString = function (str, enc) { | ||
if (enc === void 0) { enc = "utf8"; } | ||
} | ||
static FromString(str, enc = "utf8") { | ||
switch (enc.toLowerCase()) { | ||
@@ -46,9 +42,9 @@ case "utf8": | ||
default: | ||
throw new Error("Unknown type of encoding '" + enc + "'"); | ||
throw new Error(`Unknown type of encoding '${enc}'`); | ||
} | ||
}; | ||
Convert.ToBase64 = function (buffer) { | ||
var buf = PrepareBuffer(buffer); | ||
} | ||
static ToBase64(buffer) { | ||
const buf = PrepareBuffer(buffer); | ||
if (typeof btoa !== "undefined") { | ||
var binary = this.ToString(buf, "binary"); | ||
const binary = this.ToString(buf, "binary"); | ||
return btoa(binary); | ||
@@ -59,4 +55,4 @@ } | ||
} | ||
}; | ||
Convert.FromBase64 = function (base64Text) { | ||
} | ||
static FromBase64(base64Text) { | ||
base64Text = base64Text.replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").replace(/\s/g, ""); | ||
@@ -69,63 +65,63 @@ if (typeof atob !== "undefined") { | ||
} | ||
}; | ||
Convert.FromBase64Url = function (base64url) { | ||
} | ||
static FromBase64Url(base64url) { | ||
return this.FromBase64(this.Base64Padding(base64url.replace(/\-/g, "+").replace(/\_/g, "/"))); | ||
}; | ||
Convert.ToBase64Url = function (data) { | ||
} | ||
static ToBase64Url(data) { | ||
return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, ""); | ||
}; | ||
Convert.FromUtf8String = function (text) { | ||
var s = unescape(encodeURIComponent(text)); | ||
var uintArray = new Uint8Array(s.length); | ||
for (var i = 0; i < s.length; i++) { | ||
} | ||
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; | ||
}; | ||
Convert.ToUtf8String = function (buffer) { | ||
var buf = PrepareBuffer(buffer); | ||
var encodedString = String.fromCharCode.apply(null, buf); | ||
var decodedString = decodeURIComponent(escape(encodedString)); | ||
} | ||
static ToUtf8String(buffer) { | ||
const buf = PrepareBuffer(buffer); | ||
const encodedString = String.fromCharCode.apply(null, buf); | ||
const decodedString = decodeURIComponent(escape(encodedString)); | ||
return decodedString; | ||
}; | ||
Convert.FromBinary = function (text) { | ||
var stringLength = text.length; | ||
var resultView = new Uint8Array(stringLength); | ||
for (var i = 0; i < stringLength; i++) { | ||
} | ||
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; | ||
}; | ||
Convert.ToBinary = function (buffer) { | ||
var buf = PrepareBuffer(buffer); | ||
var resultString = ""; | ||
var len = buf.length; | ||
for (var i = 0; i < len; i++) { | ||
} | ||
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; | ||
}; | ||
Convert.ToHex = function (buffer) { | ||
var buf = PrepareBuffer(buffer); | ||
var splitter = ""; | ||
var res = []; | ||
var len = buf.length; | ||
for (var i = 0; i < len; i++) { | ||
var char = buf[i].toString(16); | ||
} | ||
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); | ||
}; | ||
Convert.FromHex = function (hexString) { | ||
var res = new Uint8Array(hexString.length / 2); | ||
for (var i = 0; i < hexString.length; i = i + 2) { | ||
var c = hexString.slice(i, i + 2); | ||
} | ||
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; | ||
}; | ||
Convert.Base64Padding = function (base64) { | ||
var padCount = 4 - (base64.length % 4); | ||
} | ||
static Base64Padding(base64) { | ||
const padCount = 4 - (base64.length % 4); | ||
if (padCount < 4) { | ||
for (var i = 0; i < padCount; i++) { | ||
for (let i = 0; i < padCount; i++) { | ||
base64 += "="; | ||
@@ -135,15 +131,10 @@ } | ||
return base64; | ||
}; | ||
return Convert; | ||
}()); | ||
} | ||
} | ||
function assign(target) { | ||
var sources = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
sources[_i - 1] = arguments[_i]; | ||
} | ||
var res = arguments[0]; | ||
for (var i = 1; i < arguments.length; i++) { | ||
var obj = arguments[i]; | ||
for (var prop in obj) { | ||
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]; | ||
@@ -154,12 +145,8 @@ } | ||
} | ||
function combine() { | ||
var buf = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
buf[_i] = arguments[_i]; | ||
} | ||
var totalByteLength = buf.map(function (item) { return item.byteLength; }).reduce(function (prev, cur) { return prev + cur; }); | ||
var res = new Uint8Array(totalByteLength); | ||
var currentPos = 0; | ||
buf.map(function (item) { return new Uint8Array(item); }).forEach(function (arr) { | ||
for (var i = 0; i < arr.length; i++) { | ||
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 (let i = 0; i < arr.length; i++) { | ||
res[currentPos++] = arr[i]; | ||
@@ -177,5 +164,5 @@ } | ||
} | ||
var b1 = new Uint8Array(bytes1); | ||
var b2 = new Uint8Array(bytes2); | ||
for (var i = 0; i < bytes1.byteLength; i++) { | ||
const b1 = new Uint8Array(bytes1); | ||
const b2 = new Uint8Array(bytes2); | ||
for (let i = 0; i < bytes1.byteLength; i++) { | ||
if (b1[i] !== b2[i]) { | ||
@@ -182,0 +169,0 @@ return false; |
@@ -15,8 +15,5 @@ (function (global, factory) { | ||
} | ||
var Convert = (function () { | ||
function Convert() { | ||
} | ||
Convert.ToString = function (buffer, enc) { | ||
if (enc === void 0) { enc = "utf8"; } | ||
var buf = PrepareBuffer(buffer); | ||
class Convert { | ||
static ToString(buffer, enc = "utf8") { | ||
const buf = PrepareBuffer(buffer); | ||
switch (enc.toLowerCase()) { | ||
@@ -34,7 +31,6 @@ case "utf8": | ||
default: | ||
throw new Error("Unknown type of encoding '" + enc + "'"); | ||
throw new Error(`Unknown type of encoding '${enc}'`); | ||
} | ||
}; | ||
Convert.FromString = function (str, enc) { | ||
if (enc === void 0) { enc = "utf8"; } | ||
} | ||
static FromString(str, enc = "utf8") { | ||
switch (enc.toLowerCase()) { | ||
@@ -52,9 +48,9 @@ case "utf8": | ||
default: | ||
throw new Error("Unknown type of encoding '" + enc + "'"); | ||
throw new Error(`Unknown type of encoding '${enc}'`); | ||
} | ||
}; | ||
Convert.ToBase64 = function (buffer) { | ||
var buf = PrepareBuffer(buffer); | ||
} | ||
static ToBase64(buffer) { | ||
const buf = PrepareBuffer(buffer); | ||
if (typeof btoa !== "undefined") { | ||
var binary = this.ToString(buf, "binary"); | ||
const binary = this.ToString(buf, "binary"); | ||
return btoa(binary); | ||
@@ -65,4 +61,4 @@ } | ||
} | ||
}; | ||
Convert.FromBase64 = function (base64Text) { | ||
} | ||
static FromBase64(base64Text) { | ||
base64Text = base64Text.replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").replace(/\s/g, ""); | ||
@@ -75,63 +71,63 @@ if (typeof atob !== "undefined") { | ||
} | ||
}; | ||
Convert.FromBase64Url = function (base64url) { | ||
} | ||
static FromBase64Url(base64url) { | ||
return this.FromBase64(this.Base64Padding(base64url.replace(/\-/g, "+").replace(/\_/g, "/"))); | ||
}; | ||
Convert.ToBase64Url = function (data) { | ||
} | ||
static ToBase64Url(data) { | ||
return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, ""); | ||
}; | ||
Convert.FromUtf8String = function (text) { | ||
var s = unescape(encodeURIComponent(text)); | ||
var uintArray = new Uint8Array(s.length); | ||
for (var i = 0; i < s.length; i++) { | ||
} | ||
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; | ||
}; | ||
Convert.ToUtf8String = function (buffer) { | ||
var buf = PrepareBuffer(buffer); | ||
var encodedString = String.fromCharCode.apply(null, buf); | ||
var decodedString = decodeURIComponent(escape(encodedString)); | ||
} | ||
static ToUtf8String(buffer) { | ||
const buf = PrepareBuffer(buffer); | ||
const encodedString = String.fromCharCode.apply(null, buf); | ||
const decodedString = decodeURIComponent(escape(encodedString)); | ||
return decodedString; | ||
}; | ||
Convert.FromBinary = function (text) { | ||
var stringLength = text.length; | ||
var resultView = new Uint8Array(stringLength); | ||
for (var i = 0; i < stringLength; i++) { | ||
} | ||
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; | ||
}; | ||
Convert.ToBinary = function (buffer) { | ||
var buf = PrepareBuffer(buffer); | ||
var resultString = ""; | ||
var len = buf.length; | ||
for (var i = 0; i < len; i++) { | ||
} | ||
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; | ||
}; | ||
Convert.ToHex = function (buffer) { | ||
var buf = PrepareBuffer(buffer); | ||
var splitter = ""; | ||
var res = []; | ||
var len = buf.length; | ||
for (var i = 0; i < len; i++) { | ||
var char = buf[i].toString(16); | ||
} | ||
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); | ||
}; | ||
Convert.FromHex = function (hexString) { | ||
var res = new Uint8Array(hexString.length / 2); | ||
for (var i = 0; i < hexString.length; i = i + 2) { | ||
var c = hexString.slice(i, i + 2); | ||
} | ||
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; | ||
}; | ||
Convert.Base64Padding = function (base64) { | ||
var padCount = 4 - (base64.length % 4); | ||
} | ||
static Base64Padding(base64) { | ||
const padCount = 4 - (base64.length % 4); | ||
if (padCount < 4) { | ||
for (var i = 0; i < padCount; i++) { | ||
for (let i = 0; i < padCount; i++) { | ||
base64 += "="; | ||
@@ -141,15 +137,10 @@ } | ||
return base64; | ||
}; | ||
return Convert; | ||
}()); | ||
} | ||
} | ||
function assign(target) { | ||
var sources = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
sources[_i - 1] = arguments[_i]; | ||
} | ||
var res = arguments[0]; | ||
for (var i = 1; i < arguments.length; i++) { | ||
var obj = arguments[i]; | ||
for (var prop in obj) { | ||
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]; | ||
@@ -160,12 +151,8 @@ } | ||
} | ||
function combine() { | ||
var buf = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
buf[_i] = arguments[_i]; | ||
} | ||
var totalByteLength = buf.map(function (item) { return item.byteLength; }).reduce(function (prev, cur) { return prev + cur; }); | ||
var res = new Uint8Array(totalByteLength); | ||
var currentPos = 0; | ||
buf.map(function (item) { return new Uint8Array(item); }).forEach(function (arr) { | ||
for (var i = 0; i < arr.length; i++) { | ||
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 (let i = 0; i < arr.length; i++) { | ||
res[currentPos++] = arr[i]; | ||
@@ -183,5 +170,5 @@ } | ||
} | ||
var b1 = new Uint8Array(bytes1); | ||
var b2 = new Uint8Array(bytes2); | ||
for (var i = 0; i < bytes1.byteLength; i++) { | ||
const b1 = new Uint8Array(bytes1); | ||
const b2 = new Uint8Array(bytes2); | ||
for (let i = 0; i < bytes1.byteLength; i++) { | ||
if (b1[i] !== b2[i]) { | ||
@@ -188,0 +175,0 @@ return false; |
{ | ||
"name": "pvtsutils", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "pvtsutils is a set of common utility functions used in various Peculiar Ventures TypeScript based projects.", | ||
@@ -9,14 +9,8 @@ "main": "dist/pvtsutils.js", | ||
"scripts": { | ||
"test": "mocha test/**/*.js", | ||
"build": "npm run build:dist", | ||
"build:es5": "rollup -c", | ||
"build:map": "rollup -c -m", | ||
"build:es2015": "rollup -c rollup.config.es.js", | ||
"build:dist": "npm run build:es5 && npm run build:es2015", | ||
"prepublish": "npm run build", | ||
"prepare": "npm run build", | ||
"test": "mocha", | ||
"build": "rollup -c", | ||
"prepub": "npm run build", | ||
"pub": "npm version patch && npm publish && git push", | ||
"precoverage": "npm run build:map", | ||
"coverage": "nyc npm test", | ||
"precoveragehtml": "npm run coverage", | ||
"coveragehtml": "nyc report -r html", | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls" | ||
@@ -60,4 +54,21 @@ }, | ||
"rollup-plugin-typescript": "^1.0.0", | ||
"ts-node": "^8.0.2", | ||
"typescript": "^3.2.2" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts", | ||
".tsx" | ||
], | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"**/*.d.ts" | ||
], | ||
"reporter": [ | ||
"text-summary", | ||
"html" | ||
] | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
17730
8
6
362
1