{"id":18879719,"url":"https://github.com/loilo/composite-symbol","last_synced_at":"2025-06-20T18:13:45.723Z","repository":{"id":31716676,"uuid":"128683087","full_name":"loilo/composite-symbol","owner":"loilo","description":"✳️ Map a series of values to a unique JavaScript Symbol","archived":false,"fork":false,"pushed_at":"2023-08-24T07:01:01.000Z","size":111,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T07:51:12.655Z","etag":null,"topics":[],"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/loilo.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":"2018-04-08T21:23:42.000Z","updated_at":"2022-08-02T03:43:19.000Z","dependencies_parsed_at":"2024-11-08T11:02:48.088Z","dependency_job_id":null,"html_url":"https://github.com/loilo/composite-symbol","commit_stats":{"total_commits":34,"total_committers":5,"mean_commits":6.8,"dds":0.2647058823529411,"last_synced_commit":"0128f6a1f67be74f2c8f8f2b17953ac7dee23a3d"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fcomposite-symbol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fcomposite-symbol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fcomposite-symbol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fcomposite-symbol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loilo","download_url":"https://codeload.github.com/loilo/composite-symbol/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345384,"owners_count":21088267,"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-11-08T06:39:01.262Z","updated_at":"2025-04-14T19:23:26.617Z","avatar_url":"https://github.com/loilo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cbr\u003e\n  \u003cbr\u003e\n\n![composite-symbol logo, showing the Unicode character \"Composition Symbol\": the overlapping outlines of a square and a circle](https://cdn.jsdelivr.net/gh/Loilo/composite-symbol@master/composition-symbol.svg)\n\n  \u003cbr\u003e\n\u003c/div\u003e\n\n# Composite Symbol\n\u003e Get a unique JavaScript Symbol from a series of values, inspired by Bradley Farias' [Richer Keys](https://docs.google.com/presentation/d/1q3CGeXqskL1gHTATH_VE9Dhj0VGTIAOzJ1cR0dYqDBk) proposal.\n\n[![JavaScript Style Guide](https://badgen.net/badge/code%20style/standard/green)](https://standardjs.com)\n[![Tests](https://badgen.net/github/checks/loilo/composite-symbol/master)](https://github.com/loilo/composite-symbol/actions)\n[![npm](https://badgen.net/npm/v/composite-symbol)](https://npmjs.com/package/composite-symbol)\n\n## The Problem\nSince ES2015, we can use arbitrary objects as dictionay keys by using [Maps](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map).\n\nHowever, sometimes we need to map data to not just one object but to multiple values, for example to attach data to relationships. JavaScript unfortunately has no built-in way for this.\n\n## A Solution\nThis package provides a `getCompositeSymbol` function which takes an arbitrary (non-zero) number of values and returns a unique [Symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol). Whenever the same series of values is passed to `getCompositeSymbol`, the same Symbol is going to be returned.\n\nThese unique Symbols allow us to construct things around them, e.g. we could use them as keys in dictionaries.\n\n### Example\nWe can use this feature to attach metadata to a relationship between two objects, without having to tack it onto the participating objects themselves:\n\n```javascript\nconst getCompositeSymbol = require('composite-symbol')\n\n// Imaginary models\nconst Person = require('person')\nconst { Prius, Ferrari } = require('cars')\n\n// We want to store information about how people use their cars\nconst carRelationships = {}\n\n// Say hi to John!\nconst john = new Person()\n\n// John owns an old Toyota Prius\njohn.car = new Prius()\n\n// John needs his car to drive to work everyday\ncarRelationships[getCompositeSymbol(john, 'car')] = 'drives to work daily'\n\n// How about John buying a new car? He really earned it.\njohn.car = new Ferrari()\n\n// But John still needs to drive to work everyday\ncarRelationships[getCompositeSymbol(john, 'car')] // === \"drives to work daily\"\n```\n\n## Installation\nInstall it from npm:\n\n```bash\nnpm install --save composite-symbol\n```\n\n## Gotchas\n* Order matters! `getCompositeSymbol(1, 2, 3)` will not return the same symbol as `getCompositeSymbol(3, 2, 1)`.\n* Symbols are not unique across realms. That means, `getCompositeSymbol(1, 2, 3)` in browser window A will not return the same symbol as `getCompositeSymbol(1, 2, 3)` in browser window B.\n* Symbols, as well as Maps (which this package uses in the background) are ES2015 features. This is not a problem in Node.js anymore, but if you want to use this package in the browser, be aware that it will not work in Internet Explorer.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floilo%2Fcomposite-symbol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floilo%2Fcomposite-symbol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floilo%2Fcomposite-symbol/lists"}