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

wise-helper

v2.4.3

Published

usefull simple helper functions: print, random, randomInt

Downloads

10

Readme

Wise-helper


Usefull functions like getting a random number, printing, and more using simple syntax

  • Math.floor(Math.random())-> random(MAX)
  • console.log("string") -> print("string")
  • random(255) -> Random number between 0-255
  • randString(6) -> Random String w/ length 6

<doc version 1.2 last updated 2017-11-22>

install

npm install --save wise-helper

at top of your project file

require('wise-helper');

//ready to go!

Useage

inside of your 'app.js'

require('wise-helper');
var a,b,c,d,e,f,g,h;

a = random( 255 );          // int 0-255
b = random( 10 );           // int 0-10                        
c = randInt( 0, 100 );    // int 0-100
d = randInt( -100, 100 ); // int -100 - 100

//or print like this

print( random(255) );
print( random(10) );

//prints random characters 

//randChar() : ascii 32("space") though 127 ("")
//randChar(Max) : ascii char 0 ("NULL") though Max

e = randChar();             // char a-z A-Z 0-9 ~!#$%^&**()_+_+,./;'[]\<>?:"{}|
f = randChar(99);           // char 0-99 ascii characters
h = randChar(64,90);        // char A-Z


console.log("a: ", a, ", b: ", b, ", c: ", c, ", d: ", d, ", e: ", e, ", f: ", f, ", g: ", g,", h: ", h);

print

print = console.log.bind( console );

random

Name  : random()
--------------------------------------------
Desc  : genrates radnom number
--------------------------------------------
Param : random( intager)
Return: random value between 0 and max
--------------------------------------------
EX    :
var number = random(255);
print(number); // 0 - 255

default no params
 var number = random();
 print(number); // 0 - 100
--------------------------------------------
--------------------------------------------

function random( max ){
    if( max ){
        return randInt(0, max);
    }else{
        max = 100;
        return randInt(0, 100);
    }
}

randomInt

Name  : randInt()
--------------------------------------------
Desc  : generates random numbers
between to values min, max
--------------------------------------------
Param :
Return: randInt(integer,integer)
         randInt(Min,Max)
--------------------------------------------
Long  :returns a sumirandom number
between max and min
--------------------------------------------
--------------------------------------------

function randomInt( min, max ) {
    return Math.floor( Math.random() * ( max - min + 1 ) ) + min;
}

randChar

Name  : randChar()
--------------------------------------------
Param : randChar(Integer, Integer)
Return: Char random between min, max ascii
--------------------------------------------
--------------------------------------------

function randChar( min, max ) {
    if( max && max >=0 ){
        return String.fromCharCode( randInt( min, max ) );
    }else if( min && min >=0 ){
        return String.fromCharCode( randInt( 0, min ) );
    }else{
        return String.fromCharCode( randInt( 32, 127 ) );
    }
}

randString

Name  : randString()
--------------------------------------------
Desc  : genartes random string of n length
--------------------------------------------
Param : randString(intager)
Return: string ( 0-n length) Chars 'A' to '-'
--------------------------------------------
Long  : returns string made up of ascii values
32 - 127 (A to '-') respectivily
exampe output

93nx-./1a

--------------------------------------------
--------------------------------------------


function randString( n ) {
    var string = '';
    for( var i = 0; i < n; i++ ){
        string +=  randChar();
    }
    return string;
}

padding

Name  : padding()
--------------------------------------------
Desc  : returns correct padding for printing
--------------------------------------------
Param : padding(String, Integer)
Return: String
--------------------------------------------
Long  : returns correct padding when
printing out multi line outputs
--------------------------------------------
EX    :
Pad strings START and END.

var start = "START";
var end   = "END";

var out = start + padding( start, 13 ) + ": " + end;

print(out);
--------------------------------------------
--------------------------------------------

function padding(str, padding) {
    if(str) {
        var inputString = str.toString();
        var spacer = '';
        var len = padding - inputString.length;
        if (len < 0) {
            len = 0;
        }
        for (var i = 0; i < len; i++) {
            spacer += ' ';
        }
        return spacer;
    }else{
        console.error("Error : padding()'s first argument is null or undefined.");
        console.error("FIX   : correct uses padding(String, Number).");
    }
}

arrToString

Name  : arrToString()
--------------------------------------------
Desc  : concatnate array to string
--------------------------------------------
Param : arrToString(Array)
Return: String  of A[i] + A[i+1]....A[i+n]
--------------------------------------------
Long  :
EX    :
arrToString(['Alis','#*%','KYLE','1'])
//Alis#*%KYLE1"
arrToString([4,6888,-1,101,2,0])
//'"46888-110120"'
arrToString(['Alis','#*%','KYLE','1'], ' ');
//"Alis #*% KYLE 1"
arrToString([4,6888,-1,101,2,0], ' ')
//"4 6888 -1 101 2 0"
arrToString([4,6888,-1,101,2,0], ', ')
//"4, 6888, -1, 101, 2, 0"
--------------------------------------------
--------------------------------------------

function arrToString( arr, paddingChar){
    if(! paddingChar ) paddingChar = '';

    var joined = '';
    for( var i in arr ){
        if( parseInt( i ) === arr.length - 1 ) {
            joined += arr[ i ];
        }else{
            joined += arr[ i ] + paddingChar;
        }
    }
    return joined;
}