index.js 322 B

1234567891011121314151617
  1. var isWin = process.platform === 'win32';
  2. module.exports = function (str) {
  3. var i = str.length - 1;
  4. if (i < 2) {
  5. return str;
  6. }
  7. while (isSeparator(str, i)) {
  8. i--;
  9. }
  10. return str.substr(0, i + 1);
  11. };
  12. function isSeparator(str, i) {
  13. var char = str[i];
  14. return i > 0 && (char === '/' || (isWin && char === '\\'));
  15. }