{"id":17472704,"url":"https://github.com/shinnn/node-strip-dirs","last_synced_at":"2025-04-09T22:54:14.201Z","repository":{"id":19821728,"uuid":"23082586","full_name":"shinnn/node-strip-dirs","owner":"shinnn","description":"Remove leading directory components from a path, like tar(1)'s --strip-components option","archived":false,"fork":false,"pushed_at":"2018-10-24T02:19:41.000Z","size":93,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T22:54:09.381Z","etag":null,"topics":["cross-platform","directory","javascript","nodejs","path","path-manipulation","string","strip","tar"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"hylexus/jt-808-protocol","license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinnn.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}},"created_at":"2014-08-18T18:53:56.000Z","updated_at":"2020-06-27T15:20:46.000Z","dependencies_parsed_at":"2022-08-25T20:11:39.103Z","dependency_job_id":null,"html_url":"https://github.com/shinnn/node-strip-dirs","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fnode-strip-dirs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fnode-strip-dirs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fnode-strip-dirs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fnode-strip-dirs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinnn","download_url":"https://codeload.github.com/shinnn/node-strip-dirs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125632,"owners_count":21051766,"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":["cross-platform","directory","javascript","nodejs","path","path-manipulation","string","strip","tar"],"created_at":"2024-10-18T17:34:18.559Z","updated_at":"2025-04-09T22:54:14.175Z","avatar_url":"https://github.com/shinnn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# strip-dirs\n\n[![npm version](https://img.shields.io/npm/v/strip-dirs.svg)](https://www.npmjs.com/package/strip-dirs)\n[![Build Status](https://img.shields.io/travis/shinnn/node-strip-dirs.svg)](https://travis-ci.org/shinnn/node-strip-dirs)\n[![Coverage Status](https://img.shields.io/coveralls/shinnn/node-strip-dirs.svg)](https://coveralls.io/github/shinnn/node-strip-dirs)\n\nRemove leading directory components from a path, like [tar(1)](http://linuxcommand.org/lc3_man_pages/tar1.html)'s `--strip-components` option\n\n```javascript\nconst stripDirs = require('strip-dirs');\n\nstripDirs('foo/bar/baz', 1); //=\u003e 'bar/baz'\nstripDirs('foo/bar/baz', 2); //=\u003e 'baz'\nstripDirs('foo/bar/baz', 999); //=\u003e 'baz'\n```\n\n## Installation\n\n[Use]((https://docs.npmjs.com/cli/install)) [npm](https://docs.npmjs.com/getting-started/what-is-npm).\n\n```\nnpm install strip-dirs\n```\n\n## API\n\n```javascript\nconst stripDirs = require('strip-dirs');\n```\n\n### stripDirs(*path*, *count* [, *option*])\n\n*path*: `string` (A relative path)  \n*count*: `integer` (\u003e= `0`)  \n*option*: `Object`  \nReturn: `string`\n\nIt removes directory components from the beginning of the *path* by *count*.\n\n```javascript\nconst stripDirs = require('strip-dirs');\n\nstripDirs('foo/bar', 1); //=\u003e 'bar'\nstripDirs('foo/bar/baz', 2); //=\u003e 'bar'\nstripDirs('foo/././/bar/./', 1); //=\u003e 'bar'\nstripDirs('foo/bar', 0); //=\u003e 'foo/bar'\n\nstripDirs('/foo/bar', 1) // throw an error because the path is an absolute path\n```\n\nIf you want to remove all directory components certainly, use [`path.basename`](https://nodejs.org/api/path.html#path_path_basename_path_ext) instead of this module.\n\n#### option.disallowOverflow\n\nType: `boolean`  \nDefault: `false`\n\nBy default, it keeps the last path component when path components are fewer than the *count*.\n\nIf this option is enabled, it throws an error in this situation.\n\n```javascript\nstripDirs('foo/bar/baz', 9999); //=\u003e 'baz'\n\nstripDirs('foo/bar/baz', 9999, {disallowOverflow: true}); // throws an range error\n```\n\n## License\n\n[ISC License](./LICENSE) © 2017 - 2018 Shinnosuke Watanabe\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fnode-strip-dirs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinnn%2Fnode-strip-dirs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fnode-strip-dirs/lists"}