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 🙏

© 2025 – Pkg Stats / Ryan Hefner

types-magic

v2.0.5

Published

Create and use your own types

Readme

Create types with Magic 🪄

WARNING ⚠️

Use versions 2.0.5 < For stable use.

Description

The types-magic module provides a versatile class for managing labeled parameters with customizable types. It offers methods for easy access, manipulation, and conversion of parameter values. This module is suitable for various data management tasks in JavaScript applications.

Installation

You can install the types-magic module via npm by running:

npm install types-magic

Usage

const $ = require('types-magic');


let instance = new $(['name', 'age'], ['string', 'number']);
instance.name = 'John';
instance.age = 30;

console.log(instance.toString());

Or:

const $ = require('types-magic');

const person = new $([['name', 'age'], ['string', 'number']]);
let instance1 = person.new()
instance1.name = 'John';
instance1.age = 30;
let instance2 = person.new({
	name:'Jane',
	age:34,
})
console.log(instance1.toString());
console.log(instance2.toXML());

Proxy and _pHandler

To proxy data you can use _pHandler

const $ = require('types-magic');

const person = new $([['name', 'age', 'incognito'], ['string', 'number', 'boolean']]);
person._pHandler = {
	get: function (target, prop, receiver) {
		if(person.incognito){
			return "[Unknown]"
		}
   	return target[prop];
   },
   set: function (target, prop, value, receiver) {
		if(value === null){
			throw new Error('What would you do if your name was null!')
		}
		else{
			console.log(`I like the name ${value}`)
			target[prop] = value;
		}
   },
}
person.initProxy()
person._proxy.name = 'bob' //I like the name bob
person.incognito = false
console.log(person._proxy.name)//bob
person.incognito = true
console.log(person._proxy.name)//[unknown]
person._proxy.name = null // What would you do if your name was null

Configurations

const $ = require('types-magic');

const person = new $([['name', 'age'], ['string', 'number']]);
person.configure('const', true) //the persons name can't change after set
person.configure('loose', true) //type errors will be reduced to logs. (not recommened)
person.configure('looser', true)//type errors will be not be logged. (not recommened)
person.configure('nullBypass', true)//null will be allowed on any data type. (recommended)
let bob = person.new({name:"bob",age:25})//correct
let stewart = person.new()
stewart.name = 'stewart'//incorrect
stewart.age = 33 //incorrect

All conversion functions include:

  • toString()
  • toObject()
  • toArray()
  • toJSON()
  • toXML()
  • toYAML()
  • toCSV()

Known bugs:

  • Bug: Dates will not appear in some data types.
  • Fix: Use objects instead of dates.