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

clarifyjs

v0.1.2

Published

A library to write more clear and declarative JavaScript code

Downloads

2

Readme

clarifyJs

ClarifyJs allows you to easily create chained methods that can be executed in any order you want.

This feature is particularly useful when you want to make your code more friendly and declarative, For Example we have these chained methods for sending a message to a specific group of users:

send('hello everyone!').to('friends');

This works fine with normal method chaining but what about when we want to create more complex chained methods? For example we want to filter some of our friends out:

send('hello everyone!').to('friends').except('john');

Normal javascript methods are executed from left-to-right, So when we reach "except" filter the message has already been sent to all friends. However ClarifyJs allows to overcome this limitation by allowing to priorities methods to allow execution in any order.

ClarifyJs also allows controlling async methods. Suppose we want to log a message to console when the message has been sent:

send('hello everyone!').to('friends').then.log('message has been sent.');

The problem is that if "send" method is a async method then the log message will be printed before the message is actually sent. ClarifyJs allows to decide whether the process should wait for a specific async method to complete before moving on or just execute and pass by it.

These features come in price of making the whole process async.


Installation

In a browser:

<script src="clarify.js"></script>

Using npm:

$ npm i --save clarifyjs

Usage

First the methods routes must be defined.

Syntax:

// Array of routes objects
const routesData = [ ...];
const root = clarify({ routes: routesData });

Routes

Routes are objects that have at least the two property handler and path.

| Property | Type | Default Value | Description | | :-------------: | :-------------: | :-----: | :-----: | | path| String | None | The address of the method, Root address is empty string. Wildcard can be used. | handler | Function | None | The method function. | storeResultAs | String | Empty String | Store method's result with this name. | inject | String/Array | Empty Array | Name of the stored results to pass to the method handler | controller | String | () | "()" if the method should be called with paranthesis otherwise "[]" | awaitForHandler | Boolean | False | Whether the process should wait for the method handler to complete or not. | Priority | Number | -Infinity | Priority of the method execution, Higher priority methods will be executed before others.

Example

Demonstration of the example explained above:

const routesData = [
	{
		path: '',
		handler: sendMessageFunc,
		inject: ['contacts'],
  		awaitForHandler: true,
		priority: 0
	},
	{
		path: 'to',
		handler: contactSelectorFunc,
		storeResultAs: 'contacts',
		priority: 2
	},
        {
		path: 'to.except',
		handler: contactFilterFunc,
		inject: ['contacts'],
		storeResultAs: 'contacts',
		priority: 1
	},
	{
		path: 'to.except.then.log',
		handler: logFunc,
		priority: -Infinity
	}
];

const send = clarify({ routes: routesData });
send('hello everyone!').to('friends').except('john').then.log('message has been sent!');

Storage

ClarifyJs has an integrated storage system that can store and pass values to methods. These values may also have default values:

const storage = {
	contacts: 'friends'
};

const send = clarify({ routes, storage });

Travis build status Maintainability Test Coverage Dependency Status devDependency Status