react-schemaorg
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -35,2 +35,3 @@ /** | ||
* }} | ||
* space={2} | ||
* /> | ||
@@ -41,4 +42,6 @@ * ``` | ||
item: WithContext<T>; | ||
/** Adds indentation, white space, and line break characters to JSON-LD output. {@link JSON.stringify} */ | ||
space?: string | number; | ||
}> { | ||
render(): JSX.Element; | ||
} |
@@ -17,4 +17,17 @@ "use strict"; | ||
*/ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const React = require("react"); | ||
var React = require("react"); | ||
/** | ||
@@ -37,12 +50,18 @@ * Component that inline-includes a JSON-LD script where specified. | ||
* }} | ||
* space={2} | ||
* /> | ||
* ``` | ||
*/ | ||
class JsonLd extends React.Component { | ||
render() { | ||
var JsonLd = /** @class */ (function (_super) { | ||
__extends(JsonLd, _super); | ||
function JsonLd() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
JsonLd.prototype.render = function () { | ||
return (React.createElement("script", { type: "application/ld+json", dangerouslySetInnerHTML: { | ||
__html: JSON.stringify(this.props.item, safeJsonLdReplacer) | ||
__html: JSON.stringify(this.props.item, safeJsonLdReplacer, this.props.space) | ||
} })); | ||
} | ||
} | ||
}; | ||
return JsonLd; | ||
}(React.Component)); | ||
exports.JsonLd = JsonLd; | ||
@@ -53,6 +72,6 @@ /** | ||
*/ | ||
const safeJsonLdReplacer = (() => { | ||
var safeJsonLdReplacer = (function () { | ||
// Replace per https://www.w3.org/TR/json-ld11/#restrictions-for-contents-of-json-ld-script-elements | ||
// Solution from https://stackoverflow.com/a/5499821/864313 | ||
const entities = Object.freeze({ | ||
var entities = Object.freeze({ | ||
"&": "&", | ||
@@ -64,6 +83,12 @@ "<": "<", | ||
}); | ||
const replace = (t) => entities[t] || t; | ||
return (_, value) => { | ||
var replace = function (t) { | ||
return entities[t] || t; | ||
}; | ||
return function (_, value) { | ||
switch (typeof value) { | ||
case "object": | ||
// Omit null values. | ||
if (value === null) { | ||
return undefined; | ||
} | ||
return value; // JSON.stringify will recursively call replacer. | ||
@@ -70,0 +95,0 @@ case "number": |
{ | ||
"name": "react-schemaorg", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"displayName": "React: Schema.org", | ||
@@ -5,0 +5,0 @@ "description": "Typed Schema.org JSON-LD in React", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21841
187