From 9196e8bc6f2ff2c59a9b4fde4813e7bc26b8c23d Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 26 Jan 2018 23:21:49 +0000 Subject: Extract joinPath and splitPath for zip files --- lib/zipfile.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/zipfile.js') diff --git a/lib/zipfile.js b/lib/zipfile.js index 7c534c7..ae51310 100644 --- a/lib/zipfile.js +++ b/lib/zipfile.js @@ -3,6 +3,8 @@ var JSZip = require("jszip"); var promises = require("./promises"); exports.openArrayBuffer = openArrayBuffer; +exports.splitPath = splitPath; +exports.joinPath = joinPath; function openArrayBuffer(arrayBuffer) { var zipFile = new JSZip(arrayBuffer); @@ -35,3 +37,21 @@ function openArrayBuffer(arrayBuffer) { toBuffer: toBuffer }; } + +function splitPath(path) { + var lastIndex = path.lastIndexOf("/"); + if (lastIndex === -1) { + return {dirname: "", basename: path}; + } else { + return { + dirname: path.substring(0, lastIndex), + basename: path.substring(lastIndex + 1) + }; + } +} + +function joinPath() { + return Array.prototype.filter.call(arguments, function(path) { + return path; + }).join("/"); +} -- cgit v1.2.3