Comparing version 1.0.12 to 1.0.13
@@ -47,2 +47,14 @@ /** | ||
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") { | ||
@@ -92,2 +104,5 @@ const buf = PrepareBuffer(buffer); | ||
static FromBase64(base64Text) { | ||
if (!Convert.isBase64(base64Text)) { | ||
throw new TypeError("Argument 'base64Text' is not Base64 encoded"); | ||
} | ||
base64Text = base64Text.replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").replace(/\s/g, ""); | ||
@@ -102,2 +117,5 @@ if (typeof atob !== "undefined") { | ||
static FromBase64Url(base64url) { | ||
if (!Convert.isBase64Url(base64url)) { | ||
throw new TypeError("Argument 'base64url' is not Base64Url encoded"); | ||
} | ||
return this.FromBase64(this.Base64Padding(base64url.replace(/\-/g, "+").replace(/\_/g, "/"))); | ||
@@ -151,2 +169,8 @@ } | ||
static FromHex(hexString) { | ||
if (!Convert.isHex(hexString)) { | ||
throw new TypeError("Argument 'hexString' is not HEX encoded"); | ||
} | ||
if (hexString.length % 2) { | ||
hexString = `0${hexString}`; | ||
} | ||
const res = new Uint8Array(hexString.length / 2); | ||
@@ -153,0 +177,0 @@ for (let i = 0; i < hexString.length; i = i + 2) { |
@@ -53,2 +53,14 @@ /** | ||
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") { | ||
@@ -98,2 +110,5 @@ const buf = PrepareBuffer(buffer); | ||
static FromBase64(base64Text) { | ||
if (!Convert.isBase64(base64Text)) { | ||
throw new TypeError("Argument 'base64Text' is not Base64 encoded"); | ||
} | ||
base64Text = base64Text.replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").replace(/\s/g, ""); | ||
@@ -108,2 +123,5 @@ if (typeof atob !== "undefined") { | ||
static FromBase64Url(base64url) { | ||
if (!Convert.isBase64Url(base64url)) { | ||
throw new TypeError("Argument 'base64url' is not Base64Url encoded"); | ||
} | ||
return this.FromBase64(this.Base64Padding(base64url.replace(/\-/g, "+").replace(/\_/g, "/"))); | ||
@@ -157,2 +175,8 @@ } | ||
static FromHex(hexString) { | ||
if (!Convert.isHex(hexString)) { | ||
throw new TypeError("Argument 'hexString' is not HEX encoded"); | ||
} | ||
if (hexString.length % 2) { | ||
hexString = `0${hexString}`; | ||
} | ||
const res = new Uint8Array(hexString.length / 2); | ||
@@ -159,0 +183,0 @@ for (let i = 0; i < hexString.length; i = i + 2) { |
export declare type BufferEncoding = "utf8" | "binary" | "base64" | "base64url" | "hex" | string; | ||
export declare class Convert { | ||
static isHex(data: any): data is string; | ||
static isBase64(data: any): data is string; | ||
static isBase64Url(data: any): data is string; | ||
static ToString(buffer: BufferSource, enc?: BufferEncoding): string; | ||
@@ -4,0 +7,0 @@ static FromString(str: string, enc?: BufferEncoding): ArrayBuffer; |
{ | ||
"name": "pvtsutils", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "pvtsutils is a set of common utility functions used in various Peculiar Ventures TypeScript based projects.", | ||
"main": "build/index.js", | ||
"module": "build/index.es.js", | ||
"browser": "build/index.js", | ||
"types": "build/types/index.d.ts", | ||
"files": [ | ||
"build/**/*.{ts,js}", | ||
"README.md", | ||
"LICENSE" | ||
], | ||
"scripts": { | ||
@@ -57,3 +63,3 @@ "prepare": "npm run build", | ||
"@types/mocha": "^8.0.3", | ||
"@types/node": "^12.12.55", | ||
"@types/node": "^12.12.62", | ||
"coveralls": "^3.1.0", | ||
@@ -63,7 +69,7 @@ "mocha": "^8.1.3", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.26.9", | ||
"rollup-plugin-typescript2": "^0.27.2", | ||
"rollup": "^2.28.2", | ||
"rollup-plugin-typescript2": "^0.27.3", | ||
"ts-node": "^9.0.0", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.0.2" | ||
"typescript": "^4.0.3" | ||
}, | ||
@@ -70,0 +76,0 @@ "nyc": { |
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
23841
504