diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-04-27 13:24:51 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-04-27 13:24:51 +0100 |
| commit | 4bd14e9b3de8e7077e013f652712058e37f3e261 (patch) | |
| tree | 7d87fc8f805093d3c05d4c9aace07d6472b00ba7 /lib/docx/files.js | |
| parent | 5ac58a1269b3d5e55adb17730cd965ace7970b11 (diff) | |
Don't use path module in browser builds
Diffstat (limited to 'lib/docx/files.js')
| -rw-r--r-- | lib/docx/files.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/docx/files.js b/lib/docx/files.js index 6380ea4..502db08 100644 --- a/lib/docx/files.js +++ b/lib/docx/files.js @@ -1,6 +1,7 @@ var fs = require("fs"); var url = require("url"); var os = require("os"); +var dirname = require("path").dirname; var resolvePath = require("path").resolve; var isAbsolutePath = require('path-is-absolute'); @@ -20,7 +21,7 @@ function Files(base) { }); }); } - + function resolveUri(uri) { var path = uriToPath(uri); if (isAbsolutePath(path)) { @@ -31,12 +32,20 @@ function Files(base) { return promises.reject(new Error("could not find external image '" + uri + "', path of input document is unknown")); } } - + return { read: read }; } + +function relativeToFile(filePath) { + return new Files(dirname(filePath)); +} + +Files.relativeToFile = relativeToFile; + + var readFile = promises.promisify(fs.readFile.bind(fs)); @@ -44,7 +53,7 @@ function uriToPath(uriString, platform) { if (!platform) { platform = os.platform(); } - + var uri = url.parse(uriString); if (isLocalFileUri(uri) || isRelativeUri(uri)) { var path = decodeURIComponent(uri.path); |
