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

@elastic/react-search-ui-views

Package Overview
Dependencies
Maintainers
85
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elastic/react-search-ui-views - npm Package Compare versions

Comparing version 1.14.0 to 1.15.0

lib/cjs/__tests__/view-helpers/formatResult.test.d.ts

53

lib/cjs/Result.js

@@ -19,53 +19,8 @@ "use strict";

const view_helpers_1 = require("./view-helpers");
function isFieldValueWrapper(object) {
return (object &&
(Object.prototype.hasOwnProperty.call(object, "raw") ||
Object.prototype.hasOwnProperty.call(object, "snippet")));
}
function getFieldType(result, field, type) {
if (result[field])
return result[field][type];
}
function getRaw(result, field) {
return getFieldType(result, field, "raw");
}
function getSnippet(result, field) {
return getFieldType(result, field, "snippet");
}
function htmlEscape(str) {
if (!str)
return "";
return String(str)
.replace(/&/g, "&")
.replace(/"/g, """)
.replace(/'/g, "'")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}
function getEscapedField(result, field) {
// Fallback to raw values here, because non-string fields
// will not have a snippet fallback. Raw values MUST be html escaped.
const safeField = getSnippet(result, field) || htmlEscape(getRaw(result, field));
return Array.isArray(safeField) ? safeField.join(", ") : safeField;
}
function getEscapedFields(result) {
return Object.keys(result).reduce((acc, field) => {
// If we receive an arbitrary value from the response, we may not properly
// handle it, so we should filter out arbitrary values here.
//
// I.e.,
// Arbitrary value: "_metaField: '1939191'"
// vs.
// FieldValueWrapper: "_metaField: {raw: '1939191'}"
if (!isFieldValueWrapper(result[field]))
return acc;
return Object.assign(Object.assign({}, acc), { [field]: getEscapedField(result, field) });
}, {});
}
function Result(_a) {
var { className, result, onClickLink, titleField, urlField, thumbnailField } = _a, rest = __rest(_a, ["className", "result", "onClickLink", "titleField", "urlField", "thumbnailField"]);
const fields = getEscapedFields(result);
const title = getEscapedField(result, titleField);
const url = (0, view_helpers_1.getUrlSanitizer)(URL, location.href)(getRaw(result, urlField));
const thumbnail = (0, view_helpers_1.getUrlSanitizer)(URL, location.href)(getRaw(result, thumbnailField));
const fields = (0, view_helpers_1.formatResult)(result);
const title = (0, view_helpers_1.getEscapedField)(result[titleField]);
const url = (0, view_helpers_1.getUrlSanitizer)(URL, location.href)((0, view_helpers_1.getRaw)(result[urlField]));
const thumbnail = (0, view_helpers_1.getUrlSanitizer)(URL, location.href)((0, view_helpers_1.getRaw)(result[thumbnailField]));
return (react_1.default.createElement("li", Object.assign({ className: (0, view_helpers_1.appendClassName)("sui-result", className) }, rest),

@@ -72,0 +27,0 @@ react_1.default.createElement("div", { className: "sui-result__header" },

export { default as getFilterValueDisplay } from "./getFilterValueDisplay";
export { default as appendClassName } from "./appendClassName";
export { default as getUrlSanitizer } from "./getUrlSanitizer";
export { formatResult, getEscapedField, getRaw } from "./formatResult";

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getUrlSanitizer = exports.appendClassName = exports.getFilterValueDisplay = void 0;
exports.getRaw = exports.getEscapedField = exports.formatResult = exports.getUrlSanitizer = exports.appendClassName = exports.getFilterValueDisplay = void 0;
var getFilterValueDisplay_1 = require("./getFilterValueDisplay");

@@ -14,1 +14,5 @@ Object.defineProperty(exports, "getFilterValueDisplay", { enumerable: true, get: function () { return __importDefault(getFilterValueDisplay_1).default; } });

Object.defineProperty(exports, "getUrlSanitizer", { enumerable: true, get: function () { return __importDefault(getUrlSanitizer_1).default; } });
var formatResult_1 = require("./formatResult");
Object.defineProperty(exports, "formatResult", { enumerable: true, get: function () { return formatResult_1.formatResult; } });
Object.defineProperty(exports, "getEscapedField", { enumerable: true, get: function () { return formatResult_1.getEscapedField; } });
Object.defineProperty(exports, "getRaw", { enumerable: true, get: function () { return formatResult_1.getRaw; } });

@@ -13,54 +13,9 @@ var __rest = (this && this.__rest) || function (s, e) {

import React from "react";
import { appendClassName, getUrlSanitizer } from "./view-helpers";
function isFieldValueWrapper(object) {
return (object &&
(Object.prototype.hasOwnProperty.call(object, "raw") ||
Object.prototype.hasOwnProperty.call(object, "snippet")));
}
function getFieldType(result, field, type) {
if (result[field])
return result[field][type];
}
function getRaw(result, field) {
return getFieldType(result, field, "raw");
}
function getSnippet(result, field) {
return getFieldType(result, field, "snippet");
}
function htmlEscape(str) {
if (!str)
return "";
return String(str)
.replace(/&/g, "&amp;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}
function getEscapedField(result, field) {
// Fallback to raw values here, because non-string fields
// will not have a snippet fallback. Raw values MUST be html escaped.
const safeField = getSnippet(result, field) || htmlEscape(getRaw(result, field));
return Array.isArray(safeField) ? safeField.join(", ") : safeField;
}
function getEscapedFields(result) {
return Object.keys(result).reduce((acc, field) => {
// If we receive an arbitrary value from the response, we may not properly
// handle it, so we should filter out arbitrary values here.
//
// I.e.,
// Arbitrary value: "_metaField: '1939191'"
// vs.
// FieldValueWrapper: "_metaField: {raw: '1939191'}"
if (!isFieldValueWrapper(result[field]))
return acc;
return Object.assign(Object.assign({}, acc), { [field]: getEscapedField(result, field) });
}, {});
}
import { appendClassName, getUrlSanitizer, formatResult, getEscapedField, getRaw } from "./view-helpers";
function Result(_a) {
var { className, result, onClickLink, titleField, urlField, thumbnailField } = _a, rest = __rest(_a, ["className", "result", "onClickLink", "titleField", "urlField", "thumbnailField"]);
const fields = getEscapedFields(result);
const title = getEscapedField(result, titleField);
const url = getUrlSanitizer(URL, location.href)(getRaw(result, urlField));
const thumbnail = getUrlSanitizer(URL, location.href)(getRaw(result, thumbnailField));
const fields = formatResult(result);
const title = getEscapedField(result[titleField]);
const url = getUrlSanitizer(URL, location.href)(getRaw(result[urlField]));
const thumbnail = getUrlSanitizer(URL, location.href)(getRaw(result[thumbnailField]));
return (React.createElement("li", Object.assign({ className: appendClassName("sui-result", className) }, rest),

@@ -67,0 +22,0 @@ React.createElement("div", { className: "sui-result__header" },

export { default as getFilterValueDisplay } from "./getFilterValueDisplay";
export { default as appendClassName } from "./appendClassName";
export { default as getUrlSanitizer } from "./getUrlSanitizer";
export { formatResult, getEscapedField, getRaw } from "./formatResult";
export { default as getFilterValueDisplay } from "./getFilterValueDisplay";
export { default as appendClassName } from "./appendClassName";
export { default as getUrlSanitizer } from "./getUrlSanitizer";
export { formatResult, getEscapedField, getRaw } from "./formatResult";
{
"name": "@elastic/react-search-ui-views",
"version": "1.14.0",
"version": "1.15.0",
"description": "A collection of React UI components for building search experiences",

@@ -65,3 +65,3 @@ "homepage": "https://docs.elastic.co/search-ui",

"dependencies": {
"@elastic/search-ui": "1.14.0",
"@elastic/search-ui": "1.15.0",
"downshift": "^3.2.10",

@@ -71,3 +71,3 @@ "rc-pagination": "^1.20.1",

},
"gitHead": "02f8817971c81c6b9ac57b3eef1ab98bb53bcd13"
"gitHead": "f7a446008be60e9141bfd3e952ca903181ad6133"
}
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