How to use the Base64 function from js-base64

Find comprehensive JavaScript js-base64.Base64 code examples handpicked from public code repositorys.

js-base64.Base64 is a JavaScript library that provides functions to encode and decode data in Base64 format.

114
115
116
117
118
119
120
121
122
123
    });
}
/* istanbul ignore next */
renderPdf(pdfBase64, renderFinished) {
    // @ts-ignore
    const loadingTask = (0, pdfjs_dist_1.getDocument)({ data: js_base64_1.Base64.atob(pdfBase64) });
    loadingTask.promise.then((pdf) => {
        // console.log('PDF loaded');
        this._totalPages = pdf.numPages;
        this._renderedPdf = pdf;
fork icon21
star icon129
watch icon0

+ 77 other calls in file

75
76
77
78
79
80
81
82
83
84
    });
}
/* istanbul ignore next */
renderPdf(pdfBase64, renderFinished) {
    // @ts-ignore
    const loadingTask = pdfjsLib.getDocument({ data: js_base64_1.Base64.atob(pdfBase64) });
    loadingTask.promise.then((pdf) => {
        // console.log('PDF loaded');
        this._totalPages = pdf.numPages;
        this._renderedPdf = pdf;
fork icon21
star icon126
watch icon4

+ 57 other calls in file

How does js-base64.Base64 work?

js-base64.Base64 is a class that provides methods for encoding and decoding strings using Base64 encoding. It provides several static methods that allow you to encode and decode strings, and also allows you to create an instance that can be used to encode or decode strings with specific options. The encoding uses a set of 64 characters to represent the binary data in ASCII format, resulting in a shorter representation of the data that is easier to transmit over networks or store in databases.

342
343
344
345
346
347
348
349
350
351
    value = _ref2[1];
  if (value == null) {
    return prev;
  }
  var encodedKey = useCustomEncoder ? customEncoder(key, value) : encodeURIComponent(key);
  var encodedValue = key.substr(-2) === '64' ? useCustomEncoder ? customEncoder(value, key) : jsBase64.Base64.encodeURI(value) : useCustomEncoder ? customEncoder(value, key) : encodeURIComponent(value);
  prev.push("".concat(encodedKey, "=").concat(encodedValue));
  return prev;
}, [])));
return "".concat(queryParams.length > 0 ? '?' : '').concat(queryParams.join('&'));
fork icon18
star icon117
watch icon13

+ 3 other calls in file

4411
4412
4413
4414
4415
4416
4417
4418
4419
4420

_class.prototype.addAnnotation = function addAnnotation() {
    var content = undefined;

    if (this.isInline()) {
        content = 'data:application/json;base64,' + _jsBase.Base64.encode(this.map.toString());
    } else if (typeof this.mapOpts.annotation === 'string') {
        content = this.mapOpts.annotation;
    } else {
        content = this.outputFile() + '.map';
fork icon0
star icon5
watch icon1

+ 2 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
const Base64 = require("js-base64").Base64;

const message = "Hello, world!";

// Encoding the message
const encodedMessage = Base64.encode(message);
console.log(encodedMessage); // "SGVsbG8sIHdvcmxkIQ=="

// Decoding the message
const decodedMessage = Base64.decode(encodedMessage);
console.log(decodedMessage); // "Hello, world!"

342
343
344
345
346
347
348
349
350
351
352
353
354
355




exports.formatFillString = formatFillString;


var encodeBase64 = function encodeBase64(str) {
  return _jsBase.Base64.encode(str);
};


exports.encodeBase64 = encodeBase64;

fork icon0
star icon1
watch icon0

59
60
61
62
63
64
65
66
67
68
var base64 = 'data:application/json;base64,';

if (this.startWith(text, uri)) {
    return decodeURIComponent(text.substr(uri.length));
} else if (this.startWith(text, base64)) {
    return _jsBase.Base64.decode(text.substr(base64.length));
} else {
    var encoding = text.match(/data:application\/json;([^,]+),/)[1];
    throw new Error('Unsupported source map encoding ' + encoding);
}
fork icon0
star icon0
watch icon1

161
162
163
164
165
166
167
168
169
170

_class.prototype.addAnnotation = function addAnnotation() {
    var content = undefined;

    if (this.isInline()) {
        content = 'data:application/json;base64,' + _jsBase64.Base64.encode(this.map.toString());
    } else if (typeof this.mapOpts.annotation === 'string') {
        content = this.mapOpts.annotation;
    } else {
        content = this.outputFile() + '.map';
fork icon0
star icon0
watch icon1

58
59
60
61
62
63
64
65
66
67
var uri = 'data:application/json,';

if (this.startWith(text, uri)) {
    return decodeURIComponent(text.substr(uri.length));
} else if (this.startWith(text, b64)) {
    return _jsBase64.Base64.decode(text.substr(b64.length));
} else if (this.startWith(text, utf64)) {
    return _jsBase64.Base64.decode(text.substr(utf64.length));
} else {
    var encoding = text.match(/data:application\/json;([^,]+),/)[1];
fork icon0
star icon0
watch icon1

+ 3 other calls in file