bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
22 lines (20 loc) • 535 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = toBase64;
/**
* encode a string or a buffer to base64
* @name toBase64
* @param {string|Buffer} val string or buffer to encode
* @returns {string} base64 encoded string
* @example
* ```js
* toBase64('foo bar') // => Zm9vIGJhcg==
* toBase64(Buffer.from('foo bar')) // => Zm9vIGJhcg==
* ```
*/
function toBase64(val) {
if (val instanceof Buffer) return val.toString('base64');
return Buffer.from(val).toString('base64');
}
;