UNPKG

1.74 kBJavaScriptView Raw
1var __importDefault = (this && this.__importDefault) || function (mod) {
2 return (mod && mod.__esModule) ? mod : { "default": mod };
3};
4(function (factory) {
5 if (typeof module === "object" && typeof module.exports === "object") {
6 var v = factory(require, exports);
7 if (v !== undefined) module.exports = v;
8 }
9 else if (typeof define === "function" && define.amd) {
10 define(["require", "exports", "bplist-parser", "plist"], factory);
11 }
12})(function (require, exports) {
13 "use strict";
14 Object.defineProperty(exports, "__esModule", { value: true });
15 exports.parse = void 0;
16 var bplist_parser_1 = __importDefault(require("bplist-parser"));
17 var plist_1 = __importDefault(require("plist"));
18 /**
19 * Detects the format of the given string or buffer, then attempts to parse the
20 * payload using the appropriate tooling.
21 */
22 function parse(aStringOrBuffer, aFile) {
23 var firstByte = aStringOrBuffer[0];
24 var results;
25 try {
26 if (firstByte === 60 || firstByte === "<") {
27 results = plist_1.default.parse(aStringOrBuffer.toString());
28 }
29 else if (firstByte === 98) {
30 results = bplist_parser_1.default.parseBuffer(aStringOrBuffer)[0];
31 }
32 else if (aFile) {
33 throw new Error("Unable to determine format for '" + aFile + "'");
34 }
35 else {
36 throw new Error("Unable to determine format for plist aStringOrBuffer");
37 }
38 }
39 catch (error) {
40 throw error instanceof Error ? error : new Error("error parsing " + aFile);
41 }
42 return results;
43 }
44 exports.parse = parse;
45});