UNPKG

app-info-parser2

Version:

Exact info from apk or ipa file.

49 lines (40 loc) 1.82 kB
'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var ApkParser = require('./apk'); var IpaParser = require('./ipa'); var supportFileTypes = ['ipa', 'apk']; var AppInfoParser = function () { /** * * @param {String | File | Blob} file // node:file path,browser: file or blob */ function AppInfoParser(file) { _classCallCheck(this, AppInfoParser); if (!file) { throw new Error('Param miss: file(file path in Node, File or Blob in browser).'); } var splits = (file.name || file).split('.'); var fileType = splits[splits.length - 1].toLowerCase(); if (!supportFileTypes.includes(fileType)) { throw new Error('Unsupport file type, only support .ipa or .apk file.'); } this.file = file; switch (fileType) { case 'ipa': this.parser = new IpaParser(this.file); break; case 'apk': this.parser = new ApkParser(this.file); break; } } _createClass(AppInfoParser, [{ key: 'parse', value: function parse() { return this.parser.parse(); } }]); return AppInfoParser; }(); module.exports = AppInfoParser;