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

af-conditionals

v1.3.2

Published

A library that provides tools for making decisions in your code

Downloads

108

Readme

af-conditionals Library

Status of Project

Build Status Coverage Status

Purpose

The af-conditionals library was created to provide a consistent interface from which to create dynamic comparisons, conditional expressions, logical expressions, and operations. Through the interface, expressions can be defined externally to the application code and dynamically executed.

Standard Calling Conventions

All Comparisons, Conditionals, Logicals, and Operators expose the object class and a variable named after the class with the word Instance appended, but starting with a lowercase letter. For example: IsString is exposed as is isStringInstance. The isStringInstance variable is declared with a let so you may subclass the object and then use your version of your class throughout your application easily. Additionally, we expose a function that implements the testing for the class, for example, IsString has a exposed function isString that calls isStringInstance.test(). (This is described in the Release Notes for v0.2.0.)

Comparisons

The Comparison class provides a compare and test public methods.

The compare method takes two values and compares them returning:

  • -1 (negative numeral one) when the first value is less than the second value
  • 0 (zero) when the first value is equal to the second value
  • +1 (positive numeral one) when the first value is greater than the second value

When possible the compare method will compare the values using strict equals (===). When the values are not of the same type, compare will use coerced equality (==).

The test uses the compare method to get the result and then compare that result to an expected result that you supply. test returns:

  • true if the returned result and expected result are equal
  • false otherwise

Supplied Comparisons are:

  • Equal - determines if two values are equal
  • GreaterThan - determines if the first value is greater than the second value
  • GreaterThanOrEqual - determines if the first value is greater than or equal to the second value
  • LessThan - determines if the first value is less than the second value
  • LessThanOrEqual - determines if the first value is less than or equal to the second value

Comparisons use shorthand calling function names instead of exposed functions of equal, greaterThan, etc... eq, gt, gte, lt, lte are exposed.

strict

Both the compare and test methods take an optional parameter strict that defaults to true. When the comparison is between two string values the strict parameter is used to indicate if the comparison should be case-insensitive or not. When strict is true the comparison is made taking case into account (i.e. capital letters are greater than lowercase letters).

Conditionals

This library defines a Conditional class that is then subclassed to create standard conditional checks.

Supplied Conditionals are:

  • IsArray - determines if a value is an Array (and Array only)
  • IsEmpty - determines if a value is empty
    • A string is empty if it is equal to ""
    • A number is empty if it is NaN
    • A boolean is empty if it is false
  • IsFalsey - loosely tests if a value is false (coerced using !)
  • IsFunction - determines if a value is a Function
  • IsNumber - determines if a value is a number
  • IsObject - determines if a value is an object. This excludes Array's and Function's
  • IsString - determines if a value is a string
  • IsTruthy - loosely tests if a value is true (coerced using !!)
  • IsUndefinedOrNull - determines if a value is undefined or null
  • IsUsable - inverts IsUndefinedOrNull to determine if a value is "usable"

The majority of the conditionals use typeof to determine if a value is of a particular type or not and use non-coerced equality to test the type.

Logicals

Supplied Logicals are:

  • And - performs a boolean AND on the supplied operands (can be more than a single test)
  • Or - performs a boolean OR on the supplied operands (can be more than a single test)

Operators

Supplied Operators are:

  • Not - performs a boolean NOT on the supplied value (which will be cast into truthy or falsey)

Support

To share your comments, provide suggestions, or raise issues, create an issue.