{"id":13566875,"url":"https://github.com/dsherret/ts-nameof","last_synced_at":"2025-05-16T06:07:17.998Z","repository":{"id":45813242,"uuid":"65151513","full_name":"dsherret/ts-nameof","owner":"dsherret","description":"nameof in TypeScript","archived":false,"fork":false,"pushed_at":"2023-03-23T16:04:22.000Z","size":944,"stargazers_count":498,"open_issues_count":33,"forks_count":23,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-10T02:51:58.209Z","etag":null,"topics":["babel-plugin","custom-transformer","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/dsherret.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-08-07T19:57:40.000Z","updated_at":"2025-04-25T04:00:13.000Z","dependencies_parsed_at":"2024-01-14T15:25:16.860Z","dependency_job_id":"5e5c620b-a720-473e-8248-29fa9abee5b7","html_url":"https://github.com/dsherret/ts-nameof","commit_stats":{"total_commits":218,"total_committers":7,"mean_commits":"31.142857142857142","dds":0.09174311926605505,"last_synced_commit":"5e817b83998d5e3735c2d4dc991c86a9dcffdecd"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsherret%2Fts-nameof","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsherret%2Fts-nameof/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsherret%2Fts-nameof/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsherret%2Fts-nameof/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dsherret","download_url":"https://codeload.github.com/dsherret/ts-nameof/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478190,"owners_count":22077676,"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":["babel-plugin","custom-transformer","typescript"],"created_at":"2024-08-01T13:02:18.581Z","updated_at":"2025-05-16T06:07:12.976Z","avatar_url":"https://github.com/dsherret.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Utilities :wrench:","Transformers"],"sub_categories":["General transformers"],"readme":"# ts-nameof\n\n[![Build Status](https://travis-ci.org/dsherret/ts-nameof.svg)](https://travis-ci.org/dsherret/ts-nameof)\n\n[`nameof`](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/nameof) in TypeScript.\n\nMonorepo for ts-nameof projects:\n\n- [ts-nameof](packages/ts-nameof) (TypeScript compiler)\n- [babel-plugin-ts-nameof](packages/babel-plugin-ts-nameof) (Babel compiler)\n- [ts-nameof.macro](packages/ts-nameof.macro) (Babel compiler)\n\n## Recommend: Don't use this package\n\nSee [here](https://github.com/dsherret/ts-nameof/issues/121).\n\n## Setup\n\nts-nameof is a _compile time transform_ so it requires some setup. For setup instructions, see the packages above for the compiler you use.\n\n## nameof transform\n\n### `nameof(...)`\n\n```ts\nnameof(console);\nnameof(console.log);\nnameof(console[\"warn\"]);\n```\n\nTransforms to:\n\n```ts\n\"console\";\n\"log\";\n\"warn\";\n```\n\n### `nameof\u003cT\u003e()`\n\n```ts\nnameof\u003cMyInterface\u003e();\nnameof\u003cArray\u003cMyInterface\u003e\u003e();\nnameof\u003cMyNamespace.MyInnerInterface\u003e();\n```\n\nTransforms to:\n\n```ts\n\"MyInterface\";\n\"Array\";\n\"MyInnerInterface\";\n```\n\nThis is useful when working in the type domain.\n\n### `nameof\u003cT\u003e(o =\u003e ...)`\n\n```ts\nnameof\u003cMyInterface\u003e(o =\u003e o.prop);\n```\n\nTransforms to:\n\n```ts\n\"prop\";\n```\n\n## nameof.full transform\n\n### `nameof.full(...)`\n\n```ts\nnameof.full(console.log);\nnameof.full(window.alert.length, 1);\nnameof.full(window.alert.length, 2);\nnameof.full(window.alert.length, -1);\nnameof.full(window.alert.length, -2);\nnameof.full(window.alert.length, -3);\n```\n\nTransforms to:\n\n```ts\n\"console.log\";\n\"alert.length\";\n\"length\";\n\"length\";\n\"alert.length\";\n\"window.alert.length\";\n```\n\n### `nameof.full\u003cT\u003e()`\n\n```ts\nnameof.full\u003cMyNamespace.MyInnerInterface\u003e();\nnameof.full\u003cMyNamespace.MyInnerInterface\u003e(1);\nnameof.full\u003cArray\u003cMyInterface\u003e\u003e();\n```\n\nTransforms to:\n\n```ts\n\"MyNamespace.MyInnerInterface\";\n\"MyInnerInterface\";\n\"Array\";\n```\n\n### `nameof.full\u003cT\u003e(o =\u003e ...)`\n\n```ts\nnameof.full\u003cMyInterface\u003e(o =\u003e o.prop.prop2);\nnameof.full\u003cMyInterface\u003e(o =\u003e o.prop.prop2.prop3, 1);\n```\n\nTransforms to:\n\n```ts\n\"prop.prop2\";\n\"prop2.prop3\";\n```\n\n### `nameof.interpolate(value)`\n\nWriting the following:\n\n```ts\nnameof.full(myObj.prop[i]);\n```\n\n...does not interpolate the node in the computed property.\n\n```ts\n\"myObj.prop[i]\";\n```\n\nIf you want to interpolate the value then you can specify that explicitly with a `nameof.interpolate` function.\n\n```ts\nnameof.full(myObj.prop[nameof.interpolate(i)]);\n```\n\nTransforms to:\n\n```ts\n`myObj.prop[${i}]`;\n```\n\n## nameof.toArray transform\n\nContributed by: [@cecilyth](https://github.com/cecilyth)\n\n### `nameof.toArray(...)`\n\n```ts\nnameof.toArray(myObject, otherObject);\nnameof.toArray(obj.firstProp, obj.secondProp, otherObject, nameof.full(obj.other));\n```\n\nTransforms to:\n\n```ts\n[\"myObject\", \"otherObject\"];\n[\"firstProp\", \"secondProp\", \"otherObject\", \"obj.other\"];\n```\n\n### `nameof.toArray\u003cT\u003e(o =\u003e [...])`\n\n```ts\nnameof.toArray\u003cMyType\u003e(o =\u003e [o.firstProp, o.otherProp.secondProp, o.other]);\nnameof.toArray\u003cMyType\u003e(o =\u003e [o.prop, nameof.full(o.myProp.otherProp, 1)]);\n```\n\nTransforms to:\n\n```ts\n[\"firstProp\", \"secondProp\", \"other\"];\n[\"prop\", \"myProp.otherProp\"];\n```\n\n## nameof.split transform\n\nContributed by: [@cecilyth](https://github.com/cecilyth)\n\n### `nameof.split(...)`\n\n```ts\nnameof.split(myObj.prop.prop2);\nnameof.split(myObj.prop.prop2, 1);\nnameof.split(myObj.prop.prop2, -1);\nnameof.split(myObj.prop.prop2).join(\"/\");\n```\n\nTransforms to:\n\n```ts\n[\"myObj\", \"prop\", \"prop2\"];\n[\"prop\", \"prop2\"];\n[\"prop2\"];\n[\"myObj\", \"prop\", \"prop2\"].join(\"/\"); // \"myObj/prop/prop2\"\n```\n\n### `nameof.split\u003cT\u003e(o =\u003e ...)`\n\n```ts\nnameof.split\u003cMyInterface\u003e(o =\u003e o.prop.prop2.prop3);\nnameof.split\u003cMyInterface\u003e(o =\u003e o.prop.prop2.prop3, 1);\nnameof.split\u003cMyInterface\u003e(o =\u003e o.prop.prop2.prop3, -1);\nnameof.split\u003cIState\u003e(s =\u003e s.a.b.c).join(\"/\");\n```\n\nTransforms to:\n\n```ts\n[\"prop\", \"prop2\", \"prop3\"];\n[\"prop2\", \"prop3\"];\n[\"prop3\"];\n[\"a\", \"b\", \"c\"].join(\"/\"); // \"a/b/c\"\n```\n\n## Other\n\n- [Contributing](CONTRIBUTING.md)\n- [Development](DEVELOPMENT.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsherret%2Fts-nameof","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdsherret%2Fts-nameof","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsherret%2Fts-nameof/lists"}