CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
bom-handling.js49 linesDownload Raw Back to lib
1"use strict"2 3var BOMChar = "\uFEFF"4 5exports.PrependBOM = PrependBOMWrapper6function PrependBOMWrapper (encoder, options) {7  this.encoder = encoder8  this.addBOM = true9}10 11PrependBOMWrapper.prototype.write = function (str) {12  if (this.addBOM) {13    str = BOMChar + str14    this.addBOM = false15  }16 17  return this.encoder.write(str)18}19 20PrependBOMWrapper.prototype.end = function () {21  return this.encoder.end()22}23 24// ------------------------------------------------------------------------------25 26exports.StripBOM = StripBOMWrapper27function StripBOMWrapper (decoder, options) {28  this.decoder = decoder29  this.pass = false30  this.options = options || {}31}32 33StripBOMWrapper.prototype.write = function (buf) {34  var res = this.decoder.write(buf)35  if (this.pass || !res) { return res }36 37  if (res[0] === BOMChar) {38    res = res.slice(1)39    if (typeof this.options.stripBOM === "function") { this.options.stripBOM() }40  }41 42  this.pass = true43  return res44}45 46StripBOMWrapper.prototype.end = function () {47  return this.decoder.end()48}49