{"id":17726667,"url":"https://github.com/sergeysova/match.js","last_synced_at":"2025-03-31T14:47:00.097Z","repository":{"id":57291880,"uuid":"60708983","full_name":"sergeysova/match.js","owner":"sergeysova","description":"Match values like a Boss","archived":false,"fork":false,"pushed_at":"2016-06-20T09:55:15.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T11:06:16.265Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/match.js","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sergeysova.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-08T15:34:31.000Z","updated_at":"2020-05-07T21:46:13.000Z","dependencies_parsed_at":"2022-08-27T12:20:36.675Z","dependency_job_id":null,"html_url":"https://github.com/sergeysova/match.js","commit_stats":null,"previous_names":["lestad/match.js"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeysova%2Fmatch.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeysova%2Fmatch.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeysova%2Fmatch.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeysova%2Fmatch.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergeysova","download_url":"https://codeload.github.com/sergeysova/match.js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246485197,"owners_count":20785255,"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","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":[],"created_at":"2024-10-25T17:06:27.656Z","updated_at":"2025-03-31T14:47:00.071Z","avatar_url":"https://github.com/sergeysova.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Match.js\n[![GitHub stars](https://img.shields.io/github/stars/lestad/match.js.svg)](https://github.com/lestad/match.js/stargazers)\n[![GitHub forks](https://img.shields.io/github/forks/lestad/match.js.svg)](https://github.com/lestad/match.js/network)\n[![npm](https://img.shields.io/npm/dm/match.js.svg?maxAge=2592000)](https://npmjs.com/match.js)\n[![GitHub issues](https://img.shields.io/github/issues/lestad/match.js.svg?maxAge=2592000)]()\n[![Maintainer](https://img.shields.io/badge/maintainer-lestad-blue.svg)](https://lestad.top)\n\n## Readme\n\n[![Code Climate](https://codeclimate.com/github/LestaD/match.js/badges/gpa.svg)](https://codeclimate.com/github/LestaD/match.js)\n[![Test Coverage](https://codeclimate.com/github/LestaD/match.js/badges/coverage.svg)](https://codeclimate.com/github/LestaD/match.js/coverage)\n[![Issue Count](https://codeclimate.com/github/LestaD/match.js/badges/issue_count.svg)](https://codeclimate.com/github/LestaD/match.js)\n[![Build Status](https://travis-ci.org/LestaD/match.js.svg?branch=master)](https://travis-ci.org/LestaD/match.js)\n[![David](https://img.shields.io/david/dev/lestad/match.js.svg?maxAge=2592000)]()\n\nMatch values like a Boss\n\n## Install\n\n[![NPM](https://nodei.co/npm/match.js.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/match.js/)\n\n\n## Usage\n\n### ES7:\n\n```js\nimport match from 'match.js';\n// or\nimport { match, matchType } from 'match.js';\n```\n\n### ES6:\n\n```js\nconst { match } = require('match.js');\n\nconst P_INIT = 1;\nconst P_READY = 2;\nconst P_PENDING = 3;\nconst P_SUCCESS = 4;\nconst P_FAIL = 9;\n\n\nconst result = (function someFunction(){ return P_SUCCESS; })();\n\nmatch(result, {\n  [P_PENDING]() {\n    console.info('Please, wait');\n  },\n\n  [P_SUCCESS]() {\n    console.log('Success! Let\\'s work.');\n  },\n\n  [P_FAIL](value, variants) {\n    console.error(`Failed with ${value}`, variants);\n  }\n}, () =\u003e console.warning('Default isn\\t present')); // default value\n\n// Success! Let's work.\n```\n\n\n### ES5:\n\n```js\nvar match = require('match.js');\n\nvar source = 'value';\nvar target = match.matchType(source, {\n  number: 5 + 12,\n  string: 'some',\n  function: function(){ return function(){} },\n  boolean: false,\n}, 'default');\n\nconsole.log(target); // some\n```\n\n\n\n## Example\n\n```js\nimport match, { matchType, matchStrict, matchRegexp } from 'match.js';\n\n// match by value, default is `null`\nconst result = match(20, {\n  10: 'first',\n  20: () =\u003e match('string', {\n    string: 200\n  })\n});\n\nconsole.log(result); // 200\n\n// match by type, default is `default`\nconst result2 = matchType('hello', {\n  string: 'that string',\n  number: 'that number',\n}, 'default');\n\nconsole.log(result2); // that string\n\n\n// Do not call function\nconst result3 = matchStrict('our', {\n  your: function() { return 11; },\n  my: function() { return 22; },\n  our: function() { return 33; },\n});\n\nconsole.log(result3); // function() { return 33; }\nconsole.log(result3()); // 33\n\n\nconst result4 = match('second', {\n  first: 1,\n  second: function() {\n    return 2;\n  }\n});\n\nconsole.log(result4); // 2\n\n\nconst result5 = matchRegexp('hi all', {\n  '^[a-z]+': true\n}, false, 'i');\n```\n\n\n## License\n\n[![license](https://img.shields.io/github/license/lestad/match.js.svg?maxAge=2592000)]()\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergeysova%2Fmatch.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergeysova%2Fmatch.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergeysova%2Fmatch.js/lists"}