Socket
Socket
Sign inDemoInstall

dom-serializer

Package Overview
Dependencies
3
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.4.1

196

lib/foreignNames.js

@@ -5,100 +5,100 @@ "use strict";

exports.elementNames = new Map([
"altGlyph",
"altGlyphDef",
"altGlyphItem",
"animateColor",
"animateMotion",
"animateTransform",
"clipPath",
"feBlend",
"feColorMatrix",
"feComponentTransfer",
"feComposite",
"feConvolveMatrix",
"feDiffuseLighting",
"feDisplacementMap",
"feDistantLight",
"feDropShadow",
"feFlood",
"feFuncA",
"feFuncB",
"feFuncG",
"feFuncR",
"feGaussianBlur",
"feImage",
"feMerge",
"feMergeNode",
"feMorphology",
"feOffset",
"fePointLight",
"feSpecularLighting",
"feSpotLight",
"feTile",
"feTurbulence",
"foreignObject",
"glyphRef",
"linearGradient",
"radialGradient",
"textPath",
].map(function (val) { return [val.toLowerCase(), val]; }));
["altglyph", "altGlyph"],
["altglyphdef", "altGlyphDef"],
["altglyphitem", "altGlyphItem"],
["animatecolor", "animateColor"],
["animatemotion", "animateMotion"],
["animatetransform", "animateTransform"],
["clippath", "clipPath"],
["feblend", "feBlend"],
["fecolormatrix", "feColorMatrix"],
["fecomponenttransfer", "feComponentTransfer"],
["fecomposite", "feComposite"],
["feconvolvematrix", "feConvolveMatrix"],
["fediffuselighting", "feDiffuseLighting"],
["fedisplacementmap", "feDisplacementMap"],
["fedistantlight", "feDistantLight"],
["fedropshadow", "feDropShadow"],
["feflood", "feFlood"],
["fefunca", "feFuncA"],
["fefuncb", "feFuncB"],
["fefuncg", "feFuncG"],
["fefuncr", "feFuncR"],
["fegaussianblur", "feGaussianBlur"],
["feimage", "feImage"],
["femerge", "feMerge"],
["femergenode", "feMergeNode"],
["femorphology", "feMorphology"],
["feoffset", "feOffset"],
["fepointlight", "fePointLight"],
["fespecularlighting", "feSpecularLighting"],
["fespotlight", "feSpotLight"],
["fetile", "feTile"],
["feturbulence", "feTurbulence"],
["foreignobject", "foreignObject"],
["glyphref", "glyphRef"],
["lineargradient", "linearGradient"],
["radialgradient", "radialGradient"],
["textpath", "textPath"],
]);
exports.attributeNames = new Map([
"definitionURL",
"attributeName",
"attributeType",
"baseFrequency",
"baseProfile",
"calcMode",
"clipPathUnits",
"diffuseConstant",
"edgeMode",
"filterUnits",
"glyphRef",
"gradientTransform",
"gradientUnits",
"kernelMatrix",
"kernelUnitLength",
"keyPoints",
"keySplines",
"keyTimes",
"lengthAdjust",
"limitingConeAngle",
"markerHeight",
"markerUnits",
"markerWidth",
"maskContentUnits",
"maskUnits",
"numOctaves",
"pathLength",
"patternContentUnits",
"patternTransform",
"patternUnits",
"pointsAtX",
"pointsAtY",
"pointsAtZ",
"preserveAlpha",
"preserveAspectRatio",
"primitiveUnits",
"refX",
"refY",
"repeatCount",
"repeatDur",
"requiredExtensions",
"requiredFeatures",
"specularConstant",
"specularExponent",
"spreadMethod",
"startOffset",
"stdDeviation",
"stitchTiles",
"surfaceScale",
"systemLanguage",
"tableValues",
"targetX",
"targetY",
"textLength",
"viewBox",
"viewTarget",
"xChannelSelector",
"yChannelSelector",
"zoomAndPan",
].map(function (val) { return [val.toLowerCase(), val]; }));
["definitionurl", "definitionURL"],
["attributename", "attributeName"],
["attributetype", "attributeType"],
["basefrequency", "baseFrequency"],
["baseprofile", "baseProfile"],
["calcmode", "calcMode"],
["clippathunits", "clipPathUnits"],
["diffuseconstant", "diffuseConstant"],
["edgemode", "edgeMode"],
["filterunits", "filterUnits"],
["glyphref", "glyphRef"],
["gradienttransform", "gradientTransform"],
["gradientunits", "gradientUnits"],
["kernelmatrix", "kernelMatrix"],
["kernelunitlength", "kernelUnitLength"],
["keypoints", "keyPoints"],
["keysplines", "keySplines"],
["keytimes", "keyTimes"],
["lengthadjust", "lengthAdjust"],
["limitingconeangle", "limitingConeAngle"],
["markerheight", "markerHeight"],
["markerunits", "markerUnits"],
["markerwidth", "markerWidth"],
["maskcontentunits", "maskContentUnits"],
["maskunits", "maskUnits"],
["numoctaves", "numOctaves"],
["pathlength", "pathLength"],
["patterncontentunits", "patternContentUnits"],
["patterntransform", "patternTransform"],
["patternunits", "patternUnits"],
["pointsatx", "pointsAtX"],
["pointsaty", "pointsAtY"],
["pointsatz", "pointsAtZ"],
["preservealpha", "preserveAlpha"],
["preserveaspectratio", "preserveAspectRatio"],
["primitiveunits", "primitiveUnits"],
["refx", "refX"],
["refy", "refY"],
["repeatcount", "repeatCount"],
["repeatdur", "repeatDur"],
["requiredextensions", "requiredExtensions"],
["requiredfeatures", "requiredFeatures"],
["specularconstant", "specularConstant"],
["specularexponent", "specularExponent"],
["spreadmethod", "spreadMethod"],
["startoffset", "startOffset"],
["stddeviation", "stdDeviation"],
["stitchtiles", "stitchTiles"],
["surfacescale", "surfaceScale"],
["systemlanguage", "systemLanguage"],
["tablevalues", "tableValues"],
["targetx", "targetX"],
["targety", "targetY"],
["textlength", "textLength"],
["viewbox", "viewBox"],
["viewtarget", "viewTarget"],
["xchannelselector", "xChannelSelector"],
["ychannelselector", "yChannelSelector"],
["zoomandpan", "zoomAndPan"],
]);

@@ -1,2 +0,2 @@

import type { AnyNode } from "domhandler";
import type { Node } from "domhandler";
export interface DomSerializerOptions {

@@ -28,12 +28,4 @@ /**

/**
* Encode characters that are either reserved in HTML or XML.
* Encode characters that are either reserved in HTML or XML, or are outside of the ASCII range.
*
* If `xmlMode` is `true` or the value not `'utf8'`, characters outside of the utf8 range will be encoded as well.
*
* @default `decodeEntities`
*/
encodeEntities?: boolean | "utf8";
/**
* Option inherited from parsing; will be used as the default value for `encodeEntities`.
*
* @default true

@@ -51,4 +43,3 @@ */

*/
export declare function render(node: AnyNode | ArrayLike<AnyNode>, options?: DomSerializerOptions): string;
export default render;
export default function render(node: Node | ArrayLike<Node>, options?: DomSerializerOptions): string;
//# sourceMappingURL=index.d.ts.map

@@ -15,7 +15,3 @@ "use strict";

if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {

@@ -38,3 +34,2 @@ if (k2 === undefined) k2 = k;

Object.defineProperty(exports, "__esModule", { value: true });
exports.render = void 0;
/*

@@ -51,3 +46,3 @@ * Module dependencies

*/
var foreignNames_js_1 = require("./foreignNames.js");
var foreignNames_1 = require("./foreignNames");
var unencodedElements = new Set([

@@ -63,5 +58,2 @@ "style",

]);
function replaceQuotes(value) {
return value.replace(/"/g, "&quot;");
}
/**

@@ -71,10 +63,4 @@ * Format attributes

function formatAttributes(attributes, opts) {
var _a;
if (!attributes)
return;
var encode = ((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) === false
? replaceQuotes
: opts.xmlMode || opts.encodeEntities !== "utf8"
? entities_1.encodeXML
: entities_1.escapeAttribute;
return Object.keys(attributes)

@@ -86,3 +72,3 @@ .map(function (key) {

/* Fix up mixed-case attribute names */
key = (_b = foreignNames_js_1.attributeNames.get(key)) !== null && _b !== void 0 ? _b : key;
key = (_b = foreignNames_1.attributeNames.get(key)) !== null && _b !== void 0 ? _b : key;
}

@@ -92,3 +78,5 @@ if (!opts.emptyAttrs && !opts.xmlMode && value === "") {

}
return "".concat(key, "=\"").concat(encode(value), "\"");
return key + "=\"" + (opts.decodeEntities !== false
? entities_1.encodeXML(value)
: value.replace(/"/g, "&quot;")) + "\"";
})

@@ -138,3 +126,2 @@ .join(" ");

}
exports.render = render;
exports.default = render;

@@ -145,5 +132,4 @@ function renderNode(node, options) {

return render(node.children, options);
// @ts-expect-error We don't use `Doctype` yet
case ElementType.Directive:
case ElementType.Doctype:
case ElementType.Directive:
return renderDirective(node);

@@ -179,3 +165,3 @@ case ElementType.Comment:

/* Fix up mixed-case element names */
elem.name = (_a = foreignNames_js_1.elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name;
elem.name = (_a = foreignNames_1.elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name;
/* Exit foreign mode at integration points */

@@ -190,6 +176,6 @@ if (elem.parent &&

}
var tag = "<".concat(elem.name);
var tag = "<" + elem.name;
var attribs = formatAttributes(elem.attribs, opts);
if (attribs) {
tag += " ".concat(attribs);
tag += " " + attribs;
}

@@ -212,3 +198,3 @@ if (elem.children.length === 0 &&

if (opts.xmlMode || !singleTag.has(elem.name)) {
tag += "</".concat(elem.name, ">");
tag += "</" + elem.name + ">";
}

@@ -219,16 +205,12 @@ }

function renderDirective(elem) {
return "<".concat(elem.data, ">");
return "<" + elem.data + ">";
}
function renderText(elem, opts) {
var _a;
var data = elem.data || "";
// If entities weren't decoded, no need to encode them back
if (((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) !== false &&
if (opts.decodeEntities !== false &&
!(!opts.xmlMode &&
elem.parent &&
unencodedElements.has(elem.parent.name))) {
data =
opts.xmlMode || opts.encodeEntities !== "utf8"
? (0, entities_1.encodeXML)(data)
: (0, entities_1.escapeText)(data);
data = entities_1.encodeXML(data);
}

@@ -238,6 +220,6 @@ return data;

function renderCdata(elem) {
return "<![CDATA[".concat(elem.children[0].data, "]]>");
return "<![CDATA[" + elem.children[0].data + "]]>";
}
function renderComment(elem) {
return "<!--".concat(elem.data, "-->");
return "<!--" + elem.data + "-->";
}
{
"name": "dom-serializer",
"version": "1.4.0",
"version": "1.4.1",
"description": "render domhandler DOM nodes to a string",

@@ -14,11 +14,6 @@ "author": "Felix Boehm <me@feedic.com>",

"type": "git",
"url": "git://github.com/cheeriojs/dom-serializer.git"
"url": "git://github.com/cheeriojs/dom-renderer.git"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"module": "lib/esm/index.js",
"exports": {
"require": "./lib/index.js",
"import": "./lib/esm/index.js"
},
"files": [

@@ -28,33 +23,27 @@ "lib/**/*"

"dependencies": {
"domelementtype": "^2.3.0",
"domhandler": "^5.0.2",
"entities": "^4.2.0"
"domelementtype": "^2.0.1",
"domhandler": "^4.2.0",
"entities": "^2.0.0"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.18.0",
"@typescript-eslint/parser": "^5.18.0",
"@types/jest": "^26.0.23",
"@types/node": "^15.3.0",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"cheerio": "^1.0.0-rc.9",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",
"htmlparser2": "^7.2.0",
"jest": "^27.5.1",
"prettier": "^2.6.2",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"
"coveralls": "^3.0.5",
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"htmlparser2": "^6.1.0",
"jest": "^26.0.1",
"prettier": "^2.3.0",
"ts-jest": "^26.5.6",
"typescript": "^4.0.2"
},
"scripts": {
"test": "npm run test:jest && npm run lint",
"test:jest": "jest",
"lint": "npm run lint:es && npm run lint:prettier",
"lint:es": "eslint --ignore-path .gitignore .",
"lint:prettier": "npm run prettier -- --check",
"format": "npm run format:es && npm run format:prettier",
"format:es": "npm run lint:es -- --fix",
"format:prettier": "npm run prettier -- --write",
"prettier": "prettier \"**/*.{ts,md,json,yml}\" --ignore-path .gitignore",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc",
"build:esm": "tsc --module esnext --target es2019 --outDir lib/esm && echo '{\"type\":\"module\"}' > lib/esm/package.json",
"test": "jest --coverage && npm run lint",
"coverage": "cat coverage/lcov.info | coveralls",
"lint": "eslint src",
"format": "prettier --write '**/*.{ts,md,json}'",
"build": "tsc",
"prepare": "npm run build"

@@ -64,6 +53,3 @@ },

"preset": "ts-jest",
"testEnvironment": "node",
"moduleNameMapper": {
"^(.*)\\.js$": "$1"
}
"testEnvironment": "node"
},

@@ -70,0 +56,0 @@ "funding": "https://github.com/cheeriojs/dom-serializer?sponsor=1",

@@ -34,14 +34,2 @@ # dom-serializer [![Build Status](https://travis-ci.com/cheeriojs/dom-serializer.svg?branch=master)](https://travis-ci.com/cheeriojs/dom-serializer)

### `encodeEntities`
• `Optional` **decodeEntities**: _boolean | "utf8"_
Encode characters that are either reserved in HTML or XML.
If `xmlMode` is `true` or the value not `'utf8'`, characters outside of the utf8 range will be encoded as well.
**`default`** `decodeEntities`
---
### `decodeEntities`

@@ -51,3 +39,3 @@

Option inherited from parsing; will be used as the default value for `encodeEntities`.
Encode characters that are either reserved in HTML or XML, or are outside of the ASCII range.

@@ -54,0 +42,0 @@ **`default`** true

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc