Skip to content

Commit

Permalink
Fix TS definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed Mar 15, 2020
1 parent 7870134 commit 3eda5fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Convert {
throw new Error(`Unknown type of encoding '${enc}'`);
}
}
public static FromString(str: string, enc: BufferEncoding = "utf8") {
public static FromString(str: string, enc: BufferEncoding = "utf8") : ArrayBuffer {
switch (enc.toLowerCase()) {
case "utf8":
return this.FromUtf8String(str);
Expand All @@ -59,7 +59,7 @@ export class Convert {
}
}

public static FromBase64(base64Text: string) {
public static FromBase64(base64Text: string) : ArrayBuffer{
base64Text = base64Text.replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").replace(/\s/g, "");
if (typeof atob !== "undefined") {
return this.FromBinary(atob(base64Text));
Expand All @@ -68,15 +68,15 @@ export class Convert {
}
}

public static FromBase64Url(base64url: string) {
public static FromBase64Url(base64url: string) : ArrayBuffer {
return this.FromBase64(this.Base64Padding(base64url.replace(/\-/g, "+").replace(/\_/g, "/")));
}

public static ToBase64Url(data: BufferSource): string {
return this.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
}

public static FromUtf8String(text: string) {
public static FromUtf8String(text: string) : ArrayBuffer {
const s = unescape(encodeURIComponent(text));
const uintArray = new Uint8Array(s.length);
for (let i = 0; i < s.length; i++) {
Expand All @@ -92,7 +92,7 @@ export class Convert {
return decodedString;
}

public static FromBinary(text: string) {
public static FromBinary(text: string) : ArrayBuffer {
const stringLength = text.length;
const resultView = new Uint8Array(stringLength);
for (let i = 0; i < stringLength; i++) {
Expand Down Expand Up @@ -136,7 +136,7 @@ export class Convert {
*
* @memberOf Convert
*/
public static FromHex(hexString: string) {
public static FromHex(hexString: string) : ArrayBuffer {
const res = new Uint8Array(hexString.length / 2);
for (let i = 0; i < hexString.length; i = i + 2) {
const c = hexString.slice(i, i + 2);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ES2015",
"declaration": true,
"declarationDir": "build/types",
"emitDeclarationOnly": true,
Expand Down

0 comments on commit 3eda5fe

Please sign in to comment.