{"id":13989714,"url":"https://github.com/omidh28/clarifyjs","last_synced_at":"2025-07-22T11:31:36.625Z","repository":{"id":57199429,"uuid":"112218666","full_name":"omidh28/clarifyjs","owner":"omidh28","description":"Create and Execute Chained Javascript Methods In Any Order You want","archived":false,"fork":false,"pushed_at":"2017-12-03T12:07:23.000Z","size":373,"stargazers_count":221,"open_issues_count":1,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-21T10:43:10.911Z","etag":null,"topics":["cascading","chained","javascript","syntax"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/omidh28.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-27T16:13:04.000Z","updated_at":"2025-02-11T15:49:56.000Z","dependencies_parsed_at":"2022-09-16T14:51:23.353Z","dependency_job_id":null,"html_url":"https://github.com/omidh28/clarifyjs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/omidh28/clarifyjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omidh28%2Fclarifyjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omidh28%2Fclarifyjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omidh28%2Fclarifyjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omidh28%2Fclarifyjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omidh28","download_url":"https://codeload.github.com/omidh28/clarifyjs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omidh28%2Fclarifyjs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266483691,"owners_count":23936397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cascading","chained","javascript","syntax"],"created_at":"2024-08-09T13:01:59.435Z","updated_at":"2025-07-22T11:31:35.968Z","avatar_url":"https://github.com/omidh28.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# clarifyJs\n\nClarifyJs allows you to easily create chained methods that can be executed in any order you want.\n\nThis 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:\n```javascript\nsend('hello everyone!').to('friends');\n```\nThis works fine with normal method chaining but what about when we want to create more complex chained methods?\nFor example we want to filter some of our friends out:\n```javascript\nsend('hello everyone!').to('friends').except('john');\n```\nNormal 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.\n\nClarifyJs also allows controlling async methods. Suppose we want to log a message to console when the message has been sent:\n```javascript\nsend('hello everyone!').to('friends').then.log('message has been sent.');\n```\nThe 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.\n\nThese features come in price of making the whole process async.\n\n**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.\n\n---\n\n## Installation\n\nIn a browser:\n```html\n\u003cscript src=\"clarify.js\"\u003e\u003c/script\u003e\n```\n\nUsing npm:\n```shell\n$ npm i --save clarifyjs\n```\n\n---\n\n## Usage\nFirst the methods routes must be defined.\n\n**Syntax:**\n```javascript\n// Array of routes objects\nconst routesData = [ ...];\nconst root = clarify({ routes: routesData });\n```\n\n### Routes\n\nRoutes are objects that have at least the two property **handler** and **path**.\n\n| Property        | Type           | Default Value | Description  |\n| :-------------: | :-------------: | :-----: | :-----: |\n| path| String | None | The address of the method, Root address is empty string. Wildcard can be used.\n| handler | Function | None | The method function.\n| storeResultAs | String | Empty String | Store method's result with this name.\n| inject | String/Array | Empty Array | Name of the stored results to pass to the method handler\n| controller | String | () | \"()\" if the method should be called with paranthesis otherwise \"[]\"\n| awaitForHandler | Boolean | False | Whether the process should wait for the method handler to complete or not.\n| Priority | Number | -Infinity | Priority of the method execution, Higher priority methods will be executed before others.\n\n### Example\nDemonstration of the example explained above:\n```javascript\nconst routesData = [\n\t{\n\t\tpath: '',\n\t\thandler: sendMessageFunc,\n\t\tinject: ['contacts'],\n  \t\tawaitForHandler: true,\n\t\tpriority: 0\n\t},\n\t{\n\t\tpath: 'to',\n\t\thandler: contactSelectorFunc,\n\t\tstoreResultAs: 'contacts',\n\t\tpriority: 2\n\t},\n        {\n\t\tpath: 'to.except',\n\t\thandler: contactFilterFunc,\n\t\tinject: ['contacts'],\n\t\tstoreResultAs: 'contacts',\n\t\tpriority: 1\n\t},\n\t{\n\t\tpath: 'to.except.then.log',\n\t\thandler: logFunc,\n\t\tpriority: -Infinity\n\t}\n];\n\nconst send = clarify({ routes: routesData });\nsend('hello everyone!').to('friends').except('john').then.log('message has been sent!');\n```\n\n### Storage\n\nClarifyJs has an integrated storage system that can store and pass objects to methods.\nThese objects may also have default values:\n\n```javascript\nconst storage = {\n\tcontacts: 'friends'\n};\n\nconst send = clarify({ routes, storage });\n```\n\n[![Travis build status](http://img.shields.io/travis/omidh28/clarifyJs.svg?style=flat)](https://travis-ci.org/omidh28/clarifyJs)\n[![Maintainability](https://api.codeclimate.com/v1/badges/f76a9e87744ce4283c42/maintainability)](https://codeclimate.com/github/omidh28/clarifyjs/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/f76a9e87744ce4283c42/test_coverage)](https://codeclimate.com/github/omidh28/clarifyjs/test_coverage)\n[![Dependency Status](https://david-dm.org/omidh28/clarifyJs.svg)](https://david-dm.org/omidh28/clarifyJs)\n[![devDependency Status](https://david-dm.org/omidh28/clarifyJs/dev-status.svg)](https://david-dm.org/omidh28/clarifyJs#info=devDependencies)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomidh28%2Fclarifyjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomidh28%2Fclarifyjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomidh28%2Fclarifyjs/lists"}