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

@source4society/scepter-utility-lib

v5.0.0

Published

Useful functions commonly used within application development

Downloads

3

Readme

SCEPTER-utility-lib

scepter-logo

js-standard-style

Build Status

codecov

A library of useful javascript utility functions

Usage

Add this library to your project via npm or yarn with the command:

npm install -S @source4society/scepter-utility-lib

or yarn add @source4society/scepter-utility-lib

Then in your code, you can import the utility class:

import SCEPTERUtils from '@source4society/scepter-utility-lib';

or for commonJS

const SCEPTERUtils = require('@source4society/scepter-utility-lib')

Functions

isEmpty / isNotEmpty

use this to determine if a given variable is "empty". "Emptiness" is defined as an undefined value, null, NaN, {}, [], or ''. A value such as boolean false is not counted as empty, nor is a function or a class (instantiated or definition). isNotEmpty is simply the not of isEmpty

getRandomInt

Specify a min (inclusive) and max (exclusive) to get back a random number based on the platform (or injected) Math.random() function between min/max

valueOrDefault

If the value is empty, return default, otherwise return the value. Very useful for avoiding ternary's for better line coverage when setting default values

ssValueOrDefault

Same as above, but the second argument is a function or lambda to be executed if the first argument is empty. SS stands for "short-circuit".

ifTrueElseDefault

If the first argument evaluates to true, return the second argument, otherwise return the third. Very useful for avoiding branching logic but beware - you cannot short circuit the arguments like you can with a normal ternary

ssIfTrueElseDefault

Like above but value1 and value2 should be defined as functions or lambdas to provide short circuiting.

emptyAt / notEmptyAt

Like isEmpty and isNotEmpty but will traverse an objects properties to see if the property chain exists/has an empty value. The first argument is the object, the second argument is an array of subproperties to search in the order of nesting.

ucFirst

Useful utility to transform a word to title case (first letter becomes uppercase). Pass in a string and get back a string

validateApiResult

SCEPTER API results always return with a status: true property when successful, and status: false when something goes wrong. This will attempt to throw the error in the response if status is anything other than true. It will also parse from a string if the given result is in string form.

keyGenerator

Generates a random character string of length length, useful for creating API keys or jwt encoding keys.

getInOrDefault

This is useful for getting values from nester properties within objects, and returning a default value if the property does not exist or is empty. The first argument is the object to search, the second is an array of properties in nesting order, the third is the default value to return if the property does not exist or is empty

immutableToJS

Convert an immutable object to its JS form if the object is not empty, otherwise return undefined. Simply takes the immutableJS object as an argument

standardCallback

Use this to split the results of a standard callback into two separate function calls. The first argument is the error object, the second is the success (data) object. If the error object is not empty, then the error callback is called with the error data, otherwise the success callback is called with the success data

eitherOf

Use this function to disjoin (||) two values

conjunctionOf

Use this function to conjoin (&&) two values

ssEitherOf

Use this function to disjoin (||) two values, but the second argument should be a function that will be executed if the first is not true or undefined

ssConjunctionOf

Use this function to conjoin (&&) two values, but the second argument should be a function that will be executed if the first is not true or undefined

trueIfEqual

Function will return the result of value1 === value2

nullOp

Returns null value, useful if you want to return null in a short circuited function or if you want to render a null React component