New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

typeval

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeval

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.

latest
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 31 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts