@aecworks/base64-url-safe
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

base64-url-safe

A utility to encode and decode the string using BASE64 standard, and it supports urlsafe and no-padding options also.

How to Use

Import

this lib is packaged in the umd style. So you can just use the import or require in node environment directive to import it as a Module.

import { Base64UrlSafe } from '@aecworks/base64-url-safe';

Encode a string

test('basic test for base64 encoding', () => {
    const origin = 'urn:bimbox.file:6iNy2mA8nI/6iPzuBtMvY?version=1';
    const base64Encoded = Base64UrlSafe.encode(origin, false);
    expect(base64Encoded).toBe('dXJuOmJpbWJveC5maWxlOjZpTnkybUE4bkkvNmlQenVCdE12WT92ZXJzaW9uPTE=');

    const base64UrlSafeEncoded = Base64UrlSafe.encode(origin, true);
    expect(base64UrlSafeEncoded).toBe('dXJuOmJpbWJveC5maWxlOjZpTnkybUE4bkkvNmlQenVCdE12WT92ZXJzaW9uPTE');
});

Decode a string

test('basic test for base64 decoding', () => {
    const originUrlSafe = 'dXJuOmJpbWJveC5maWxlOjZpTnkybUE4bkkvNmlQenVCdE12WT92ZXJzaW9uPTE';
    let base64Decoded = Base64UrlSafe.decode(originUrlSafe, true);
    expect(base64Decoded).toBe('urn:bimbox.file:6iNy2mA8nI/6iPzuBtMvY?version=1');

    const origin = 'dXJuOmJpbWJveC5maWxlOjZpTnkybUE4bkkvNmlQenVCdE12WT92ZXJzaW9uPTE=';
    base64Decoded = Base64UrlSafe.decode(origin, false);
    expect(base64Decoded).toBe('urn:bimbox.file:6iNy2mA8nI/6iPzuBtMvY?version=1');
});

How to Develop

  • tslint: npm run lint
  • test: npm run test
  • build: npm run build

How to publish

  • set registry: npm config set registry https://registry.npmjs.org
  • login: npm login
  • publish: npm publish

Readme

Keywords

Package Sidebar

Install

npm i @aecworks/base64-url-safe

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

15.9 kB

Total Files

7

Last publish

Collaborators

  • chris_zp
  • aecworks.adn
  • wushanggao
  • wbjqiqi
  • xuyuanjie
  • hanlijun