All Projects → omidh28 → Clarifyjs

omidh28 / Clarifyjs

Licence: mit
Create and Execute Chained Javascript Methods In Any Order You want

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Clarifyjs

Ui As Code
Design work on improving Dart's syntax for UI code
Stars: ✭ 90 (-60.35%)
Mutual labels:  syntax
Ecsharp
Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
Stars: ✭ 141 (-37.89%)
Mutual labels:  syntax
Lexical syntax analysis
编译原理词法分析器&语法分析器LR(1)实现 C++
Stars: ✭ 173 (-23.79%)
Mutual labels:  syntax
Nord Sublime Text
An arctic, north-bluish clean and elegant Sublime Text theme.
Stars: ✭ 109 (-51.98%)
Mutual labels:  syntax
Es.next.syntax.vim
ES.Next syntax for Vim
Stars: ✭ 125 (-44.93%)
Mutual labels:  syntax
Burrido
Do-notation for JavaScript
Stars: ✭ 150 (-33.92%)
Mutual labels:  syntax
Syntax Highlighter
Syntax Highlighter extension for Visual Studio Code (VSCode). Based on Tree-sitter.
Stars: ✭ 88 (-61.23%)
Mutual labels:  syntax
Ifmt
Inline expression interpolation for Rust.
Stars: ✭ 197 (-13.22%)
Mutual labels:  syntax
Lightscript
JavaScript, with cleaned-up syntax and a few conveniences.
Stars: ✭ 141 (-37.89%)
Mutual labels:  syntax
Command
A library to build command line applications using PHP
Stars: ✭ 164 (-27.75%)
Mutual labels:  syntax
Clang Format Hooks
Apply a coding style with clang-format only to new code added to an existing code base.
Stars: ✭ 122 (-46.26%)
Mutual labels:  syntax
Sugar Rs
Rust syntax sugar collections.
Stars: ✭ 125 (-44.93%)
Mutual labels:  syntax
Es6
ES5 vs ES6 Reference
Stars: ✭ 158 (-30.4%)
Mutual labels:  syntax
Postcss Less
PostCSS Syntax for parsing LESS
Stars: ✭ 93 (-59.03%)
Mutual labels:  syntax
Vue Highlight.js
📜 Highlight.js syntax highlighter component for Vue.
Stars: ✭ 180 (-20.7%)
Mutual labels:  syntax
Astq
Abstract Syntax Tree (AST) Query Engine
Stars: ✭ 89 (-60.79%)
Mutual labels:  syntax
Udify
A single model that parses Universal Dependencies across 75 languages. Given a sentence, jointly predicts part-of-speech tags, morphology tags, lemmas, and dependency trees.
Stars: ✭ 147 (-35.24%)
Mutual labels:  syntax
Linqit
Extend python lists with .NET's LINQ syntax for clean and fast coding. Also known as PINQ.
Stars: ✭ 222 (-2.2%)
Mutual labels:  syntax
Phpgrep
Syntax-aware grep for PHP code.
Stars: ✭ 185 (-18.5%)
Mutual labels:  syntax
React Ast
render abstract syntax trees with react
Stars: ✭ 160 (-29.52%)
Mutual labels:  syntax

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.

Note That ClarifyJs is not intended to wrap your whole code but just endpoints that you want to be called more fluently or want to put a layer of abstract over calling functions and passing arguments.


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 objects to methods. These objects may also have default values:

const storage = {
	contacts: 'friends'
};

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

Travis build status Maintainability Test Coverage Dependency Status devDependency Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].