utils.js 307 B

12345678910
  1. 'use strict';
  2. const path = require('path');
  3. // judge if parent is child's parent path
  4. // isEqualOrParentPath('/foo', '/foo/bar') => true
  5. // isEqualOrParentPath('/foo/bar', '/foo') => false
  6. exports.isEqualOrParentPath = function(parent, child) {
  7. return !path.relative(parent, child).startsWith('..');
  8. };