npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

base64-string

v1.1.3

Published

Encode or decode base64 strings - including cli

Downloads

20,429

Readme

base64-string

Install

$ npm install --save base64-string

CLI

CLI Options

base64-string:
  Options:
    in:     specifies a file for base64 encoding
    input:  specifies the string to process
    out:    specifies a file to write into
    decode  specifies the the process is to decode
    encode  specifies the process is to encode (default)
    sniff   specifies the process it to sniff if the 'in' 
            or 'input:' is to be tested is it may have 
            been url base64 encoded

    eol     specifies if an end of line should be appended
            to the the return output (stdOut).
            if eol is absent no end of line will be appended.
            The end of line is os specific.

    url     specifies if the process should base64 url encode

Notes:
  The order of parameter does not matter.

  If 'out:' is omitted result ares sent to stdOut

  When writing to a file 'eol' is not needed.
  It is the same result if you include 'eol'.

  'eol' is useful when using a terminal window.

  When writing files any directories needed will be automatically created.
  If a file exist it WILL be overwritten.

See RFC-4648 for more information on base64 url encoding.

CLI Examples

base64-string input:"hello world" // aGVsbG8gd29ybGQ=

base64-string input:"hello world" encode // aGVsbG8gd29ybGQ=

// returns and end of line based on the current os
base64-string input:"hello world" eol // aGVsbG8gd29ybGQ=\n

base64-string decode input:"aGVsbG8gd29ybGQ=" // hello world

// will write hello world into a file
base64-string decode input:"aGVsbG8gd29ybGQ=" out:"./where/hello.txt"

// base64 encodes file myfile.txt and saves to file enc.txt
base64-string encode in:"./myfile.txt" out:"./tmp/enc.txt"

// base64 decodes file b64.txt and saves to file decoded.txt
base64-string decode in:"./b64.txt" out:"./tmp/decoded.txt"

// base64 url encodes myfile.txt and outputs to stdOut
base64-string url in:"./myfile.txt"

// returs a true if text file is detected as url base64 encoded
base64-string sniff in:"./tmp/enc.txt"

Usage

base64.urlEncode()

Encode text to base64url, as per RFC-4648. The result is a URL-safe base64url encoded UTF-8 string.

TypeScript:

import { Base64 } from 'base64-string';
// other code
const enc = new Base64();
const b64 = enc.urlEncode('some url data');

JavaScript:

var Base64 = require('base64-string').Base64;
// other code
var enc = new Base64();
var b64 = enc.urlEncode('some url data');

base64.decode()

Decode base64 and base64url encoded text, as per RFC-4648. Input data is assumed to be a base64 or base64url encoded UTF-8 string.

TypeScript:

import { Base64 } from 'base64-string';
// other code
const enc = new Base64();
const b64 = enc.decode('aGVsbG8gd29ybGQ='); // hello world

JavaScript:

var Base64 = require('base64-string').Base64;
// other code
var enc = new Base64();
var b64 = enc.decode('aGVsbG8gd29ybGQ='); // hello world

base64.encode()

Encode text to base64, as per RFC-4648. The result is a base64 encoded UTF-8 string.

TypeScript:

import { Base64 } from 'base64-string';
// other code
const enc = new Base64();
const b64 = enc.encode('hello world'); // aGVsbG8gd29ybGQ=

JavaScript:

var Base64 = require('base64-string').Base64;
// other code
var enc = new Base64();
var b64 = enc.encode('hello world'); // aGVsbG8gd29ybGQ=

base64.urlSniff()

Check whether specified base64 string contains base64url specific characters.
Return true if specified string is base64url encoded, false otherwise.

TypeScript:

import { Base64 } from 'base64-string';
// other code
const enc = new Base64();
const b64 = enc.urlSniff(someStringVar); // returns a boolean

JavaScript:

var Base64 = require('base64-string').Base64;
// other code
var enc = new Base64();
var isUrlBase64 = enc.urlSniff(someStringVar); // returns a boolean