@timberio/tools
Advanced tools
Comparing version 0.5.1 to 0.6.0
/** | ||
* Converts ASCII to Base64 | ||
* Converts a plain-text string to a base64 string | ||
* | ||
* @param ascii - ASCII string -> base64 | ||
* @param str - Plain text string -> base64 | ||
*/ | ||
export declare function atob(ascii: string): string; | ||
/** | ||
* Converts Base64 to ASCII | ||
* | ||
* @param base64 - Base64 -> ASCII | ||
*/ | ||
export declare function btoa(base64: string): string; | ||
export declare function base64Encode(str: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Converts ASCII to Base64 | ||
* Converts a plain-text string to a base64 string | ||
* | ||
* @param ascii - ASCII string -> base64 | ||
* @param str - Plain text string -> base64 | ||
*/ | ||
function atob(ascii) { | ||
return Buffer.from(ascii).toString("base64"); | ||
function base64Encode(str) { | ||
return Buffer.from(str).toString("base64"); | ||
} | ||
exports.atob = atob; | ||
/** | ||
* Converts Base64 to ASCII | ||
* | ||
* @param base64 - Base64 -> ASCII | ||
*/ | ||
function btoa(base64) { | ||
return Buffer.from(base64, "base64").toString("ascii"); | ||
} | ||
exports.btoa = btoa; | ||
exports.base64Encode = base64Encode; | ||
//# sourceMappingURL=encode.js.map |
@@ -8,9 +8,6 @@ "use strict"; | ||
const base64 = "aGVsbG8gd29ybGQ="; | ||
it("should convert ASCII to Base64", () => { | ||
expect(encode_1.atob(ascii)).toEqual(base64); | ||
it("should convert plain text to base64", () => { | ||
expect(encode_1.base64Encode(ascii)).toEqual(base64); | ||
}); | ||
it("should convert Base64 to ASCII", () => { | ||
expect(encode_1.btoa(base64)).toEqual(ascii); | ||
}); | ||
}); | ||
//# sourceMappingURL=encode.test.js.map |
import { IQueue } from "./types"; | ||
import Queue from "./queue"; | ||
import { atob, btoa } from "./encode"; | ||
import { base64Encode } from "./encode"; | ||
import makeThrottle from "./throttle"; | ||
export { IQueue, Queue, atob, btoa, makeThrottle }; | ||
export { IQueue, Queue, base64Encode, makeThrottle }; |
@@ -9,6 +9,5 @@ "use strict"; | ||
const encode_1 = require("./encode"); | ||
exports.atob = encode_1.atob; | ||
exports.btoa = encode_1.btoa; | ||
exports.base64Encode = encode_1.base64Encode; | ||
const throttle_1 = __importDefault(require("./throttle")); | ||
exports.makeThrottle = throttle_1.default; | ||
//# sourceMappingURL=index.js.map |
/** | ||
* Converts ASCII to Base64 | ||
* Converts a plain-text string to a base64 string | ||
* | ||
* @param ascii - ASCII string -> base64 | ||
* @param str - Plain text string -> base64 | ||
*/ | ||
export declare function atob(ascii: string): string; | ||
/** | ||
* Converts Base64 to ASCII | ||
* | ||
* @param base64 - Base64 -> ASCII | ||
*/ | ||
export declare function btoa(base64: string): string; | ||
export declare function base64Encode(str: string): string; |
/** | ||
* Converts ASCII to Base64 | ||
* Converts a plain-text string to a base64 string | ||
* | ||
* @param ascii - ASCII string -> base64 | ||
* @param str - Plain text string -> base64 | ||
*/ | ||
export function atob(ascii) { | ||
return Buffer.from(ascii).toString("base64"); | ||
export function base64Encode(str) { | ||
return Buffer.from(str).toString("base64"); | ||
} | ||
/** | ||
* Converts Base64 to ASCII | ||
* | ||
* @param base64 - Base64 -> ASCII | ||
*/ | ||
export function btoa(base64) { | ||
return Buffer.from(base64, "base64").toString("ascii"); | ||
} | ||
//# sourceMappingURL=encode.js.map |
@@ -1,2 +0,2 @@ | ||
import { atob, btoa } from "./encode"; | ||
import { base64Encode } from "./encode"; | ||
describe("Encode function tests", () => { | ||
@@ -6,9 +6,6 @@ // Fixtures | ||
const base64 = "aGVsbG8gd29ybGQ="; | ||
it("should convert ASCII to Base64", () => { | ||
expect(atob(ascii)).toEqual(base64); | ||
it("should convert plain text to base64", () => { | ||
expect(base64Encode(ascii)).toEqual(base64); | ||
}); | ||
it("should convert Base64 to ASCII", () => { | ||
expect(btoa(base64)).toEqual(ascii); | ||
}); | ||
}); | ||
//# sourceMappingURL=encode.test.js.map |
import { IQueue } from "./types"; | ||
import Queue from "./queue"; | ||
import { atob, btoa } from "./encode"; | ||
import { base64Encode } from "./encode"; | ||
import makeThrottle from "./throttle"; | ||
export { IQueue, Queue, atob, btoa, makeThrottle }; | ||
export { IQueue, Queue, base64Encode, makeThrottle }; |
import Queue from "./queue"; | ||
import { atob, btoa } from "./encode"; | ||
import { base64Encode } from "./encode"; | ||
import makeThrottle from "./throttle"; | ||
@@ -8,3 +8,3 @@ export { | ||
// Functions | ||
atob, btoa, makeThrottle }; | ||
base64Encode, makeThrottle }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@timberio/tools", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Javascript logging tools", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
@@ -77,7 +77,7 @@ # 🌲 Timber - Javascript tools | ||
### `atob(ascii: string): string` | ||
### `base64Encode(str: string): string` | ||
**Node.js only** | ||
Converts ASCII text to a Base64 encoded string. Equivalent to [window.atob()](https://www.w3schools.com/jsref/met_win_atob.asp) in the browser. | ||
Converts a plain-text string to a Base64 encoded string. Similar to [window.btoa()](https://www.w3schools.com/jsref/met_win_atob.asp) in the browser. | ||
@@ -93,15 +93,1 @@ Used by the logger to convert an API key to Timber's `user:password` basic auth. | ||
``` | ||
### `btoa(base64: string): string` | ||
**Node.js only** | ||
Converts Base64 encoded string to an ASCII string. Equivalent to [window.btoa()](https://www.w3schools.com/jsref/met_win_btoa.asp) in the browser. | ||
**Usage example:** | ||
```typescript | ||
import { btoa } from "@timberio/tools"; | ||
console.log(btoa("aGVsbG8gd29ybGQ=")); // <-- returns "hello world" | ||
``` |
@@ -1,2 +0,2 @@ | ||
import { atob, btoa } from "./encode"; | ||
import { base64Encode } from "./encode"; | ||
@@ -8,9 +8,5 @@ describe("Encode function tests", () => { | ||
it("should convert ASCII to Base64", () => { | ||
expect(atob(ascii)).toEqual(base64); | ||
it("should convert plain text to base64", () => { | ||
expect(base64Encode(ascii)).toEqual(base64); | ||
}); | ||
it("should convert Base64 to ASCII", () => { | ||
expect(btoa(base64)).toEqual(ascii); | ||
}); | ||
}); |
/** | ||
* Converts ASCII to Base64 | ||
* Converts a plain-text string to a base64 string | ||
* | ||
* @param ascii - ASCII string -> base64 | ||
* @param str - Plain text string -> base64 | ||
*/ | ||
export function atob(ascii: string): string { | ||
return Buffer.from(ascii).toString("base64"); | ||
export function base64Encode(str: string): string { | ||
return Buffer.from(str).toString("base64"); | ||
} | ||
/** | ||
* Converts Base64 to ASCII | ||
* | ||
* @param base64 - Base64 -> ASCII | ||
*/ | ||
export function btoa(base64: string): string { | ||
return Buffer.from(base64, "base64").toString("ascii"); | ||
} |
import { IQueue } from "./types"; | ||
import Queue from "./queue"; | ||
import { atob, btoa } from "./encode"; | ||
import { base64Encode } from "./encode"; | ||
import makeThrottle from "./throttle"; | ||
@@ -12,5 +12,4 @@ | ||
// Functions | ||
atob, | ||
btoa, | ||
base64Encode, | ||
makeThrottle | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
53513
993
92