90 lines
3.1 KiB
JavaScript
90 lines
3.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Configuration = void 0;
|
|
const validator_1 = require("./validator");
|
|
const DEFAULT_CONFIG = {
|
|
segmentTerminator: 39,
|
|
dataElementSeparator: 43,
|
|
componentDataSeparator: 58,
|
|
decimalMark: 46,
|
|
releaseCharacter: 63,
|
|
lineFeed: 10,
|
|
carriageReturn: 13,
|
|
endOfTag: 4,
|
|
validator: new validator_1.ValidatorImpl()
|
|
};
|
|
class Configuration {
|
|
constructor(config) {
|
|
this.config = this.mergeWithDefault(config);
|
|
if (config && config.charset) {
|
|
this.charset = config.charset;
|
|
}
|
|
else {
|
|
this.charset = "UNOA";
|
|
}
|
|
this.validator = this.config.validator;
|
|
}
|
|
mergeWithDefault(config) {
|
|
const conf = Object.assign({}, DEFAULT_CONFIG);
|
|
if (config) {
|
|
if (config.segmentTerminator) {
|
|
conf.segmentTerminator = config.segmentTerminator;
|
|
}
|
|
if (config.dataElementSeparator) {
|
|
conf.dataElementSeparator = config.dataElementSeparator;
|
|
}
|
|
if (config.componentDataSeparator) {
|
|
conf.componentDataSeparator = config.componentDataSeparator;
|
|
}
|
|
if (config.decimalMark) {
|
|
conf.decimalMark = config.decimalMark;
|
|
}
|
|
if (config.releaseCharacter) {
|
|
conf.releaseCharacter = config.releaseCharacter;
|
|
}
|
|
if (config.lineFeed) {
|
|
conf.lineFeed = config.lineFeed;
|
|
}
|
|
if (config.carriageReturn) {
|
|
conf.carriageReturn = config.carriageReturn;
|
|
}
|
|
if (config.endOfTag) {
|
|
conf.endOfTag = config.endOfTag;
|
|
}
|
|
if (config.validator) {
|
|
conf.validator = config.validator;
|
|
}
|
|
}
|
|
return conf;
|
|
}
|
|
delimiters() {
|
|
const compareAndSwap = function (array, a, b) {
|
|
if (array[a] > array[b]) {
|
|
array[a] = array[a] ^ array[b];
|
|
array[b] = array[a] ^ array[b];
|
|
array[a] = array[a] ^ array[b];
|
|
}
|
|
};
|
|
const exclude = [this.config.segmentTerminator, this.config.dataElementSeparator, this.config.componentDataSeparator, this.config.releaseCharacter];
|
|
compareAndSwap(exclude, 1, 2);
|
|
compareAndSwap(exclude, 3, 4);
|
|
compareAndSwap(exclude, 1, 3);
|
|
compareAndSwap(exclude, 0, 2);
|
|
compareAndSwap(exclude, 2, 4);
|
|
compareAndSwap(exclude, 0, 3);
|
|
compareAndSwap(exclude, 0, 1);
|
|
compareAndSwap(exclude, 2, 3);
|
|
compareAndSwap(exclude, 1, 2);
|
|
return exclude;
|
|
}
|
|
toString() {
|
|
let result = this.charset;
|
|
result += String.fromCharCode(this.config.componentDataSeparator, this.config.decimalMark, this.config.releaseCharacter, this.config.segmentTerminator);
|
|
return result;
|
|
}
|
|
updateCharset(charset) {
|
|
this.charset = charset;
|
|
}
|
|
}
|
|
exports.Configuration = Configuration;
|
|
//# sourceMappingURL=configuration.js.map
|