UNPKG

@signatu/common-lib

Version:

Common Javascript/Typescript library for Signatu

43 lines 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // This is basically a map keyed on language var Metadata = /** @class */ (function () { function Metadata(metadata) { if (metadata === void 0) { metadata = {}; } // Copy metadata onto this Object.assign(this, JSON.parse(JSON.stringify(metadata))); } /** All languages */ Metadata.prototype.add = function (key, value, language) { var metadata = this; var rootKey = language ? language.isoLanguage : 'ALL_LANGUAGES'; var root = metadata[rootKey] = metadata[rootKey] || {}; root[key] = value; }; Metadata.prototype.get = function (key, language) { var metadata = this; var rootKey = language ? language.isoLanguage : 'ALL_LANGUAGES'; var root = metadata[rootKey] = metadata[rootKey] || {}; return root[key]; }; /** Deprecated */ Metadata.prototype.addForLanguage = function (language, newMetadata) { var metadata = this; metadata[language.isoLanguage] = newMetadata; }; Metadata.prototype.getForLanguage = function (language) { var metadata = this; var m = metadata[language.isoLanguage]; // Copy it. return m ? JSON.parse(JSON.stringify(m)) : {}; }; Metadata.prototype.toJSON = function () { return this; }; Metadata.fromJSON = function (data) { return new Metadata(data); }; return Metadata; }()); exports.Metadata = Metadata; //# sourceMappingURL=metadata.js.map