@barchart/common-js
Version:
Library of common JavaScript utilities
109 lines (103 loc) • 3.7 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ComponentBuilder_exports = {};
__export(ComponentBuilder_exports, {
default: () => ComponentBuilder
});
module.exports = __toCommonJS(ComponentBuilder_exports);
var assert = __toESM(require("./../../../lang/assert.js"));
var import_Component = __toESM(require("./../Component.js"));
var import_DataType = __toESM(require("./../DataType.js"));
var import_Field = __toESM(require("./../Field.js"));
class ComponentBuilder {
#component;
#name;
/**
* @param {string} name - The name of the schema
*/
constructor(name) {
this.#component = new import_Component.default(name);
}
/**
* The {@link Schema} current schema instance.
*
* @public
* @returns {Component}
*/
get component() {
return this.#component;
}
/**
* Adds a new {@link Field} to the schema and returns the current instance.
*
* @public
* @param {string} name
* @param {DataType} dataType
* @returns {ComponentBuilder}
*/
withField(name, dataType) {
assert.argumentIsRequired(name, "name", String);
assert.argumentIsRequired(dataType, "dataType", import_DataType.default, "DataType");
const fields = this.#component.fields.concat([new import_Field.default(name, dataType)]);
this.#component = new import_Component.default(this.#component.name, fields, this.#component.reviver);
return this;
}
/**
* Adds a "reviver" function for use with JSON.parse.
*
* @public
* @param {Function} reviver
* @returns {ComponentBuilder}
*/
withReviver(reviver) {
assert.argumentIsRequired(reviver, "reviver", Function);
this.#component = new import_Component.default(this.#component.name, this.#component.fields, reviver);
return this;
}
/**
* Returns a string representation.
*
* @public
* @returns {string}
*/
toString() {
return `[ComponentBuilder (name=${this.#name})]`;
}
}
{
const cjsExports = module.exports;
const cjsDefaultExport = cjsExports && cjsExports.__esModule ? cjsExports.default : cjsExports;
if (cjsDefaultExport && (typeof cjsDefaultExport === 'function' || typeof cjsDefaultExport === 'object')) {
Object.keys(cjsExports).forEach((key) => {
if (key !== 'default' && key !== '__esModule') {
cjsDefaultExport[key] = cjsExports[key];
}
});
}
module.exports = cjsDefaultExport;
}