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

typeval

v2.0.0

Published

typeVal es una función útil para determinar el tipo de un valor en JavaScript y realizar comparaciones de tipo de manera flexible y precisa.

Downloads

19

Readme

typeVal Module

Este es un módulo de JavaScript que exporta una función llamada typeVal. La función toma dos parámetros: value (valor) y type (tipo). Así es como funciona:

El objeto option define las correspondencias entre los tipos de JavaScript y sus representaciones en forma de cadena.

Si no se proporciona el parámetro type, la función devuelve la representación en forma de cadena del tipo del parámetro value. Busca la función adecuada en el objeto option en función del tipo del parámetro value y la invoca, devolviendo el resultado.

Ejemplo de uso

const { typeVal, typeValmin } = require('typeVal');

// input: value
// output: name
console.log(typeVal(42));             // "number"
console.log(typeVal(BigInt(42)));     // "bigint"
console.log(typeVal(""));             // "string"
console.log(typeVal(Symbol()));       // "symbol"
console.log(typeVal(true));           // "boolean"
console.log(typeVal(undefined));      // "undefined"

console.log(typeVal(()=>{}));         // "arrow"
console.log(typeVal(function(){}));   // "function"
console.log(typeVal(class {}));       // "class"
console.log(typeVal(null));           // "null"
console.log(typeVal([]));             // "array"
console.log(typeVal({}));             // "object"
console.log(typeVal(new (class {}))); // "instance"

Si se proporciona el parámetro type, la función verifica si la representación en forma de cadena del tipo del parámetro value coincide con el type proporcionado. Lo hace comparando el resultado de invocar la función adecuada del objeto option con el type proporcionado. Si coinciden, devuelve true; de lo contrario, devuelve false.

Ejemplo de uso

// inputs comparation
// output: boolean
console.log(typeVal(42, "number"));           // true
console.log(typeVal(BigInt(42), "bigint"));   // true
console.log(typeVal("", "string"));           // true
console.log(typeVal(Symbol(), "symbol"));     // true
console.log(typeVal(true, "boolean"));        // true
console.log(typeVal(undefined, "undefined")); // true

console.log(typeVal(()=>{}, "arrow"));            // true
console.log(typeVal(function(){}, "function"));   // true
console.log(typeVal(class {}, "class"));          // true
console.log(typeVal(null, "null"));               // true
console.log(typeVal([], "array"));                // true
console.log(typeVal({}, "object"));               // true
console.log(typeVal(new (class {}), "instance")); // true