index.js 703 B

12345678910111213141516171819202122232425
  1. var currentPlatform = process !== void 0 ? process.platform : '';
  2. function isAbsolute (path) {
  3. if (currentPlatform === 'win32') {
  4. // Regex to split a windows path into three parts: [*, device, slash,
  5. // tail] windows-only
  6. var splitDeviceRe =
  7. /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  8. var result = splitDeviceRe.exec(path),
  9. device = result[1] || '',
  10. isUnc = device && device.charAt(1) !== ':';
  11. // UNC paths are always absolute
  12. return !!result[2] || isUnc;
  13. } else {
  14. return path.charAt(0) === '/';
  15. }
  16. }
  17. module.exports = isAbsolute;
  18. isAbsolute.setPlatform = function (platform) {
  19. currentPlatform = platform;
  20. };