How to use base64-js - 10 common examples

To help you get started, we’ve selected a few base64-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / base64-js / base64-js-tests.ts View on Github external
import * as base64js from "base64-js";

base64js.byteLength(""); // $ExpectType number
base64js.toByteArray(""); // $ExpectType Uint8Array
base64js.fromByteArray(new Uint8Array(0)); // $ExpectType string
github HdrHistogram / HdrHistogramJS / src / encoding.spec.ts View on Github external
it("should decode and decompress reading a byte buffer", () => {
    // given
    const base64 = require("base64-js");
    const buffer = new ByteBuffer(
      base64.toByteArray(
        "HISTFAAAACB42pNpmSzMwMDAxAABMJqRQf4/GNh/gAgEMwEAkp4I6Q=="
      )
    );
    // when
    const histogram = AbstractHistogram.decodeFromCompressedByteBuffer(
      buffer,
      Int32Histogram,
      0
    );
    // then
    expect(histogram.getMean()).to.be.equal(42);
    expect(histogram.getTotalCount()).to.be.equal(1);
  });
github noironetworks / aci-containers / vendor / github.com / hashicorp / consul / ui-v2 / app / utils / atob.js View on Github external
export default function(str, encoding = 'utf-8') {
  // decode
  const bytes = base64js.toByteArray(str);
  return new TextDecoder(encoding).decode(bytes);
}
github keybase / client / shared / common-adapters / markdown / service-decoration.tsx View on Github external
const ServiceDecoration = (props: Props) => {
  // Parse JSON to get the type of the decoration
  let parsed: RPCChatTypes.UITextDecoration
  try {
    const json = Buffer.from(toByteArray(props.json)).toString()
    parsed = JSON.parse(json)
  } catch (e) {
    return null
  }
  if (parsed.typ === RPCChatTypes.UITextDecorationTyp.payment && props.message) {
    let paymentID: WalletTypes.PaymentID | undefined
    let error
    if (
      parsed.payment.result.resultTyp === RPCChatTypes.TextPaymentResultTyp.sent &&
      parsed.payment.result.sent
    ) {
      paymentID = WalletTypes.rpcPaymentIDToPaymentID(parsed.payment.result.sent)
    } else if (
      parsed.payment.result.resultTyp === RPCChatTypes.TextPaymentResultTyp.error &&
      parsed.payment.result.error
    ) {
github DefinitelyTyped / DefinitelyTyped / base64-js / base64-js-tests.ts View on Github external
import * as base64js from "base64-js";

const length: number = base64js.byteLength("");
const bytes: Uint8Array = base64js.toByteArray("");
const decoded: string = base64js.fromByteArray(new Uint8Array(0));
github manfredsteyer / angular-oauth2-oidc / src / oauth-service.ts View on Github external
checkAtHash(accessToken, idClaims) {
        if (!accessToken || !idClaims || !idClaims.at_hash ) return true;
        var tokenHash: Array = sha256(accessToken, { asBytes: true });
        var leftMostHalf = tokenHash.slice(0, (tokenHash.length/2) );
        var tokenHashBase64 = fromByteArray(leftMostHalf);
        var atHash = tokenHashBase64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
        var claimsAtHash = idClaims.at_hash.replace(/=/g, "");
        
        var atHash = tokenHashBase64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");

        if (atHash != claimsAtHash) {
            console.warn("exptected at_hash: " + atHash);    
            console.warn("actual at_hash: " + claimsAtHash);
        }
        
        
        return (atHash == claimsAtHash);
    }
github MiEcosystem / miot-plugin-sdk / projects / com.xiaomi.camera.demo / MainPage.js View on Github external
DeviceEventEmitter.addListener(kCommandReceiveCallBackName, ({ command, data }) => {
            console.log('reach serverCmd callback');
            if (command == MISSCommand.MISS_CMD_SPEAKER_START_RESP) {
                console.log(' receive start speaker');
                console.log('data:' + data);
                var ba = base64js.toByteArray(data);
                if (ba.length > 0) {
                    console.log('receive start speaker 0');
                    console.log(ba[0]);
                    if (Platform.OS === 'android') {
                        if (ba[0] == 48) {
                            console.log("start call in android");
                            this.refs.openGLViewRef.startAudioRecord();
                        }
                    } else {
                        if (ba[0] == 0) {
                            this.refs.openGLViewRef.startAudioRecord();
                        }
                    }
                }
            } else {
                console.log('receive command:' + command + ' data:' + JSON.stringify(data));
github tmikov / jscomp / runtime / js / modules / buffer / index.js View on Github external
function base64Slice (buf, start, end) {
  if (start === 0 && end === buf.length) {
    return base64.fromByteArray(buf)
  } else {
    return base64.fromByteArray(buf.slice(start, end))
  }
}
github SangLiang / PhaserHearthStone / dist / main.js View on Github external
function _base64Slice (buf, start, end) {
  if (start === 0 && end === buf.length) {
    return base64.fromByteArray(buf)
  } else {
    return base64.fromByteArray(buf.slice(start, end))
  }
}
github swipely / state-trooper / statetrooper.bundle.js View on Github external
function base64Slice (buf, start, end) {
  if (start === 0 && end === buf.length) {
    return base64.fromByteArray(buf)
  } else {
    return base64.fromByteArray(buf.slice(start, end))
  }
}

base64-js

Base64 encoding/decoding in pure JS

MIT
Latest version published 4 years ago

Package Health Score

74 / 100
Full package analysis