0.1.6 • Published 12 months ago

bytes-and-bits-converter v0.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

Note: I am not a software developer. This project was made solely and exclusively for personal learning purposes. I would greatly appreciate it if you could send me criticisms, tips, suggestions, and any other comments that may help me to evolve.

A library to convert magnitudes

Examples:

  • Bits to Bytes
  • Bytes to Bits
  • Handle and convert different unit types: Binary (Kibi, Mebi, etc) and Decimal (Kilo, Mega, etc)

Description:

The chosen approach in this library is to convert the input value to bits, regardless of the system (Binary or Decimal), magnitude (Mega, Mebi, Giga, Tebi, etc.), or type (Bytes or Bits) it came in, and then convert the raw bit value to the final unit selected by the user.

How to use:

Back-end implementation:

Install the library from NPM:

npm i bytes-and-bits-converter

For Node.js, import the library as follows:

const calculator = require('calculator')

Inside the demo folder, YOUR-NODE-CODE.js provide a simple example of how to use the library on the back-end.

If you're using node type as ES Modules, you'll need to comment all "require" and "module.exports" from the .js files, and uncomment the "import" and "export" lines.

Front-end implementation:

Install the library from NPM:

npm i bytes-and-bits-converter

Copy the /src folder and script.js file from /node_modules to your working directory.

In order to work on a browser, you'll need to make some changes in these files:

./script.js
./src/calculator.js
./src/help.js
./unitReferences.js

All you need to do is comment the lines using "require" or "module.exports" and uncomment the lines using "import" and "export", like this example on calculator.js:

import { unitReferences } from './unitReferences.js'
// const unitReferences = require('./unitReferences')
...
export {calculator}
// module.exports = calculator

If you want to use this project inside your .js file, import the library as follows:

import { calculator } from "./script.js"

If you want to use this project right through your HTML file, import the library at the end of the <body> tag, as follows:

<body>
...your html code...
<script src="./script.js" type="module"></script
</body>

Inside the demo folder, index.html and YOUR-FRONTEND-CODE.js provides an example of how to use the libray on the front-end.

Changelog:

Last updates: ## 0.1.6 - 2023-05-18

Updating "type" from ES Modules to CommonJS.

Added:

  • On all .js files, added const xx = require('') and module.exports in order to work as CommonJS.
  • On all .js files, added commented import and export lines to facilitate any potential change on node type to ES Modules.

View complete history

0.1.6

12 months ago

0.1.4

1 year ago

0.1.5

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago