Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contentstack/utils

Package Overview
Dependencies
Maintainers
13
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentstack/utils - npm Package Compare versions

Comparing version 1.3.6 to 1.3.7

65

dist/index.es.js

@@ -5,24 +5,2 @@ 'use strict';

var DOMPurify = require('dompurify');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var DOMPurify__namespace = /*#__PURE__*/_interopNamespace(DOMPurify);
function createMetadata(attribute) {

@@ -175,26 +153,9 @@ return {

_a$1[StyleType$1.BLOCK] = function (item) {
var title = DOMPurify__namespace.sanitize(item.title || item.uid);
var contentTypeUid = DOMPurify__namespace.sanitize(item._content_type_uid || (item.system ? item.system.content_type_uid : ''));
return "<div><p>".concat(title, "</p><p>Content type: <span>").concat(contentTypeUid, "</span></p></div>");
return "<div><p>".concat(item.title || item.uid, "</p><p>Content type: <span>").concat(item._content_type_uid || (item.system ? item.system.content_type_uid : ''), "</span></p></div>");
},
_a$1[StyleType$1.INLINE] = function (item) {
var title = DOMPurify__namespace.sanitize(item.title || item.uid);
return "<span>".concat(title, "</span>");
},
_a$1[StyleType$1.LINK] = function (item, metadata) {
var url = DOMPurify__namespace.sanitize(item.url || 'undefined');
var text = DOMPurify__namespace.sanitize(metadata.text || item.title || item.uid || (item.system ? item.system.uid : ''));
return "<a href=\"".concat(url, "\">").concat(text, "</a>");
},
_a$1[StyleType$1.DISPLAY] = function (item, metadata) {
var url = DOMPurify__namespace.sanitize(item.url || 'undefined');
var alt = DOMPurify__namespace.sanitize(metadata.attributes.alt || item.title || item.filename || item.uid
|| (item.system ? item.system.uid : ''));
return "<img src=\"".concat(url, "\" alt=\"").concat(alt, "\" />");
},
_a$1[StyleType$1.DOWNLOAD] = function (item, metadata) {
var href = DOMPurify__namespace.sanitize(item.url || 'undefined');
var text = DOMPurify__namespace.sanitize(metadata.text || item.title || item.uid || (item.system ? item.system.content_type_uid : ''));
return "<a href=\"".concat(href, "\">").concat(text, "</a>");
},
_a$1[StyleType$1.INLINE] = function (item) { return "<span>".concat(item.title || item.uid, "</span>"); },
_a$1[StyleType$1.LINK] = function (item, metadata) { return "<a href=\"".concat(item.url, "\">").concat(metadata.text || item.title || item.uid || (item.system ? item.system.uid : ''), "</a>"); },
_a$1[StyleType$1.DISPLAY] = function (item, metadata) { return "<img src=\"".concat(item.url, "\" alt=\"").concat(metadata.attributes.alt || item.title || item.filename || item.uid
|| (item.system ? item.system.uid : ''), "\" />"); },
_a$1[StyleType$1.DOWNLOAD] = function (item, metadata) { return "<a href=\"".concat(item.url, "\">").concat(metadata.text || item.title || item.uid || (item.system ? item.system.content_type_uid : ''), "</a>"); },
_a$1);

@@ -444,15 +405,12 @@

_a[NodeType$1.LINK] = function (node, next) {
var sanitizedHref = DOMPurify__namespace.sanitize(node.attrs.href || node.attrs.url);
if (node.attrs.target) {
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(sanitizedHref, "\" target=\"").concat(node.attrs.target, "\">").concat(next(node.children), "</a>");
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\" target=\"").concat(node.attrs.target, "\">").concat(next(node.children), "</a>");
}
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(sanitizedHref, "\">").concat(next(node.children), "</a>");
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\">").concat(next(node.children), "</a>");
},
_a[NodeType$1.IMAGE] = function (node, next) {
var sanitizedSrc = DOMPurify__namespace.sanitize(node.attrs.src || node.attrs.url);
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(sanitizedSrc, "\" />").concat(next(node.children));
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs.src || node.attrs.url, "\" />").concat(next(node.children));
},
_a[NodeType$1.EMBED] = function (node, next) {
var sanitizedSrc = DOMPurify__namespace.sanitize(node.attrs.src || node.attrs.url);
return "<iframe".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(sanitizedSrc, "\">").concat(next(node.children), "</iframe>");
return "<iframe".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs.src || node.attrs.url, "\">").concat(next(node.children), "</iframe>");
},

@@ -536,5 +494,4 @@ _a[NodeType$1.HEADING_1] = function (node, next) {

_a['reference'] = function (node, next) {
var sanitizedAsset = DOMPurify__namespace.sanitize(node.attrs['asset-link']);
if (node.attrs.type === 'asset') {
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(sanitizedAsset, "\" />");
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs['asset-link'], "\" />");
}

@@ -541,0 +498,0 @@ return "";

@@ -0,25 +1,7 @@

var FigureTagRegex = /<\s*figure[^>]*>([^]*?)<\s*\/\s*figure>/g;
export function containsFigureTag(content) {
var openingTag = '<figure';
var closingTag = '</figure>';
var openingIndex = content.indexOf(openingTag);
var closingIndex = content.indexOf(closingTag);
return openingIndex !== -1 && closingIndex !== -1 && closingIndex > openingIndex;
return countFigureTags(content) > 0;
}
export function matchFigureTag(content) {
var matches = [];
var openingTag = '<figure';
var closingTag = '</figure>';
var startIndex = content.indexOf(openingTag);
while (startIndex !== -1) {
var endIndex = content.indexOf(closingTag, startIndex);
if (endIndex !== -1 && endIndex > startIndex) {
matches.push(content.substring(startIndex, endIndex + closingTag.length));
startIndex = content.indexOf(openingTag, endIndex + closingTag.length);
}
else {
console.error('Malformed figure tag found in content');
break;
}
}
return matches.length > 0 ? matches : null;
return content.match(FigureTagRegex);
}

@@ -26,0 +8,0 @@ export function countFigureTags(content) {

15

dist/lib/options/default-node-options.js
var _a;
import MarkType from "../nodes/mark-type";
import NodeType from "../nodes/node-type";
import * as DOMPurify from 'dompurify';
export var defaultNodeOption = (_a = {},

@@ -13,15 +12,12 @@ _a[NodeType.DOCUMENT] = function (node) {

_a[NodeType.LINK] = function (node, next) {
var sanitizedHref = DOMPurify.sanitize(node.attrs.href || node.attrs.url);
if (node.attrs.target) {
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(sanitizedHref, "\" target=\"").concat(node.attrs.target, "\">").concat(next(node.children), "</a>");
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\" target=\"").concat(node.attrs.target, "\">").concat(next(node.children), "</a>");
}
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(sanitizedHref, "\">").concat(next(node.children), "</a>");
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\">").concat(next(node.children), "</a>");
},
_a[NodeType.IMAGE] = function (node, next) {
var sanitizedSrc = DOMPurify.sanitize(node.attrs.src || node.attrs.url);
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(sanitizedSrc, "\" />").concat(next(node.children));
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs.src || node.attrs.url, "\" />").concat(next(node.children));
},
_a[NodeType.EMBED] = function (node, next) {
var sanitizedSrc = DOMPurify.sanitize(node.attrs.src || node.attrs.url);
return "<iframe".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(sanitizedSrc, "\">").concat(next(node.children), "</iframe>");
return "<iframe".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs.src || node.attrs.url, "\">").concat(next(node.children), "</iframe>");
},

@@ -105,5 +101,4 @@ _a[NodeType.HEADING_1] = function (node, next) {

_a['reference'] = function (node, next) {
var sanitizedAsset = DOMPurify.sanitize(node.attrs['asset-link']);
if (node.attrs.type === 'asset') {
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(sanitizedAsset, "\" />");
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs['asset-link'], "\" />");
}

@@ -110,0 +105,0 @@ return "";

var _a;
import StyleType from '../embedded-types/style-type';
import * as DOMPurify from 'dompurify';
export var defaultOptions = (_a = {},
_a[StyleType.BLOCK] = function (item) {
var title = DOMPurify.sanitize(item.title || item.uid);
var contentTypeUid = DOMPurify.sanitize(item._content_type_uid || (item.system ? item.system.content_type_uid : ''));
return "<div><p>".concat(title, "</p><p>Content type: <span>").concat(contentTypeUid, "</span></p></div>");
return "<div><p>".concat(item.title || item.uid, "</p><p>Content type: <span>").concat(item._content_type_uid || (item.system ? item.system.content_type_uid : ''), "</span></p></div>");
},
_a[StyleType.INLINE] = function (item) {
var title = DOMPurify.sanitize(item.title || item.uid);
return "<span>".concat(title, "</span>");
},
_a[StyleType.LINK] = function (item, metadata) {
var url = DOMPurify.sanitize(item.url || 'undefined');
var text = DOMPurify.sanitize(metadata.text || item.title || item.uid || (item.system ? item.system.uid : ''));
return "<a href=\"".concat(url, "\">").concat(text, "</a>");
},
_a[StyleType.DISPLAY] = function (item, metadata) {
var url = DOMPurify.sanitize(item.url || 'undefined');
var alt = DOMPurify.sanitize(metadata.attributes.alt || item.title || item.filename || item.uid
|| (item.system ? item.system.uid : ''));
return "<img src=\"".concat(url, "\" alt=\"").concat(alt, "\" />");
},
_a[StyleType.DOWNLOAD] = function (item, metadata) {
var href = DOMPurify.sanitize(item.url || 'undefined');
var text = DOMPurify.sanitize(metadata.text || item.title || item.uid || (item.system ? item.system.content_type_uid : ''));
return "<a href=\"".concat(href, "\">").concat(text, "</a>");
},
_a[StyleType.INLINE] = function (item) { return "<span>".concat(item.title || item.uid, "</span>"); },
_a[StyleType.LINK] = function (item, metadata) { return "<a href=\"".concat(item.url, "\">").concat(metadata.text || item.title || item.uid || (item.system ? item.system.uid : ''), "</a>"); },
_a[StyleType.DISPLAY] = function (item, metadata) { return "<img src=\"".concat(item.url, "\" alt=\"").concat(metadata.attributes.alt || item.title || item.filename || item.uid
|| (item.system ? item.system.uid : ''), "\" />"); },
_a[StyleType.DOWNLOAD] = function (item, metadata) { return "<a href=\"".concat(item.url, "\">").concat(metadata.text || item.title || item.uid || (item.system ? item.system.content_type_uid : ''), "</a>"); },
_a);
//# sourceMappingURL=default-options.js.map
export declare function containsFigureTag(content: string): boolean;
export declare function matchFigureTag(content: string): string[] | null;
export declare function matchFigureTag(content: string): RegExpMatchArray;
export declare function countFigureTags(content: string): number;
{
"name": "@contentstack/utils",
"version": "1.3.6",
"version": "1.3.7",
"description": "Contentstack utilities for Javascript",

@@ -40,3 +40,2 @@ "main": "dist/index.es.js",

"@commitlint/config-conventional": "^17.7.0",
"@types/dompurify": "^3.0.5",
"@types/jest": "^26.0.24",

@@ -83,7 +82,3 @@ "babel-core": "^4.7.16",

]
},
"dependencies": {
"cheerio": "^1.0.0-rc.12",
"dompurify": "^3.1.1"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc