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

product-logic-operator

v1.0.14

Published

It is inspired by the concept of polynomial multiplication and tries to reproduce the concept in comparison operations.

Downloads

12

Readme

Introduction

It is inspired by the concept of polynomial multiplication and tries to reproduce the concept in comparison operations. For the moment it is very minimal, an example is proposed for understanding:

Example

OR

This is a series of classically written comparisons.

a == x1 || a == x2 || a == x3 || a == x4 || a == x5

from so would become so:

or(a, '==')(x1,x2,x3,x4,x5);

AND

similarly:

a == x1 && a == x2 && a == x3 && a == x4 && a == x5

would become

and(a, '==')(x1,x2,x3,x4,x5);

General structure for functions

The structure of the two functions (and, or) is similar.

(variableToCompare: any | Array<any| logicOperator>, params?: operator, howToHandleError?: howToHandleError)

below explained the parameters:

variableToCompare: any | Array<any| logicOperator>.

Accepts normal types: string and number. Accepts functions and executes them before comparing.

Warning in case of error it will raise the error as is.

This parameter if passed singly will go directly into the matching iterator, otherwise it will have an alternate path. If array could be a simple array of elements to compare, in which case the boolean operator will be decided depending on the function called.

ex: xx([a,b], '==')(x1,x2,x3,x4,x5); -> a == x1 XX a == x2 XX a == x3 XX a == x4 XX a == x5 XX b == x1 XX b == x2 XX b == x3 XX b == x4 XX b == x5

instead of XX we are going to substitute the operator that is decided by the function called. So with :

  • and we will have &&
  • or we will have || But we have an additional parameter to pass(type logicOperator), this is divided into three options:
  • and can be represented by: 'and', '&'
  • or can be represented by: 'or', '|'
  • not can be represented by: 'not', '!'

If we go to insert them we have to use a little bit of head, it may cause error. If inserted they change the operator that stands between the various comparisons that will be held to the right and left of the symbol. Example, using an "and" operator and writing it right with "and":

ex: xx([a,'and',b], '==')(x1,x2,x3,x4,x5); -> a == x1 XX a == x2 XX a == x3 XX a == x4 XX a == x5 && b == x1 XX b == x2 XX b == x3 XX b == x4 XX b == x5

Note that now regardless of the method (and, or) used between the first comparison group (a)(x1,x2,x3,x4,x5) and the second (b)(x1,x2,x3,x4,x5) the scielected operator will always be infraposed, in our what 'and'.

params?: operator

They go to determine which operation to go and execute.

'<' | '>' | '==' | '<=' | '>=' | '!=' | ((x: any, y: any) => boolean);

you can go and use the classic comparison operators or pass a function that will be called instead.

howToHandleError?: howToHandleError.

if the types are different the manageable cases are settable by setting the howToHandleError variable:

  • error : raises error: error: different types (this is case-settable by changing the messageError variable)
  • try : tries the comparison
  • return : returns false if the types are different
  • skip : avoids the comparison if the types are different
  • convert : tries the comparison but first tries to convert to a common value

shot

Function that proposes to perform an operation in a try-catch, trying to streamline the process and writing. It accepts as input either a function or a value. (I'm thinking about whether to include options that can go into better specifying what happens in conversion).

Example.

const message = shot(() => { if (tmp == true) { return 'hello'; } else if (tmp == false) { return 'wella'; } else { throw new Error("monazza"); } });