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

@raadsel/smallify

v1.0.8

Published

Shortens some basic javascipt functions

Downloads

19

Readme

Smallify

Originally made for documatics hackathon.

Actual content:

I am very new to NPM packages so this is my first one! I hope it is something useful/good!

How to install

Run this command

$ npm install @raadsel/smallify

How to use

You can import all the short functions adding this line:

const { log, print, clear, int, float, sleep, random, randomColor, randomColorRGB, round, ev, getenv, setenv, UUID } = require("@raadsel/smallify");
  • log, => alternative console.log
  • print, => alternative console.log
  • clear, => shorter console.clear. Clears console
  • str, => converts object to string
  • int, => converts object to int
  • float, => converts object to float
  • sleep, => sleep and continue after that. Usage: sleep(miliseconds)
  • random, => random number between min and max
  • randomColor, => Gets a random Hex color
  • randomColorRGB, => Gets a random RGB color
  • randomColorRGBA, => Gets a random RGBA color
  • round, => Rounds number to decimals
  • ev, => shorter eval
  • getenv, => alternative to process.env.SECRET. Gets the environment variable
  • setenv, => set environment variable ; alternative to process.env[env] = value
  • allenvs, => get all environment variables
  • UUID, => generate a random UUID

Now the more detailed explanation

You can use the log() or print() function as a replacement for console.log(). And the clear() function as a replacement for console.clear()
Example:

const { log, print, clear } = require("@raadsel/smallify");

log("Hello world!")
//=> Hello world!

print("Hello NPM!")
//=> Hello NPM!

//to clear the console
clear()

You can use the str() function to convert an object to a string
Example:

const { str, log} = require("@raadsel/smallify");


const integer = 1
const inttostring = str(integer)
log(inttostring)
//=> 1
// but now it is an string!

You can use the int() function to convert an object to a integer!
Or use the float() function to convert an object to a float!
Example:

const { int, float, log} = require("@raadsel/smallify");

const string1 = "1"
const string2 = "2"
const float1 = "1.9"
const float2 = "1.1"

log(int(string1)+int(string2))
//=> 3

log(float(float1)+float(float2))
//=> 3

//this won't work if its a string
log(string1+string2)

You can use the random(num1, num2) function to get a random nummer between 2 inputted values. By default it's 0,100
Example:

const { print, random } = require("@raadsel/smallify");
print(random())
//=> random number between 0 and 100

//or like this
print(random(0,5))
//=> random number between 0 and 5

Now for the random colors:
There are 3 random colors functions: randomColor() (returns a random hex color), randomColorRGB() (returns a random RGB color) and randomColorRGBA() (returns a random RGBA color).
Usage:

const { print, randomColor, randomColorRGB, randomColorRGBA } = require("@raadsel/smallify");

print(randomColor())
//=> #387687
// (random hex)

print(randomColorRGB())
//=> rgb(213,187,1)
// (random RGB)

print(randomColorRGBA())
//=> rgba(60,93,176,72)
// (random RGBA)

The round() function rounds a number to a decimal.
Usage: \

round(1.23456789, 3) 
//=> 1.235

You can use ev() as shorter/replacement for eval(). And the sleep() function pauzes the code for a specific time. Kinda like the python time.sleep() function.
Example:

const { clear, log, sleep} = require("@raadsel/smallify");

ev("log('SPAM\nSPAM\nSPAM\nSPAM\nSPAM\nSPAMSPAMSPAM')")
//=> a lot of spam in the console

//using sleep() to not instantly clear the console so you can still see it
sleep(1000)

clear()
//=> 
//console is cleared

The getenv("ENV") version is an shorter version of process.env.[ENV], and the setenv("FOO", "BAR") is a shorter function of procces.env.[ENV] = value]
Usage example:

.env file:

FOO=bar

index file:

const { log, getenv} = require("@raadsel/smallify");

log(getenv("FOO"))
//=> BAR

or \

.env file:

index file:

const { log, getenv, setenv} = require("@raadsel/smallify");

setenv("FOO", "BAR")

log(getenv("FOO"))
//=> BAR

There's also the getenvs() function which gives ALL the envs there are

The UUID() function returns a random UUID (Universally unique identifier)

const { log, UUID} = require("@raadsel/smallify");

log(UUID())
//=> 1dda2536-3cc3-4978-a82c-a0f202916ac1 (this is random)

That's it, simple but powerful!