How to use the whatwg-encoding.getBOMEncoding function in whatwg-encoding

To help you get started, we’ve selected a few whatwg-encoding examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jsdom / jsdom / lib / jsdom / browser / old-resource-loader.js View on Github external
readableStream.on("end", () => {
    // Not passing default encoding means binary
    if (defaultEncoding) {
      const encoding = detectMetaCharset ?
                       sniffHTMLEncoding(data, { defaultEncoding }) :
                       whatwgEncoding.getBOMEncoding(data) || defaultEncoding;
      const decoded = whatwgEncoding.decode(data, encoding);
      callback(null, decoded, { headers: { "content-type": "text/plain;charset=" + encoding } });
    } else {
      callback(null, data);
    }
  });
github sx1989827 / DOClever / node_modules / jsdom / lib / jsdom / living / file-api / FileReader-impl.js View on Github external
switch (format) {
          default:
          case "buffer": {
            this.result = (new Uint8Array(data)).buffer;
            break;
          }
          case "binaryString": {
            this.result = data.toString("binary");
            break;
          }
          case "dataURL": {
            // Spec seems very unclear here; see https://github.com/whatwg/fetch/issues/665#issuecomment-362930079.
            let dataUrl = "data:";
            const contentType = MIMEType.parse(file.type);
            if (contentType && contentType.type === "text") {
              const fallbackEncoding = whatwgEncoding.getBOMEncoding(data) ||
                whatwgEncoding.labelToName(contentType.parameters.get("charset")) || "UTF-8";
              const decoded = whatwgEncoding.decode(data, fallbackEncoding);

              contentType.parameters.set("charset", encoding);
              dataUrl += contentType.toString();
              dataUrl += ",";
              dataUrl += querystring.escape(decoded);
            } else {
              if (contentType) {
                dataUrl += contentType.toString();
              }
              dataUrl += ";base64,";
              dataUrl += data.toString("base64");
            }
            this.result = dataUrl;
            break;
github jsdom / jsdom / lib / jsdom / browser / old-resource-loader.js View on Github external
function readDataURL(dataURL, { defaultEncoding, detectMetaCharset }, callback) {
  try {
    const parsed = parseDataURL(dataURL);
    // If default encoding does not exist, pass on binary data.
    if (defaultEncoding) {
      const sniffOptions = {
        transportLayerEncodingLabel: parsed.mimeType.parameters.get("charset"),
        defaultEncoding
      };

      const encoding = detectMetaCharset ?
                       sniffHTMLEncoding(parsed.body, sniffOptions) :
                       whatwgEncoding.getBOMEncoding(parsed.body) ||
                        whatwgEncoding.labelToName(parsed.mimeType.parameters.get("charset")) ||
                        defaultEncoding;
      const decoded = whatwgEncoding.decode(parsed.body, encoding);

      parsed.mimeType.parameters.set("charset", encoding);

      callback(null, decoded, { headers: { "content-type": parsed.mimeType.toString() } });
    } else {
      callback(null, parsed.body, { headers: { "content-type": parsed.mimeType.toString() } });
    }
  } catch (err) {
    callback(err, null);
  }
  return null;
}
github flaviuse / mern-authentication / client / node_modules / jsdom / lib / jsdom / living / xmlhttprequest.js View on Github external
}
      if (this.readyState !== XMLHttpRequest.LOADING && this.readyState !== XMLHttpRequest.DONE) {
        return "";
      }
      if (properties.responseTextCache) {
        return properties.responseTextCache;
      }
      const responseBuffer = properties.responseBuffer ?
                             properties.responseBuffer.slice(0, properties.totalReceivedChunkSize) :
                             null;

      if (!responseBuffer) {
        return "";
      }

      const fallbackEncoding = finalCharset(this) || whatwgEncoding.getBOMEncoding(responseBuffer) || "UTF-8";
      const res = whatwgEncoding.decode(responseBuffer, fallbackEncoding);

      properties.responseTextCache = res;
      return res;
    }
    get responseXML() {
github sx1989827 / DOClever / node_modules / jsdom / lib / jsdom / living / xmlhttprequest.js View on Github external
let isHTML = false;
      let isXML = false;
      const parsed = MIMEType.parse(contentType);
      if (parsed) {
        isHTML = parsed.isHTML();
        isXML = parsed.isXML();
        if (!isXML && !isHTML) {
          return null;
        }
      }

      if (this.responseType === "" && isHTML) {
        return null;
      }

      const encoding = finalCharset(this) || whatwgEncoding.getBOMEncoding(responseBuffer) || "UTF-8";
      const resText = whatwgEncoding.decode(responseBuffer, encoding);

      if (!resText) {
        return null;
      }
      const res = Document.create([], { options: {
        url: flag.uri,
        lastModified: new Date(getResponseHeader(this, "last-modified")),
        parsingMode: isHTML ? "html" : "xml",
        cookieJar: { setCookieSync: () => undefined, getCookieStringSync: () => "" },
        encoding,
        parseOptions: this._ownerDocument._parseOptions
      } });
      const resImpl = idlUtils.implForWrapper(res);
      try {
        resImpl._htmlToDom.appendToDocument(resText, resImpl);
github jsdom / jsdom / lib / jsdom / living / xmlhttprequest.js View on Github external
let isHTML = false;
      let isXML = false;
      const parsed = MIMEType.parse(contentType);
      if (parsed) {
        isHTML = parsed.isHTML();
        isXML = parsed.isXML();
        if (!isXML && !isHTML) {
          return null;
        }
      }

      if (this.responseType === "" && isHTML) {
        return null;
      }

      const encoding = finalCharset(this) || whatwgEncoding.getBOMEncoding(responseBuffer) || "UTF-8";
      const resText = whatwgEncoding.decode(responseBuffer, encoding);

      if (!resText) {
        return null;
      }
      const res = Document.create(this._globalObject, [], {
        options: {
          url: flag.uri,
          lastModified: new Date(getResponseHeader(this, "last-modified")),
          parsingMode: isHTML ? "html" : "xml",
          cookieJar: { setCookieSync: () => undefined, getCookieStringSync: () => "" },
          encoding,
          parseOptions: this._ownerDocument._parseOptions
        }
      });
      const resImpl = idlUtils.implForWrapper(res);
github jsdom / jsdom / lib / jsdom / living / xmlhttprequest.js View on Github external
}
      if (this.readyState !== XMLHttpRequest.LOADING && this.readyState !== XMLHttpRequest.DONE) {
        return "";
      }
      if (properties.responseTextCache) {
        return properties.responseTextCache;
      }
      const responseBuffer = properties.responseBuffer ?
                             properties.responseBuffer.slice(0, properties.totalReceivedChunkSize) :
                             null;

      if (!responseBuffer) {
        return "";
      }

      const fallbackEncoding = finalCharset(this) || whatwgEncoding.getBOMEncoding(responseBuffer) || "UTF-8";
      const res = whatwgEncoding.decode(responseBuffer, fallbackEncoding);

      properties.responseTextCache = res;
      return res;
    }
    get responseXML() {
github flaviuse / mern-authentication / client / node_modules / jsdom / lib / jsdom / living / xmlhttprequest.js View on Github external
let isHTML = false;
      let isXML = false;
      const parsed = MIMEType.parse(contentType);
      if (parsed) {
        isHTML = parsed.isHTML();
        isXML = parsed.isXML();
        if (!isXML && !isHTML) {
          return null;
        }
      }

      if (this.responseType === "" && isHTML) {
        return null;
      }

      const encoding = finalCharset(this) || whatwgEncoding.getBOMEncoding(responseBuffer) || "UTF-8";
      const resText = whatwgEncoding.decode(responseBuffer, encoding);

      if (!resText) {
        return null;
      }
      const res = Document.create([], { options: {
        url: flag.uri,
        lastModified: new Date(getResponseHeader(this, "last-modified")),
        parsingMode: isHTML ? "html" : "xml",
        cookieJar: { setCookieSync: () => undefined, getCookieStringSync: () => "" },
        encoding,
        parseOptions: this._ownerDocument._parseOptions
      } });
      const resImpl = idlUtils.implForWrapper(res);
      try {
        resImpl._htmlToDom.appendToDocument(resText, resImpl);
github zubairghori / Ultimate_todo_list / node_modules / jsdom / lib / jsdom / living / xmlhttprequest.js View on Github external
}
      if (this.readyState !== XMLHttpRequest.LOADING && this.readyState !== XMLHttpRequest.DONE) {
        return "";
      }
      if (properties.responseTextCache) {
        return properties.responseTextCache;
      }
      const responseBuffer = properties.responseBuffer ?
                             properties.responseBuffer.slice(0, properties.totalReceivedChunkSize) :
                             null;

      if (!responseBuffer) {
        return "";
      }

      const fallbackEncoding = finalCharset(this) || whatwgEncoding.getBOMEncoding(responseBuffer) || "UTF-8";
      const res = whatwgEncoding.decode(responseBuffer, fallbackEncoding);

      properties.responseTextCache = res;
      return res;
    }
    get responseXML() {
github jsdom / jsdom / lib / jsdom / living / nodes / HTMLScriptElement-impl.js View on Github external
const onLoadExternalScript = data => {
      const { response } = request;
      let contentType;

      if (response && response.statusCode !== undefined && response.statusCode >= 400) {
        throw new Error("Status code: " + response.statusCode);
      }

      if (response) {
        contentType = MIMEType.parse(response.headers["content-type"]) || new MIMEType("text/plain");
      }

      const encoding = whatwgEncoding.getBOMEncoding(data) ||
        (contentType && whatwgEncoding.labelToName(contentType.parameters.get("charset"))) ||
        defaultEncoding;
      const script = whatwgEncoding.decode(data, encoding);

      this._innerEval(script, this.src);
    };

whatwg-encoding

Decode strings according to the WHATWG Encoding Standard

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis