index.js 424 B

123456789101112131415161718192021
  1. /*!
  2. * path-root <https://github.com/jonschlinkert/path-root>
  3. *
  4. * Copyright (c) 2016, Jon Schlinkert.
  5. * Licensed under the MIT License.
  6. */
  7. 'use strict';
  8. var pathRootRegex = require('path-root-regex');
  9. module.exports = function(filepath) {
  10. if (typeof filepath !== 'string') {
  11. throw new TypeError('expected a string');
  12. }
  13. var match = pathRootRegex().exec(filepath);
  14. if (match) {
  15. return match[0];
  16. }
  17. };