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

paracetamol

v0.7.2

Published

declarative check type of function arguments and development profiler for your functions

Downloads

53

Readme

Version

Current pre-alpha 0.7.2 Release is pre-alpha

Install

> npm i -S paracetamol

About

Declarative checking arguments in your function. Possible wrap and runtime syntax Added function profiling

You need any function where should be strong-type arguments

let fn = function functionName(number, string) {
    return string + '(' + number + ')';
};

Variant A: Declare and wrap

1.Declare arguments and wrap your function
fn = $p(
    fn,
    $p.Number, // asserts for 0 argument 
    $p.String  // asserts for 1 argument
);
2. Call it
// Normal run
fn(1, 'one');
fn(2, 'two');
fn(3, 'three');

// Throw TypeError
fn(1, []);
fn({}, 1);
fn(null, function(){});

Variant B. RunTime assert

let fn = function functionName(number, string) {
    $p.Number(number);
    $p.String(string);

    return string + '(' + number + ')';
};

Variant C. RunTime no throw assert

let fn = function functionName(number, string) {
    if (
        $p.Number.for(number) && 
        $p.String.for(string)
    ) {
        return string + '(' + number + ')';
    } else {
        return null;
    }
};

Function Time, Memory, Result profiling

it possible only wrap syntax:

let fn = function(a, b, c) {
    return Math.pow(a, b * c);
};

fn = $p(fn, $p.Number, $p.Number, $p.Number, {
    profile: {
        // profile memory change, default false
        memory        : true,
        
        // average/total time without first calling (VM jit compile), default true
        ignoreCompile : true, 
        
        // store all call event (Attention use, it is slow and need many memory), default false
        every         : true  
    }
});

for (let i = 0; i < 16; ++i) {
    fn(2, i, i+1);
}

console.log(fn.profile.print());
Result:
Function "anonymous" has been called 16 times
total calling time: 70us
compile time: 44us
average calling time: 4us
sum of memory diff: 18920
average memory diff: 1182.5
list of every call:
    P_TIME  HR_TIME  MEMORY_CHANGE  ARGS => RESULT
    52ms    44us     5696           (2 ,0 ,1) => 1
    52ms    56us     4072           (2 ,1 ,2) => 4
    52ms    1us      680            (2 ,2 ,3) => 64
    52ms    998ns    1656           (2 ,3 ,4) => 4096
    52ms    1us      568            (2 ,4 ,5) => 1048576
    52ms    964ns    568            (2 ,5 ,6) => 1073741824
    52ms    952ns    568            (2 ,6 ,7) => 4398046511104
    52ms    1us      568            (2 ,7 ,8) => 72057594037927940
    52ms    989ns    568            (2 ,8 ,9) => 4.722366482869645e+21
    52ms    975ns    568            (2 ,9 ,10) => 1.2379400392853803e+27
    52ms    920ns    568            (2 ,10 ,11) => 1.298074214633707e+33
    52ms    834ns    568            (2 ,11 ,12) => 5.444517870735016e+39
    52ms    832ns    568            (2 ,12 ,13) => 9.134385233318143e+46
    52ms    823ns    568            (2 ,13 ,14) => 6.129982163463556e+54
    52ms    815ns    568            (2 ,14 ,15) => 1.645504557321206e+63
    52ms    812ns    568            (2 ,15 ,16) => 1.7668470647783843e+72

Release Notes:

0.0.1:

  • Initial work concept

0.7.1:

  • Initial modular build: declarations factory (store), assert library, $p main function, definer, main point
  • Api: Basic types: Number, String, Symbol, Bool, Array, Object, Function, Null, Undef
  • Api: Type classes: Complex, Scalar, Any, Defined, Countable)

0.7.2

  • Api: Add new type class Numeric
  • Api: Numeric asserts types: int, float, positive, negative
  • Testing chained calling declarations $p.Numeric.int.positive(5);