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-utils

v1.0.4

Published

Provides functionalities related to Base64

Downloads

79

Readme

Base64 Utils

Utility module to perform various operations on a base64 string, has features to convert image to base64 string.

Release Notes

  • Added support for conversion of images to base64 string.

Installation

 $ npm install base64-utils 

Usage

const base64Utils = require("base64-utils");
//or
import * as base64Utils from "base64-utils"

API

isValidBase64

Checks if the base64 string is valid.

base64Utils.isValidBase64("SGVsbG8gV29ybGQ"); //returns false

base64Utils.isValidBase64("SGVsbG8gV29ybGQ="); //returns true

getMimeType

Tries to read mimetype of a base64 string, returns mimetype if found, otherwise returns a empty string.

base64Utils.getMimeTypeBySignature("data:image/png;base64,iUgAAAAUAAAAF=="); //returns "image/png"

base64Utils.getMimeTypeBySignature("SGVsbG8gV29ybGQ="); //returns ""

To get MimeType by reading string, and seeing string pattern, this is currently only available for pdf, png, jpg and gif.

base64Utils.getMimeType("iUgAAAAUAAAAF=="); //returns "image/png"

base64Utils.getMimeType("SGVsbG8gV29ybGQ="); //returns ""

Conversion Methods from Base64

To Convert Base64 String to different data formats

//Convert Base64 to Buffer
base64Utils.base64ToBuffer("SGVsbG8gV29ybGQ="); 
//Convert Base64 to UTF8
base64Utils.base64ToUtf8("SGVsbG8gV29ybGQ=");
//Convert Base64 to Hex
base64Utils.base64ToHex("SGVsbG8gV29ybGQ="); 
//Convert Base64 to Binary
base64Utils.base64ToBinary("SGVsbG8gV29ybGQ=");   

Conversion Methods To Base64

To Convert different formats to base64 String

//Convert Base64 to Buffer
base64Utils.bufferToBase64(Buffer); 

Convert Image To Base64

To convert image to base64 encoded string

//Convert image to base64 asynchronously 
base64Utils.imageToBase64(imagePath).then(data => console.log(data));

//Convert image to base64 synchronously 
base64Utils.imageToBase64Sync(imagePath);