{"id":18870345,"url":"https://github.com/streetstrider/rootpath","last_synced_at":"2026-04-25T21:31:55.877Z","repository":{"id":15211893,"uuid":"17940341","full_name":"StreetStrider/rootpath","owner":"StreetStrider","description":"pivot point for path hierarchy in Node.js projects","archived":false,"fork":false,"pushed_at":"2024-01-26T01:09:17.000Z","size":147,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-12T12:47:05.479Z","etag":null,"topics":["flow","glob","isc","node","path","path-join","rootpath","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/StreetStrider.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":"2014-03-20T11:40:29.000Z","updated_at":"2022-02-01T22:26:41.000Z","dependencies_parsed_at":"2024-01-25T22:31:20.442Z","dependency_job_id":"4bd4faf5-c787-4190-9605-a31bd9235a8c","html_url":"https://github.com/StreetStrider/rootpath","commit_stats":{"total_commits":241,"total_committers":2,"mean_commits":120.5,"dds":"0.20746887966804983","last_synced_commit":"7f7a755360ce158cd6df80d7d0ce87394933d672"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Frootpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Frootpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Frootpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Frootpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StreetStrider","download_url":"https://codeload.github.com/StreetStrider/rootpath/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239816505,"owners_count":19701753,"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":["flow","glob","isc","node","path","path-join","rootpath","typescript"],"created_at":"2024-11-08T05:19:48.649Z","updated_at":"2026-02-14T17:30:14.007Z","avatar_url":"https://github.com/StreetStrider.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rootpath\n\n[![ISC licensed](http://img.shields.io/badge/license-ISC-brightgreen.svg?style=flat-square)](#license)\n[![typescript](http://img.shields.io/badge/type-script-0074C1.svg?style=flat-square)](#types)\n[![npm|@streetstrider/rootpath](http://img.shields.io/badge/npm-@streetstrider/rootpath-CB3837.svg?style=flat-square)](https://www.npmjs.org/package/@streetstrider/rootpath)\n\nAddress Node.js project's files relatively to project's root.\n\n## usage\nConsider the following structure:\n\n```sh\nproject/\n  cfg/\n    config.json\n  src/\n    App.js\n```\n\nIf you want to address config from App you could use composition of `__dirname`, path joining and relative paths. This becomes messy and uncontrollable very quickly. There's a place for an abstraction which would encapsulate point in fs hierarchy and allow to construct paths and address files in clean and easy manner.\n\nApp.js:\n```javascript\nimport rootpath from '@streetstrider/rootpath'\n\nfunction App ()\n{\n  /* with rootpath: */\n  this.fromroot = rootpath()\n  /*\n   * which means: \"pinpoint project's root directory (where package.json).\"\n   */\n\n  /* it is also possible to supply path or path segments manually */\n  this.fromroot = rootpath(__dirname, '..')\n  /* or */\n  this.fromroot = rootpath([ __dirname, '..' ])\n  /* or */\n  this.fromroot = rootpath(__dirname + '/..')\n  /* or in ESM you can take pinpoint dirname of import.meta.url's path */\n  /* file:/// is handled correctly */\n  this.fromroot = rootpath(import.meta.url)\n\n  /* on this point `fromroot` becomes a pivot for addressing */\n  this.config = load(this.fromroot('cfg', 'config.json'))\n  /* or */\n  this.config = load(this.fromroot([ 'cfg', 'config.json' ]))\n  /* or */\n  this.config = load(this.fromroot('cfg/config.json'))\n\n  /* you also can use `rootpath#resolve` as an explicit analogue */\n  this.config   = load(this.fromroot.resolve('cfg', 'config.json')\n\n  /* if you need to create concretized view onto fs, use `rootpath#partial`: */\n  this.someModel = new SomeModel(this.fromroot.partial('data/model'))\n  /* this creates new instance of rootpath, focused on `data/model` */\n\n  /* get path in the space of rootpath */\n  const relpath = this.fromroot.relative(some_abspath)\n\n  /* check if some path is not above rootpath */\n  this.fromroot.contains(some_path)\n\n  /* assert that some path not above rootpath */\n  this.fromroot.guard(some_path)\n\n  /* map paths iterable over rootpath */\n  this.fromroot.over(paths)\n}\n```\n\n## install\n```\nnpm install @streetstrider/rootpath\n```\n\n## API\nBehavior of this module is similar to std's `path#resolve`. In addition it also flattens any arrays found in arguments. It will resolve path relative to `process.cwd()` if path would not be absolute after all computations. This also include glob support and glob negation.\n\n```javascript\n// rootpath with package root or process.cwd() if not inside package.\n// any path may be also a glob, including negative glob\nnew Rootpath(), Rootpath()\n\n// rootpath with given path root\nnew Rootpath(path, ...), Rootpath(path, ...)\n\n// resolve paths relative to root\nrootpath.resolve(path, ...), rootpath(path, ...)\n\n// create new rootpath relative to root + given path\nrootpath.partial(path, ...)\n\n// get relative path from root\nrootpath.relative(path)\n\n// does this rootpath contains path as a subpath\nroootpath.contains(path)\n\n// root path of instance can be received via String/toString\nconst base = String(rootpath)\n\n// one instance can be directly used as base for another\nconst rootpath = Rootpath(another_rootpath, 'some/path')\n```\n\n## types\nWe're providing built-in [TypeScript](http://typescriptlang.org/) \u0026 [Flow](https://flowtype.org/) type definitions.\n\n## license\nISC. © Strider, 2013 — 2024.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreetstrider%2Frootpath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreetstrider%2Frootpath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreetstrider%2Frootpath/lists"}