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

convertion

v0.0.2

Published

Librería simple para conversiones de bases numéricas.

Downloads

42

Readme

Convertion

Librería simple para conversiones de bases numéricas.


License: MIT


Contenido


Descripción

Convertion es una pequeña librería en fase de desarrollo para conversión entre bases numéricas. De momento solo cubre conversiones entre bases binario, octal, decimal y hexadecimal. A medida de lo posible intentaré aportar mayor cantidad de métodos a esta librería, con el fin de que tenga un amplio rango de conversiones


Instalación

Solo se necesita tener instalado node.js y npm

npm install convertion

🚀 Guia de uso

La manera mas simple de usar convertion es.

import { bin, num } from 'convertion';

const binary = num(10).convert().bin(); // returns '1010'

const hexa = bin('1010').convert().dec(); // returns 10

✋ ¿Te fijaste? A pesar de que el método num utiliza de convert el método bin para la conversión, bin > para hacer la conversión a decimal utiliza de convert el método dec.

Esto significa que los métodos que retorna convert no son los mismos handlers. Saber más


Handlers

Estos son los principales métodos de convertion. puedes visitar la documentación para conocer más.


Handler num

Este manejador recibe como parámetros solo expresiones numérica 123, 0b123, etc las cuales convertirá en una expresión decimal. Nos devuelve solo el método convert.

// Ejemplo
let num = num(10).convert().hex();
console.log(num);
// returns a (string)

let num = num(10).convert().bin();
console.log(num);
// returns 1010 (string)

Handler bin

Este manejador recibe como parámetros solo expresiones numéricas de tipo string y binario '0b1100', '110011', etc. El Handler bin devuelve los validadores:

  • isNumber(): que devuelve true en caso de ser un string numérico.
  • isBinary() que devuelve true si la expresión sigue un patrón binario.

También devuelve el método convert que desde bin nos devuelve tres métodos:

  • dec() Retorna la expresión convertida a decimal.
  • oct() Retorna la expresión convertida a octal.
  • hex() Retorna la expresión convertida a hexadecimal.
// Ejemplos

let number = bin('1010').isNumber();
console.log(number);
//returns true

let number = bin('Hello').isBinary();
console.log(number);
//returns false

let bin = bin('1010').convert().hex();
console.log(bin);
// returns a (string)

Saber mas


Handler oct

Este manejador recibe como parámetros solo expresiones numéricas de tipo string y octal '0o17', '752', etc. El Handler oct devuelve los validadores:

  • isNumber(): que devuelve true en caso de ser un string numérico.
  • isOctal() que devuelve true si la expresión sigue un patrón octal.

También devuelve el método convert que desde oct nos devuelve tres métodos:

  • dec() Retorna la expresión convertida a decimal.
  • bin() Retorna la expresión convertida a binario.
  • hex() Retorna la expresión convertida a hexadecimal.
// Ejemplos

let number = oct('77').isNumber();
console.log(number);
//returns true

let number = oct('Hello').isOctal();
console.log(number);
//returns false

let oct = oct('20').convert().hex();
console.log(oct);
// returns 10 (string)

Saber mas


Handler hex

Este manejador recibe como parámetros solo expresiones numéricas de tipo string y hexadecimal '0x1ff', '12ff', etc. El Handler hex devuelve los validadores:

  • isNumber(): que devuelve true en caso de ser un string numérico.
  • ishHex() que devuelve true si la expresión sigue un patrón hexadecimal.

También devuelve el método convert que desde hex nos devuelve tres métodos:

  • dec() Retorna la expresión convertida a decimal.
  • bin() Retorna la expresión convertida a binario.
  • oct() Retorna la expresión convertida a octal.
// Ejemplos

let number = hex('77').isNumber();
console.log(number);
//returns true

let number = hex('Hello').isHex();
console.log(number);
//returns false

let hex = hex('a').convert().dec();
console.log(hex);
// returns 10 (number)

Saber mas


Contribuciones

De momento me encuentro trabajando por mi cuenta en este proyecto. Si deseas contribuir con gusto ajustamos una metodología y comenzamos a colaborarnos en equipo. Déjame un pull request o un correo a [email protected]


Autor

  • Ángel Zamora

Licencia

MIT


Donaciones

Si deseas apoyarme para continuar desarrollando más librerías y mejorando las existentes puedes hacerlo por el siguiente link.

"Buy Me A Coffee"