{"id":16822273,"url":"https://github.com/strml/keymirror","last_synced_at":"2025-05-15T23:05:09.857Z","repository":{"id":17681008,"uuid":"20485854","full_name":"STRML/keyMirror","owner":"STRML","description":"Simple util to create an object with its keys mirrored as values. Standalone port of react/lib/keyMirror.","archived":false,"fork":false,"pushed_at":"2022-05-09T11:33:45.000Z","size":216,"stargazers_count":382,"open_issues_count":6,"forks_count":45,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-15T23:05:06.838Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"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/STRML.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":"2014-06-04T13:58:59.000Z","updated_at":"2025-02-18T02:50:04.000Z","dependencies_parsed_at":"2022-09-05T18:00:34.690Z","dependency_job_id":null,"html_url":"https://github.com/STRML/keyMirror","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2FkeyMirror","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2FkeyMirror/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2FkeyMirror/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2FkeyMirror/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/STRML","download_url":"https://codeload.github.com/STRML/keyMirror/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254436944,"owners_count":22070946,"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-13T11:03:10.328Z","updated_at":"2025-05-15T23:05:09.757Z","avatar_url":"https://github.com/STRML.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"KeyMirror\n=========\n\nCreate an object with values equal to its key names.\n\nI thought `react/lib/keyMirror` was useful and wanted to reuse it without any dependencies.\n\nThis is not my code, this is property of Facebook.\n\nWhy?\n----\n\nFrom [this discussion](https://github.com/facebook/react/issues/1639#issuecomment-45188026):\n\n\n\u003e The main purpose of keyMirror is to deal with the fact that Closure Compiler advanced mode crushes keys, which allows you to write code like\n\n\u003e `keyMirror({monkey: null, gorilla: null})`\n\n\u003e and have it become something like\n\n\u003e `k({m:null,g:null})`\n\n\u003e which evaluates to\n\n\u003e `{m:\"m\",g:\"g\"}`\n\n\u003e at runtime. If it was specified as a list of strings, they wouldn't get crushed matching the property names.\n\nUsage\n-----\n\n`npm install keymirror`\n\n```javascript\nvar keyMirror = require('keymirror');\nvar COLORS = keyMirror({blue: null, red: null});\nvar myColor = COLORS.blue;\nvar isColorValid = !!COLORS[myColor];\n```\n\nThe last line could not be performed if the values of the generated enum were\nnot equal to their keys.\n\nInput:  `{key1: val1, key2: val2}`\n\nOutput: `{key1: key1, key2: key2}`\n\nI sometimes use this with lodash - use the following upon your first use of lodash to mix it in:\n\n```javascript\nvar _ = require('lodash');\n_.mixin({keyMirror: require('keymirror')});\n// Can now be used as _.keyMirror(object)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrml%2Fkeymirror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrml%2Fkeymirror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrml%2Fkeymirror/lists"}