@ezs/basics
Version:
Basics statements for EZS
59 lines (57 loc) • 1.31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _string_decoder = require("string_decoder");
var _bib2json = _interopRequireDefault(require("bib2json"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function BIBParse(data, feed) {
if (!this.decoder) {
this.decoder = new _string_decoder.StringDecoder('utf8');
this.remainder = '';
this.counter = 0;
this.parser = new _bib2json.default(entry => {
feed.write(entry);
});
}
if (this.isLast()) {
this.remainder += this.decoder.end();
if (this.remainder && this.counter > 1) {
this.parser.parse(this.remainder);
}
return feed.close();
}
let chunk;
if (Buffer.isBuffer(data)) {
chunk = this.decoder.write(data);
} else if (typeof data === 'string') {
chunk = data;
} else {
chunk = '';
}
this.parser.parse(chunk);
this.counter += 1;
feed.end();
}
/**
* Take a `String` and split it at bibtext entry.
*
* Input:
*
* ```json
* ["@article{my_article,\ntitle = {Hello world},\n", "journal = \"Some Journal\"\n"]
* ```
*
* Output:
*
* ```json
* ["a", "b", "c", "d"]
* ```
*
* @name BIBParse
* @returns {Object}
*/
var _default = exports.default = {
BIBParse
};