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

dpm-base

v0.3.4

Published

Convert numeric bases to and from binary, octal, decimal and hexadecimal

Downloads

5

Readme

Base Converter (dpm-base)

A simple JavaScript library for converting numeric bases. Comprised of modules binary, octal, decimal and hex - supporting functions for conversion of base-2, base-8, base-10 and base-16. Conversion logic written in JavaScript, with support for big number calculations via bignumber.js dependancy.

Limitations

  • Currently only support conversion of whole number values - no fractional values as of yet. Support for fractional conversion may be added in the future.

Installation

npm install dpm-base

API Documentation

https://recursive-redundancy.github.io/npm-dpm-base/

Usage

importing package in script

const base = require('dpm-base');

Conversions

Each module contains four basic conversion functions:

  • toBin(value) - for conversion from base to binary (base-2)
  • toOct(value) - for conversion from base to octal (base-8)
  • toDec(value)- for conversion from base to decimal (base-10)
  • toHex(value) - for conversion from base to hexadecimal (base-16)

Converted values return as String

These conversion functions return null if supplied value is invalid

Each module also supports converting from its base to the same base, which means it simply returns the same value supplied.

Additionally, each module has a function for validating number is valid base value

  • isValid(value)

Binary

Binary is valid

let isValid = base.binary.isValid(1001);

Binary to Binary

let result = base.binary.toBin(1001);

Binary to Octal

let result = base.binary.toOct(1001);

Binary to Decimal

let result = base.binary.toDec(1001);

Binary to Hexadecimal

let result = base.binary.toHex(1001);

Octal

Octal is valid

let isValid = base.octal.isValid(1001);

Octal to Binary

let result = base.octal.toBin(1001);

Octal to Octal

let result = base.octal.toOct(1001);

Octal to Decimal

let result = base.octal.toDec(1001);

Octal to Hexadecimal

let result = base.octal.toHex(1001);

Decimal

Decimal is valid

let isValid = base.decimal.isValid(1001);

Decimal to Binary

let result = base.decimal.toBin(1001);

Decimal to Octal

let result = base.decimal.toOct(1001);

Decimal to Decimal

let result = base.decimal.toDec(1001);

Decimal to Hexadecimal

let result = base.decimal.toHex(1001);

Hexadecimal

Hexadecimal is valid

let isValid = base.hex.isValid(1001);

Hexadecimal to Binary

let result = base.hex.toBin(1001);

Hexadecimal to Octal

let result = base.hex.toOct(1001);

Hexadecimal to Decimal

let result = base.hex.toDec(1001);

Hexadecimal to Hexadecimal

let result = base.hex.toHex(1001);

Hexadecimal alphanumeric digit to numeric

let result = HEX_ALPHA_TO_DIGIT['a']; // result = '10'

Hexadecimal numeric to alphanumeric digit

let result = HEX_ALPHA_TO_DIGIT['15']; // result = 'f' 

Dependencies

bignumber.js : A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic

License

MIT