UNPKG

keynote-parser2

Version:

A library for parsing Apple Keynote file

35 lines (34 loc) 1.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parse = void 0; const decompress_1 = __importDefault(require("decompress")); const fs_extra_1 = __importDefault(require("fs-extra")); const utils_1 = require("../utils"); const parse_iwa_1 = require("./parse-iwa"); /** * Parse and output a keynote file * * @see https://github.com/obriensp/iWorkFileFormat/blob/master/Docs/index.md#bundle */ const parse = async (inputPath, outputPath = `${inputPath}.parsed`) => { // avoid output path conflict if (await fs_extra_1.default.pathExists(outputPath)) { throw new Error(`Output path already exists: ${outputPath}`); } // unzip keynote file and parse iwa files await (0, decompress_1.default)(inputPath, outputPath, { map: (file) => { if (!(0, utils_1.isIwaFile)(file.path)) return file; return { ...file, data: Buffer.from(JSON.stringify((0, parse_iwa_1.parseIwa)(file.data), null, 2)), path: `${file.path}.json`, }; }, }); }; exports.parse = parse;