extract-base-iterator
Version:
Base iterator for extract iterators like tar-iterator and zip-iterator
9 lines (8 loc) • 417 B
JavaScript
import path from 'path';
export default function stripPath(relativePath, options) {
const strip = options.strip || 0;
if (!strip) return relativePath;
const parts = relativePath.split(path.sep).filter(Boolean);
if (parts.length < strip) throw new Error(`You cannot strip more levels than there are directories. Strip: ${strip}. Path: ${relativePath}`);
return parts.slice(strip).join(path.sep);
}