{"id":13726917,"url":"https://github.com/bsalex/typed-path","last_synced_at":"2025-04-09T06:13:20.126Z","repository":{"id":17654824,"uuid":"82240238","full_name":"bsalex/typed-path","owner":"bsalex","description":"Type safe object field string paths for typescript.","archived":false,"fork":false,"pushed_at":"2023-09-10T20:22:53.000Z","size":786,"stargazers_count":124,"open_issues_count":5,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-15T07:27:49.343Z","etag":null,"topics":["lodash","path","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsalex.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}},"created_at":"2017-02-17T00:37:13.000Z","updated_at":"2024-04-20T19:40:28.734Z","dependencies_parsed_at":"2024-04-23T08:06:35.455Z","dependency_job_id":null,"html_url":"https://github.com/bsalex/typed-path","commit_stats":{"total_commits":71,"total_committers":7,"mean_commits":"10.142857142857142","dds":0.3661971830985915,"last_synced_commit":"e0253e9a99b400623f3d892c7925b0ddf73df9ab"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsalex%2Ftyped-path","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsalex%2Ftyped-path/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsalex%2Ftyped-path/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsalex%2Ftyped-path/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsalex","download_url":"https://codeload.github.com/bsalex/typed-path/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247987285,"owners_count":21028895,"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":["lodash","path","typescript"],"created_at":"2024-08-03T01:03:31.332Z","updated_at":"2025-04-09T06:13:20.097Z","avatar_url":"https://github.com/bsalex.png","language":"TypeScript","readme":"# Typed Path\n\n[![https://nodei.co/npm/typed-path.svg?downloads=true\u0026downloadRank=true\u0026stars=true](https://nodei.co/npm/typed-path.svg?downloads=true\u0026downloadRank=true\u0026stars=true)](https://www.npmjs.com/package/typed-path)  \n\n[![Travis](https://img.shields.io/travis/bsalex/typed-path)](https://travis-ci.org/github/bsalex/typed-path)\n[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fbsalex%2Ftyped-path\u0026count_bg=%2379C83D\u0026title_bg=%23555555\u0026icon=\u0026icon_color=%23E7E7E7\u0026title=hits\u0026edge_flat=false)](https://hits.seeyoufarm.com)\n[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/bsalex/typed-path/issues)\n![GitHub top language](https://img.shields.io/github/languages/top/bsalex/typed-path)\n![David](https://img.shields.io/david/bsalex/typed-path)\n![npm bundle size](https://img.shields.io/bundlephobia/min/typed-path)\n![GitHub last commit](https://img.shields.io/github/last-commit/bsalex/typed-path)\n![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/bsalex/typed-path)\n[![GitHub issues](https://img.shields.io/github/issues/bsalex/typed-path)](https://github.com/bsalex/typed-path/issues)\n[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability-percentage/bsalex/typed-path)](https://codeclimate.com/github/bsalex/typed-path/)\n[![Code Climate technical debt](https://img.shields.io/codeclimate/tech-debt/bsalex/typed-path)](https://codeclimate.com/github/bsalex/typed-path/)\n[![codecov](https://codecov.io/gh/bsalex/typed-path/branch/master/graph/badge.svg?token=uzpVtSWKbv)](https://codecov.io/gh/bsalex/typed-path)\n---\n  \n## Overview\n\nThis small utility helps to extract type information from a TypeScript class, interface or type to use it in your code. \n\nExample:\n\n```js\nimport {typedPath} from 'typed-path';\n\ntype TestType = {\n    a: {\n        testFunc: () =\u003e {result: string};\n        b: {\n            arrayOfArrays: string[][];\n            c: {\n                d: number;\n            };\n        }[];\n    };\n};\n\nconsole.log(typedPath\u003cTestType\u003e().a.b[5].c.d.$rawPath);\n/*\nOutputs\n[\"a\", \"b\", 5, \"c\", \"d\"]\n\n*/\n```\nPlease see other path access methods and how to add custom path access methods below.\n\nThe utility might also be used to add type protection to such methods as `_.get, _.map, _.set, R.pluck` from libraries like [lodash](https://lodash.com), [ramda](http://ramdajs.com/).  \n\n**It is recommended, though, to use [optional chaining](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#optional-chaining) instead.**\n\n\n---\n\n## Features\n\n### Errors\n\nWith `typed-path`, typescript can check paths and warns you about errors.\n\n![](http://res.cloudinary.com/daren64mz/image/upload/v1487457505/tp-refactoring_p4byr3.gif)\n\n### Path access methods\n#### Default\n##### .$path\n[@m-abboud](https://github.com/m-abboud)  \nAlso, you can get access to the path string using `$path` special field. \n\nLike this:\n```js\n    console.log(tp\u003cTestType\u003e().a.b.c.d.$path); // this will output \"a.b.c.d\"\n```\n\n##### .$raw\n[@dcbrwn](https://github.com/dcbrwn)  \nIf you need a raw path, which is of type `string[]` - you can get it using `$raw` special field.  \n*Deprecated, since it transforms symbols and numbers to strings, which might be not an expected behavior (the method name is \"raw\").\nPlease use `.$rawPath`*\n```js\n    console.log(tp\u003cTestType\u003e().a.b.c.d.$raw); // this will output [\"a\", \"b\", \"c\", \"d\"]\n```\n\n##### .$rawPath\nIf you need a raw path, which is of type `(string | number | Symbol)[]` - you can get it using `$rawPath` special field.  \n```js\n    console.log(tp\u003cTestType\u003e().a.b[5].c.d.$rawPath); // this will output [\"a\", \"b\", 5, \"c\", \"d\"]\n```\n\nThe `$rawPath` is something that you might want to use with the following methods from\nRamda, to add type safety on the path:\n- [R.assocPath](https://ramdajs.com/docs/#assocPath),\n- [R.dissocPath](https://ramdajs.com/docs/#dissocPath),\n- [R.hasPath](https://ramdajs.com/docs/#hasPath),\n- [R.path](https://ramdajs.com/docs/#path),\n- [R.pathEq](https://ramdajs.com/docs/#pathEq),\n- [R.pathOr](https://ramdajs.com/docs/#pathOr),\n- [R.paths](https://ramdajs.com/docs/#paths),\n- [R.lensPath](https://ramdajs.com/docs/#lensPath)\n\nExample: [https://codesandbox.io/s/typed-path-ramda-assoc-path-x3qby?file=/src/index.ts](https://codesandbox.io/s/typed-path-ramda-assoc-path-x3qby?file=/src/index.ts)\n\n#### Additional handlers \n[@nick-lvov-dev](https://github.com/nick-lvov-dev)\n\nYou can extend path handlers functionality using additional handlers:\n\n```js\nconst testAdditionalHandlers = {\n    $url: (path: TypedPathKey[]) =\u003e path.join('/')\n}\n\nconsole.log(tp\u003cTestType, typeof testAdditionalHandlers\u003e(testAdditionalHandlers).a.b.c.$url); // this will output \"a/b/c\"\n```\n\nThe additional handlers are also chainable:\n\n```js\nconst testAdditionalHandlers = {\n    $abs: (path: TypedPathKey[]) =\u003e typedPath\u003cTestType, typeof testAdditionalHandlers\u003e(testAdditionalHandlers, ['', ...path]),\n    $url: (path: TypedPathKey[]) =\u003e path.join('/'),\n    $length: (path: TypedPathKey[]) =\u003e path.length\n}\n\nconsole.log(tp\u003cTestType, typeof testAdditionalHandlers\u003e(testAdditionalHandlers).a.b.c.$abs.$url); // this will output \"/a/b/c\"\n```\n\n--- \n\n### Suggestions\n\nAlso, `typed-path` allows typescript to suggest field names for you.\n\n![](http://res.cloudinary.com/daren64mz/image/upload/v1487458263/tp-suggestions_lg5vnb.gif)\n\n## License\n\nCopyright (c) 2021 Oleksandr Beshchuk \u003c[bs.alex.mail@gmail.com](mailto:bs.alex.mail@gmail.com)\u003e  \nLicensed under the [Apache License](http://www.apache.org/licenses/LICENSE-2.0).\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsalex%2Ftyped-path","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsalex%2Ftyped-path","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsalex%2Ftyped-path/lists"}