Ingen beskrivning

index.js 862B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. var isRelative = require('is-relative');
  3. var isWindows = require('is-windows');
  4. /**
  5. * Expose `isAbsolute`
  6. */
  7. module.exports = isAbsolute;
  8. /**
  9. * Returns true if a file path is absolute.
  10. *
  11. * @param {String} `fp`
  12. * @return {Boolean}
  13. */
  14. function isAbsolute(fp) {
  15. if (typeof fp !== 'string') {
  16. throw new TypeError('isAbsolute expects a string.');
  17. }
  18. return isWindows() ? isAbsolute.win32(fp) : isAbsolute.posix(fp);
  19. }
  20. /**
  21. * Test posix paths.
  22. */
  23. isAbsolute.posix = function posixPath(fp) {
  24. return fp.charAt(0) === '/';
  25. };
  26. /**
  27. * Test windows paths.
  28. */
  29. isAbsolute.win32 = function win32(fp) {
  30. if (/[a-z]/i.test(fp.charAt(0)) && fp.charAt(1) === ':' && fp.charAt(2) === '\\') {
  31. return true;
  32. }
  33. // Microsoft Azure absolute filepath
  34. if (fp.slice(0, 2) === '\\\\') {
  35. return true;
  36. }
  37. return !isRelative(fp);
  38. };