版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # parse-filepath [![NPM version](https://img.shields.io/npm/v/parse-filepath.svg?style=flat)](https://www.npmjs.com/package/parse-filepath) [![NPM downloads](https://img.shields.io/npm/dm/parse-filepath.svg?style=flat)](https://npmjs.org/package/parse-filepath) [![Build Status](https://img.shields.io/travis/jonschlinkert/parse-filepath.svg?style=flat)](https://travis-ci.org/jonschlinkert/parse-filepath)
  2. > Pollyfill for node.js `path.parse`, parses a filepath into an object.
  3. You might also be interested in [global-prefix](https://github.com/jonschlinkert/global-prefix).
  4. ## Install
  5. Install with [npm](https://www.npmjs.com/):
  6. ```sh
  7. $ npm install parse-filepath --save
  8. ```
  9. ## Usage
  10. ```js
  11. var parsePath = require('parse-filepath');
  12. parsePath(filepath);
  13. ```
  14. This can be used as a polyfill for the native node.js `path.parse()` method, and it also adds a few properties:
  15. * `path`: the original filepath
  16. * `isAbsolute`: (getter) true if the given path is absolute
  17. * `absolute`: (getter) fully resolved, absolute filepath
  18. * `dirname`: alias for `dir`
  19. * `basename`: alias for `base`
  20. * `extname`: alias for `ext`
  21. * `stem`: alias for `name`
  22. **Example**
  23. ```js
  24. var parsePath = require('parse-filepath');
  25. console.log(parsePath('foo/bar/baz/index.js'));
  26. ```
  27. Returns:
  28. ```js
  29. { root: '',
  30. dir: 'foo/bar/baz',
  31. base: 'index.js',
  32. ext: '.js',
  33. name: 'index',
  34. // aliases
  35. extname: '.js',
  36. basename: 'index.js',
  37. dirname: 'foo/bar/baz',
  38. stem: 'index',
  39. // original path
  40. path: 'foo/bar/baz/index.js',
  41. // getters
  42. absolute: [Getter/Setter],
  43. isAbsolute: [Getter/Setter] }
  44. ```
  45. ## Related projects
  46. You might also be interested in these projects:
  47. * [global-prefix](https://www.npmjs.com/package/global-prefix): Get the npm global path prefix. | [homepage](https://github.com/jonschlinkert/global-prefix)
  48. * [is-absolute](https://www.npmjs.com/package/is-absolute): Polyfill for node.js `path.isAbolute`. Returns true if a file path is absolute. | [homepage](https://github.com/jonschlinkert/is-absolute)
  49. * [is-relative](https://www.npmjs.com/package/is-relative): Returns `true` if the path appears to be relative. | [homepage](https://github.com/jonschlinkert/is-relative)
  50. * [relative](https://www.npmjs.com/package/relative): Get the relative filepath from path A to path B. Calculates from file-to-directory, file-to-file, directory-to-file,… [more](https://www.npmjs.com/package/relative) | [homepage](https://github.com/jonschlinkert/relative)
  51. ## Contributing
  52. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/parse-filepath/issues/new).
  53. ## Building docs
  54. Generate readme and API documentation with [verb](https://github.com/verbose/verb):
  55. ```sh
  56. $ npm install verb && npm run docs
  57. ```
  58. Or, if [verb](https://github.com/verbose/verb) is installed globally:
  59. ```sh
  60. $ verb
  61. ```
  62. ## Running tests
  63. Install dev dependencies:
  64. ```sh
  65. $ npm install -d && npm test
  66. ```
  67. ## Author
  68. **Jon Schlinkert**
  69. * [github/jonschlinkert](https://github.com/jonschlinkert)
  70. * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
  71. ## License
  72. Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
  73. Released under the [MIT license](https://github.com/jonschlinkert/parse-filepath/blob/master/LICENSE).
  74. ***
  75. _This file was generated by [verb](https://github.com/verbose/verb), v, on March 29, 2016._