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

type-conversion

v0.1.0

Published

A javascript module which helps in various data type conversion

Downloads

2

Readme

Data types in javascript

| Data type | Example | | -------- | ------- |
| string | "Hello World" | | number | 42 | | null | null | | undefined | undefined | | boolean | true | | symbol | Symbol(42) | | object | {a: 1, b: 2} | | array | [1, 2, 3] | | BigInt | BigInt(42) | | map | new Map([[1, 2], [2, 3]]) | | date | new Date() | | RegExp | /^\d+$/ | | set | new Set([1, 2, 3]) | | Weakmap | new WeakMap() | | Weakset | new WeakSet([1, 2, 3]) |

Methods

tostr()

Converts the given input to a string datatype.

tostr(42); // "42"
tostr(true); // "true"
tostr(null); // ""
tostr() //""
tostr(undefined); // ""
tostr("Hello World"); // "Hello World"
tostr(new Date()); // "2020-01-01T00:00:00.000Z"
tostr(/^\d+$/); // "^\\d+$"
tostr([1,2,3]); // "123"
tostr({a: 1, b: 2}); // "{a: 1, b: 2}"
tostr(new Map([[1, 2], [2, 3]])); //"1234"
tostr(new Set([1, 2, 3])); // "123"
tostr(new WeakMap()); // "Error"

toint()

Converts the given input to an integer datatype.

toint(42); // 42
toint(true); // 1
toint(null); // 0
toint("hello world352")// 352
toint("464632423236") // 464632423236
toint("464632423236.5") // 464632423236
toint() // 0
toint(undefined); // 0
toint("Hello World"); // 0
toint(new Date()); // 0
toint(/^\d+$/); // 0
toint([1,2,3]); // 0
toint({a: 1, b: 2}); // 0
toint(new Map([[1, 2], [2, 3]])); // 0

toBool()

Converts the given input to a boolean datatype.

toBool(42); // true
toBool(true); // true
toBool(null); // false
toBool() // false
toBool(undefined); // false
toBool("Hello World"); // true
toBool(new Date()); // true
toBool(/^\d+$/); // true
toBool([1,2,3]); // true
toBool({a: 1, b: 2}); // true
toBool(new Map([[1, 2], [2, 3]])); // true
toBool(new Set([1, 2, 3])); // true
toBool(new WeakMap()); // false
toBool(new Set()) //false
toBool([]) //false
toBool({}) //false
toBool(-352)//false

toFloat()

Converts the given input to a float datatype.

toFloat(42); // 42
toFloat(true); // 1
toFloat(null); // 0
toFloat("hello world352")// 352
toFloat("464632423236") // 464632423236
toFloat("464632423236.5") // 464632423236.5
toFloat() // 0
toFloat(undefined); // 0
toFloat("Hello World"); // 0