noodl-loader
Version:
Loader for noodl applications
63 lines • 1.8 kB
JavaScript
"use strict";
var _Asset_id, _Asset_props;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
class Asset {
[(_Asset_id = new WeakMap(), _Asset_props = new WeakMap(), Symbol.for('nodejs.util.inspect.custom'))]() {
return this.toJSON();
}
constructor(type) {
_Asset_id.set(this, '');
_Asset_props.set(this, {});
this.type = '';
if (type)
this.type = type;
}
get props() {
return tslib_1.__classPrivateFieldGet(this, _Asset_props, "f");
}
clear() {
for (const key of Object.keys(this.props)) {
delete this.props[key];
}
return this;
}
get(key) {
return tslib_1.__classPrivateFieldGet(this, _Asset_props, "f")[key];
}
set(key, value) {
tslib_1.__classPrivateFieldGet(this, _Asset_props, "f")[key] = value;
return this;
}
getId() {
return tslib_1.__classPrivateFieldGet(this, _Asset_id, "f");
}
setId(id) {
tslib_1.__classPrivateFieldSet(this, _Asset_id, id, "f");
return this;
}
merge(...objs) {
for (const obj of objs) {
for (const [key, value] of Object.entries(obj)) {
this.set(key, value);
}
}
return this.props;
}
remove(key) {
delete this.props[key];
return this;
}
toJSON() {
return {
type: this.type,
id: this.getId(),
props: tslib_1.__classPrivateFieldGet(this, _Asset_props, "f"),
};
}
toString() {
return JSON.stringify(this.toJSON(), null, 2);
}
}
exports.default = Asset;
//# sourceMappingURL=asset.js.map