{"id":26296347,"url":"https://github.com/maxroecker/evaluable","last_synced_at":"2026-05-17T19:37:20.884Z","repository":{"id":57231112,"uuid":"365606978","full_name":"MaxRoecker/evaluable","owner":"MaxRoecker","description":"A tiny library to compare objects as values in ECMAScript","archived":false,"fork":false,"pushed_at":"2024-01-04T13:23:40.000Z","size":427,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-18T23:40:11.006Z","etag":null,"topics":["comparison","ecmascript","evaluation","javascript","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/MaxRoecker.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-05-08T20:39:33.000Z","updated_at":"2023-11-15T04:39:12.000Z","dependencies_parsed_at":"2024-01-11T21:59:24.321Z","dependency_job_id":"247ad944-032d-4ab0-b84d-3249f2a50f9d","html_url":"https://github.com/MaxRoecker/evaluable","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0714285714285714,"last_synced_commit":"8af51ba9cfd2f78600331cb8180a8a9908f44293"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/MaxRoecker/evaluable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxRoecker%2Fevaluable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxRoecker%2Fevaluable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxRoecker%2Fevaluable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxRoecker%2Fevaluable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaxRoecker","download_url":"https://codeload.github.com/MaxRoecker/evaluable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxRoecker%2Fevaluable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265653284,"owners_count":23805778,"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":["comparison","ecmascript","evaluation","javascript","typescript"],"created_at":"2025-03-15T04:17:57.553Z","updated_at":"2025-10-19T10:47:51.977Z","avatar_url":"https://github.com/MaxRoecker.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Evaluable\n\nA tiny library to compare objects as values in ECMAScript\n\n[![View on NPM](https://img.shields.io/npm/v/evaluable?style=flat-square)](https://www.npmjs.com/package/evaluable)\n[![License](https://img.shields.io/npm/l/evaluable?style=flat-square)](https://maxroecker.mit-license.org/)\n\n## Installation\n\nUse the npm package manager to install Evaluable.\n\n```bash\nnpm i evaluable\n```\n\n## Usage\n\nEvaluable provides a function compare equality of anything in ECMAScript as a\nvalue. It is similar to the [“same-value-zero” algorithm][same-value-zero],\nwhich is used in collections such as [`Set`][Set] and [`Map`][Map], but it\nconsiders the methods `equals` or overwritten `valueOf`. See the API bellow to\ncheck every rule.\n\n```js\nimport { is } from 'evaluable';\n\nis(null, null); // returns true\n\nis(null, undefined); // returns false\n\nis(null, ''); // returns false\n\nis(+0, -0); // returns true\n\nis(0.1 + 0.2, 0.3); // returns true\n\nis(NaN, NaN); // returns true\n\nis('abc', 'abc'); // returns true\n\nis('\\u00F1', '\\u006E\\u0303'); // returns true\n\nis(new Date(0), new Date(0)); // returns true\n\nis(new Number(2), new Number(2)); // returns true\n```\n\nYou can also create custom classes with the `equals` method, and the `is`\nfunction will call it.\n\n```js\nimport { is } from 'evaluable';\n\nclass Box {\n  constructor(value) {\n    this.value = value;\n  }\n\n  equals(other) {\n    return (\n      this === other || (other instanceof Box \u0026\u0026 this.value === other.value)\n    );\n  }\n}\n\nis(new Box(0), new Box(0)); // returns true\n\nis(new Box(0), new Box(1)); // returns false\n```\n\nFor TypeScript users, you can import the `Evaluable\u003cT\u003e` interface to guide the\ncreation of objects that compared as values.\n\n```typescript\nimport { type Evaluable, is } from 'evaluable';\nimport { hash } from 'cruxhash';\n\nclass Point2D implements Evaluable {\n  x: number;\n  y: number;\n\n  constructor(x: number, y: number) {\n    this.x = x;\n    this.y = y;\n  }\n\n  equals(other: unknown): boolean {\n    return (\n      this === other ||\n      (other !== null \u0026\u0026\n        other instanceof Point2D \u0026\u0026\n        this.x === other.x \u0026\u0026\n        this.y === other.y)\n    );\n  }\n\n  hashCode(): number {\n    return hash(this);\n  }\n}\n\nconst a = new Point2D(3, 4);\nconst b = new Point2D(5, 12);\nconst c = new Point2D(3, 4);\n\nis(a, b); // returns false\nis(a, c); // returns true\nis(b, c); // returns false\n```\n\n\u003e To ensure compatibility with [Immutable.js][Immutable], the `Evaluable\u003cT\u003e`\n\u003e interface will enforce the implementation of the `hashCode` method. You can\n\u003e use the [CRUXHash][CRUXHash] library to easily create hashes from objects.\n\n## API\n\n### is\n\n▸ **is**(`a`, `b`, `delta?`): `boolean`\n\nReturns true if the inputs have the same value, false otherwise.\n\nTwo inputs, `a` and `b`, have the same value if:\n\n- Both are `undefined`;\n- Both are `null`;\n- Both are `true` or both `false`;\n- Both are the same symbol;\n- Both are the same bigint;\n- Both are strings with same length and with the same sequence of code points\n  in the [Unicode Normalized NFC form][NormalForm];\n- Both are numbers and:\n  - both are `NaN`;\n  - both are `Infinite` or both are `-Infinite`;\n  - both are equals by some `delta` tolerance. Default: `Number.EPSILON`.\n- Both are objects and:\n  - have the `equals` method and `a.equals(b)` returns true, or;\n  - have the `valueOf` method overwritten and `is(a.valueOf(), b.valueOf())`\n    returns true, or;\n  - are the same object, i.e., both references the same memory address.\n\nThe `is` function differs from:\n\n- the [`==` operator][==], because it does not perform a type conversion when\n  comparing the inputs;\n- the [`===` operator][===], because it returns true when comparing `NaN`\n  with `NaN`;\n- the [`Object.is` method][Object.is], because it returns true when comparing\n  `+0` and `-0`;\n- the [“same-value-zero” algorithm][same-value-zero], which is used in\n  collections such as [`Set`][Set] and [`Map`][Map], because it considers the\n  results of `equals` and overwritten `valueOf` methods.\n- the [`Immutable.is`][Immutable.is] method because it only considers the\n  results of `equals` methods and does not check the `delta` tolerance when\n  comparing numbers.\n\n[NormalForm]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\n[==]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality\n[===]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality\n[Object.is]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n[same-value-zero]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#same-value-zero_equality\n[Set]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set\n[Map]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\n[Immutable.is]: https://immutable-js.github.io/immutable-js/docs/#/is\n\n#### Parameters\n\n| Name    | Type      | Default value    | Description                                |\n| :------ | :-------- | :--------------- | :----------------------------------------- |\n| `a`     | `unknown` | -                | an input                                   |\n| `b`     | `unknown` | -                | another input                              |\n| `delta` | `number`  | `Number.EPSILON` | the minimum difference between two numbers |\n\n#### Returns\n\n`boolean`\n\n`true` if the inputs have the same value, `false` otherwise.\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to\ndiscuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n\n[MIT](https://maxroecker.mit-license.org/)\n\n[NormalForm]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\n[same-value-zero]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#same-value-zero_equality\n[Set]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set\n[Map]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\n[Immutable]: https://immutable-js.github.io/immutable-js/\n[CRUXHash]: https://github.com/MaxRoecker/cruxhash\n[==]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality\n[===]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality\n[Object.is]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ObjectsObject/is\n[Immutable.is]: https://immutable-js.github.io/immutable-js/docs/#/is\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxroecker%2Fevaluable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxroecker%2Fevaluable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxroecker%2Fevaluable/lists"}