{"id":22697532,"url":"https://github.com/tomaskraus/not-predicate","last_synced_at":"2026-04-17T11:31:13.946Z","repository":{"id":63255373,"uuid":"565920441","full_name":"tomaskraus/not-predicate","owner":"tomaskraus","description":"Negation of predicate. Typed. Suitable for RxJS, Array.filter and others. ","archived":false,"fork":false,"pushed_at":"2023-06-19T22:00:04.000Z","size":911,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-22T23:01:50.241Z","etag":null,"topics":["filter","functional","ixjs","js","negation","not","predicate","rxjs","ts","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/tomaskraus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-14T15:50:35.000Z","updated_at":"2022-11-16T01:36:32.000Z","dependencies_parsed_at":"2024-12-10T05:14:23.013Z","dependency_job_id":"f9741c66-ce3a-4c07-8cbc-d9e2670e2525","html_url":"https://github.com/tomaskraus/not-predicate","commit_stats":{"total_commits":28,"total_committers":3,"mean_commits":9.333333333333334,"dds":0.3928571428571429,"last_synced_commit":"68cdcc7e7241dd318517044a1702d81268593b3b"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/tomaskraus/not-predicate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomaskraus%2Fnot-predicate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomaskraus%2Fnot-predicate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomaskraus%2Fnot-predicate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomaskraus%2Fnot-predicate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomaskraus","download_url":"https://codeload.github.com/tomaskraus/not-predicate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomaskraus%2Fnot-predicate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31927642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T10:35:34.458Z","status":"ssl_error","status_checked_at":"2026-04-17T10:35:09.472Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["filter","functional","ixjs","js","negation","not","predicate","rxjs","ts","typescript"],"created_at":"2024-12-10T05:14:16.837Z","updated_at":"2026-04-17T11:31:13.929Z","avatar_url":"https://github.com/tomaskraus.png","language":"TypeScript","readme":"![build](https://github.com/tomaskraus/not-predicate/actions/workflows/node.js.yml/badge.svg)\n[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)\n\n# not-predicate\n\nPredicate negation. A predicate that negates a result of its predicate argument:\n\n```ts\nimport {not} from 'not-predicate';\n\nconst isEven = (n: number) =\u003e n % 2 === 0;\n\nconsole.log([1, 2, 8, 5].filter(not(isEven)));\n//=\u003e [ 1, 5 ]\n```\n\n## Why to use\n\nYou cannot simply use the `!` negation operator on functions, because you cannot cast a function type to boolean:\n\n```ts\n// You cannot do this:\n[3, 2, 8, 5].filter(!isEven);\n```\n\n`not` acts as a predicate, so we can use it:\n\n```ts\n[3, 2, 8, 5].filter(not(isEven)); //=\u003e [ 3, 5 ]\n```\n\nPlus, there are more `not-predicate`'s advantages:\n\n- Works well with RxJS, Array.filter and others.\n- Typed. With `d.ts` for Javascript.\n- Zero-dependency.\n- Well tested.\n\n## Installation\n\n```bash\n$ npm install not-predicate\n```\n\n## Usage\n\nTypescript / ES module:\n\n```ts\nimport {not} from 'not-predicate';\n```\n\nJavascript / CommonJS:\n\n```js\nconst {not} = require('not-predicate');\n```\n\n## More\n\nCorrectly negates a predicate that uses an index argument:\n\n```ts\nconst isElementIndexEven = (_: unknown, index: number) =\u003e index % 2 === 0;\n\nconsole.log(['a', 'a', 'a', 'abc'].map(not(isElementIndexEven)));\n//=\u003e [ false, true, false, true ];\n```\n\nDeals with `this` object properly:\n\n```ts\nconst customWindow = {\n  innerWidth: 640,\n  innerHeight: 480,\n};\n\nfunction canXCoordFit(x) {\n  return x \u003e 0 \u0026\u0026 x \u003c= this.innerWidth;\n}\n\nconst xValues = [-10, 20, 680, 600, 800, 5];\nconst xsThatCanFit1 = xValues.filter(not(canXCoordFit), customWindow);\nconst xsThatCanFit2 = xValues.filter(not(canXCoordFit).bind(customWindow));\nconsole.log(xsThatCanFit1, xsThatCanFit2);\n//=\u003e [ -10, 680, 800 ] [ -10, 680, 800 ]\n```\n\nA predicate type is also provided:\n\n```ts\nexport type TPredicate\u003cT\u003e = (value: T, index: number) =\u003e boolean;\n```\n\nWe can also use the `not-predicate` in [RxJS](https://rxjs.dev/):\n\n```ts\nimport {not} from 'not-predicate';\nimport {from} from 'rxjs';\nimport {filter} from 'rxjs/operators';\n\nconst evenValueOnEvenIndex = (val: number, index: number) =\u003e\n  val % 2 === 0 \u0026\u0026 index % 2 === 0;\n\nconst src = from([1, 3, 5, 4, 6, 8]).pipe(filter(not(evenValueOnEvenIndex)));\nconst res: number[] = [];\nsrc.subscribe(x =\u003e res.push(x));\nconsole.log(res);\n//=\u003e [ 1, 3, 5, 4, 8 ]\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomaskraus%2Fnot-predicate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomaskraus%2Fnot-predicate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomaskraus%2Fnot-predicate/lists"}