@aecworks/base64-url-safe
v1.0.1
Published
A utility to encode and decode the string using BASE64 standard, and it supports `urlsafe` and `no-padding` options also.
Downloads
18
Readme
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