Wondering what’s next for npm?Check out our public roadmap! »

    base64-string
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.2 • Public • Published

    «-(¯`v´¯)-« 【🇧​🇦​🇸​🇪​@-🇸​🇹​🇷​🇮​🇳​🇬​】 »-(¯`v´¯)-»
    Base64 string encode and decode including cli

    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

    Install

    npm i base64-string

    DownloadsWeekly Downloads

    7,865

    Version

    1.1.2

    License

    MIT

    Unpacked Size

    17.2 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar