UNPKG

@enonic/mock-xp

Version:

Mock Enonic XP API JavaScript Library

61 lines (60 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LibIo = void 0; var isString_1 = require("@enonic/js-utils/value/isString"); var LibIo = (function () { function LibIo(_a) { var app = _a.app; this.app = app; } LibIo.prototype.getMimeType = function (name) { var parts = name.split('.'); var ext = parts[parts.length - 1]; switch (ext) { case 'css': return 'text/css'; case 'ico': return 'image/x-icon'; case 'jpg': return 'image/jpeg'; case 'js': return 'application/javascript'; case 'json': return 'application/json'; case 'gif': return 'image/gif'; case 'html': return 'text/html'; case 'png': return 'image/png'; case 'svg': return 'image/svg+xml'; case 'txt': return 'text/plain'; case 'xml': return 'application/xml'; default: return 'application/octet-stream'; } }; LibIo.prototype.getResource = function (key) { return this.app.getResource((0, isString_1.isString)(key) ? key : key.getPath()); }; LibIo.prototype.getSize = function (stream) { return stream.length; }; LibIo.prototype.newStream = function (text) { return Buffer.from(text); }; LibIo.prototype.processLines = function (stream, func) { stream.toString().split('\n').forEach(func); }; LibIo.prototype.readLines = function (stream) { return stream.toString().split('\n'); }; LibIo.prototype.readText = function (stream) { return stream.toString(); }; return LibIo; }()); exports.LibIo = LibIo;