UNPKG

language-manager-ts

Version:

A language manager for web application with typescript

59 lines (58 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StorageServer = exports.StorageClient = void 0; var isNode = true; var _process; try { _process = eval("process"); // avoid browserify shim } catch (e) { } var isNode = typeof _process === "object" && _process.toString() === "[object process]"; var fs = isNode ? require("fs") : undefined; var path = isNode ? require("path") : undefined; var StorageClient = /** @class */ (function () { function StorageClient() { } StorageClient.prototype.getItem = function (key) { return localStorage.getItem(key); }; StorageClient.prototype.setItem = function (item, key) { localStorage.setItem(key, item); }; return StorageClient; }()); exports.StorageClient = StorageClient; var StorageServer = /** @class */ (function () { /** * * @param path path for localization settings file */ function StorageServer(path) { this._path = ''; this._path = path; } /** * * @param key useless */ StorageServer.prototype.getItem = function (key) { if (key === void 0) { key = ""; } var filePath = path.join(this._path, "lang-file"); if (fs.existsSync(filePath)) { var val = fs.readFileSync(filePath, { encoding: "utf8" }); return val !== undefined ? val : null; } return null; }; /** * set an item for storage server * @param item the value * @param key useless */ StorageServer.prototype.setItem = function (item, key) { if (key === void 0) { key = ""; } fs.writeFileSync(path.join(this._path, "lang-file"), item, { encoding: "utf8" }); }; return StorageServer; }()); exports.StorageServer = StorageServer;