{"id":17609698,"url":"https://github.com/bitoiu/venn","last_synced_at":"2025-04-30T14:29:56.926Z","repository":{"id":416377,"uuid":"9757768","full_name":"bitoiu/venn","owner":"bitoiu","description":"Fluent API for set operations.","archived":false,"fork":false,"pushed_at":"2022-12-30T17:14:59.000Z","size":691,"stargazers_count":9,"open_issues_count":12,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T14:29:53.556Z","etag":null,"topics":["fluent-api","intersection","javascript","union","venn"],"latest_commit_sha":null,"homepage":"http://bitoiu.github.io/venn","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitoiu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-29T20:52:39.000Z","updated_at":"2023-12-14T12:23:07.000Z","dependencies_parsed_at":"2023-01-13T10:16:06.080Z","dependency_job_id":null,"html_url":"https://github.com/bitoiu/venn","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitoiu%2Fvenn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitoiu%2Fvenn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitoiu%2Fvenn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitoiu%2Fvenn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitoiu","download_url":"https://codeload.github.com/bitoiu/venn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251721332,"owners_count":21632813,"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":["fluent-api","intersection","javascript","union","venn"],"created_at":"2024-10-22T17:09:47.057Z","updated_at":"2025-04-30T14:29:56.900Z","avatar_url":"https://github.com/bitoiu.png","language":"JavaScript","readme":"# venn \n \n[![NPM version](https://badge.fury.io/js/venn.png)](http://badge.fury.io/js/venn)\n\n## Motivation\n\nOne of these days I was looking for a library that would allow me to do simple set operations, mostly intersection and union. There's a lot of libraries that do this but I didn't find one with a fluent API. This a stab at one:\n\nCompatible with AMD and node.\n\n### getting started \n\nA venn set is just an array on steroids:\n\n```javascript\n\n  var venn = require(\"venn\")\n  venn.create([1,2])   \n  console.log(venn) // [1,2]\n\n```\n\n### union\n\nYou can now chain operations to this set, using `union` or `or`:\n\n```javascript\n  venn.create([1,2])\n      .union([1,2,3,4])\n      .or([5]) // [1,2,3,4,5]\n```\n\n`union` and `or` are just alias for the same operation.\n\n### intersection\n\n\n```javascript\n    venn.create([1,2])\n      .union([1,2,3,4]) \n      .intersection([1,5]) // [1]\n```\n\nif you prefer you can also use `and` instead of `intersection`\n\n\n### not\n\nIf you want to be negative about it, you can check out `not`\n\n```javascript\n    venn.create([1,2,3,4,5])\n      .not([4])\n      .not([5]) // [1,2,3]\n```\n\n### chaining everything\n\nOr a mix of everything\n\n```javascript\n    venn.create([1,2])\n      .or([1,2,3,4,5])\n      .and([1,5])\n      .or([2]) // [1,5,2]\n```\n\n### Objects\n\nIf you're crazy you can use venn without a key function. We'll just figure it out how to index the objects.\n\n```javascript\n    venn.create([\n        {name: \"vitor\", age: \"23\"}\n      , {name: \"khov\",  age: \"24\"}\n      , {name: \"pat\",   age: \"30\"}])\n      .intersection([\n        {name: \"vitor\",  age: \"23\"}\n      , {name: \"newguy\", age: \"0\"}\n      , {name: \"pat\",    age: \"50\"}])\n      .union([\n        {name: \"khov\", age : \"10\"}\n      , {name: \"nuno\", age : \"20\"}]) \n\n    // vitor, khov and nuno\n```\n\n### Key function\n\nBut really, write your own key function:\n\n```javascript\n  \n    var myKeyFunction = function(item) {\n      return item.name\n    }\n    \n    venn.create([\n        {name: \"vitor\", age: \"100\"}\n      , {name: \"khov\",  age: \"100\"}], myKeyFunction)\n      .and([\n        {name: \"vitor\", age: \"0\"}\n      , {name: \"khov\",  age: \"0\"}\n      .or([\n        {name: \"khov\",  age : \"-100\"}\n      , {name: \"nuno\",  age : \"20\"}]) \n   \n    // vitor, khov(the first of them), nuno\n```\n\n### Some notes\n\n* The keyFunction only needs to be set once for each venn object (as you would expect)\n* Don't forget if you apply a built-in array function like `filter` or `map` the returning object is not a venn object (as you would once again expect)\n\nLet me know if there are improvements I can do to the library. I might take some time to implement the other less used set operations.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitoiu%2Fvenn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitoiu%2Fvenn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitoiu%2Fvenn/lists"}