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

react-document-meta

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-document-meta - npm Package Compare versions

Comparing version 2.1.2 to 3.0.0-beta.0

dist/server.js

26

CHANGELOG.md

@@ -0,1 +1,26 @@

v2.1.2
--------------------
#### Internal
- Add `prop-types` to dependencies as `PropTypes` from `react` is deprecated
- Use `webpack@2` in example
v2.1.1
--------------------
#### Bugs
- Move `react` and `react-dom` to peerDependencies to avoid loading multiple versions of `react`
v2.1.0
--------------------
#### Features
- Add `renderToStaticMarkup` as static method on `DocumentMeta`
#### Internal
- Rewrite as ES6 class
v2.0.2

@@ -52,2 +77,1 @@ --------------------

- `DocumentMeta.rewind()` no longer takes an argument with options, and therefore `.rewind({ asReact: true })` and `.rewind({ asHtml: true })` is no longer possible. Two new static methods has been added to support this feature: `.renderAsReact()` and `.renderAsHTML()`

42

dist/__tests__/basic.test.js

@@ -17,2 +17,6 @@ 'use strict';

var _server2 = require('../server');
var _server3 = _interopRequireDefault(_server2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -66,14 +70,2 @@

describe('.renderAsHTML()', function () {
it('returns an empty string if no meta data has been mounted', function () {
_react2.default.createElement(_2.default, { title: 'a' }, _react2.default.createElement(_2.default, { title: 'b' }, _react2.default.createElement(_2.default, { title: 'c' })));
_assert2.default.strictEqual(_2.default.renderAsHTML(), '');
});
it('returns the latest document meta as HTML', function () {
(0, _server.renderToStaticMarkup)(_react2.default.createElement(_2.default, { title: 'a' }, _react2.default.createElement(_2.default, { title: 'b' }, _react2.default.createElement(_2.default, { title: 'c' }))));
_assert2.default.strictEqual(_2.default.renderAsHTML(), '<title>c</title>');
});
});
describe('container element with children', function () {

@@ -97,1 +89,27 @@ it('renders the children', function () {

});
describe('DocumentMetaServer', function () {
describe('.renderToStaticMarkup()', function () {
it('returns an empty string if no meta data has been mounted', function () {
_react2.default.createElement(_2.default, { title: 'a' }, _react2.default.createElement(_2.default, { title: 'b' }, _react2.default.createElement(_2.default, { title: 'c' })));
_assert2.default.strictEqual(_server3.default.renderToStaticMarkup(), '');
});
it('returns the latest document meta as HTML', function () {
(0, _server.renderToStaticMarkup)(_react2.default.createElement(_2.default, { title: 'a' }, _react2.default.createElement(_2.default, { title: 'b' }, _react2.default.createElement(_2.default, { title: 'c' }))));
_assert2.default.strictEqual(_server3.default.renderToStaticMarkup(), '<title>c</title>');
});
});
describe('.renderAsHTML()', function () {
it('returns an empty string if no meta data has been mounted', function () {
_react2.default.createElement(_2.default, { title: 'a' }, _react2.default.createElement(_2.default, { title: 'b' }, _react2.default.createElement(_2.default, { title: 'c' })));
_assert2.default.strictEqual(_server3.default.renderAsHTML(), '');
});
it('returns the latest document meta as HTML', function () {
(0, _server.renderToStaticMarkup)(_react2.default.createElement(_2.default, { title: 'a' }, _react2.default.createElement(_2.default, { title: 'b' }, _react2.default.createElement(_2.default, { title: 'c' }))));
_assert2.default.strictEqual(_server3.default.renderAsHTML(), '<title>c</title>');
});
});
});

@@ -11,3 +11,3 @@ 'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.render = render;

@@ -22,4 +22,2 @@ var _react = require('react');

var _server = require('react-dom/server');
var _reactSideEffect = require('react-side-effect');

@@ -140,8 +138,3 @@

var meta = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var opts = arguments[1];
if ((typeof opts === 'undefined' ? 'undefined' : _typeof(opts)) !== 'object') {
return meta;
}
var i = 0;

@@ -171,16 +164,6 @@ var tags = [];

getTags(meta).reduce(function (acc, entry) {
return getTags(meta).reduce(function (acc, entry) {
tags.push(renderTag(entry));
return tags;
}, tags);
if (opts.asReact) {
return tags;
}
return (0, _server.renderToStaticMarkup)(_react2.default.createElement(
'div',
null,
tags
)).replace(/(^<div>|<\/div>$)/g, '').replace(/data-rdm="true"/g, 'data-rdm');
}

@@ -228,14 +211,5 @@

DocumentMetaWithSideEffect.renderAsReact = function rewindAsReact() {
return render(DocumentMetaWithSideEffect.rewind(), { asReact: true });
return render(DocumentMetaWithSideEffect.rewind());
};
DocumentMetaWithSideEffect.renderAsHTML = function rewindAsHTML() {
return render(DocumentMetaWithSideEffect.rewind(), { asHtml: true });
};
DocumentMetaWithSideEffect.renderToStaticMarkup = function rewindAsHTML() {
return render(DocumentMetaWithSideEffect.rewind(), { asHtml: true });
};
exports.default = DocumentMetaWithSideEffect;
module.exports = exports['default'];

@@ -5,2 +5,3 @@ import assert from 'assert';

import DocumentMeta from '../';
import DocumentMetaServer from '../server';

@@ -81,3 +82,19 @@ describe('DocumentMeta', () => {

describe('.renderAsHTML()', () => {
describe('container element with children', () => {
it('renders the children', () => {
const title = 'foo';
const markup = renderToStaticMarkup(
<DocumentMeta title={ title }>
<div>Child element</div>
</DocumentMeta>
);
assert.strictEqual(markup, '<div>Child element</div>');
assert.deepEqual(DocumentMeta.rewind(), { title });
});
});
});
describe('DocumentMetaServer', () => {
describe('.renderToStaticMarkup()', () => {
it('returns an empty string if no meta data has been mounted', () => {

@@ -89,3 +106,3 @@ React.createElement(DocumentMeta, {title: 'a'},

);
assert.strictEqual(DocumentMeta.renderAsHTML(), '');
assert.strictEqual(DocumentMetaServer.renderToStaticMarkup(), '');
});

@@ -101,20 +118,27 @@

);
assert.strictEqual(DocumentMeta.renderAsHTML(), '<title>c</title>');
assert.strictEqual(DocumentMetaServer.renderToStaticMarkup(), '<title>c</title>');
});
});
describe('.renderAsHTML()', () => {
it('returns an empty string if no meta data has been mounted', () => {
React.createElement(DocumentMeta, {title: 'a'},
React.createElement(DocumentMeta, {title: 'b'},
React.createElement(DocumentMeta, {title: 'c'})
)
);
assert.strictEqual(DocumentMetaServer.renderAsHTML(), '');
});
describe('container element with children', () => {
it('renders the children', () => {
const title = 'foo';
const markup = renderToStaticMarkup(
<DocumentMeta title={ title }>
<div>Child element</div>
</DocumentMeta>
it('returns the latest document meta as HTML', () => {
renderToStaticMarkup(
React.createElement(DocumentMeta, {title: 'a'},
React.createElement(DocumentMeta, {title: 'b'},
React.createElement(DocumentMeta, {title: 'c'})
)
)
);
assert.strictEqual(markup, '<div>Child element</div>');
assert.deepEqual(DocumentMeta.rewind(), { title });
assert.strictEqual(DocumentMetaServer.renderAsHTML(), '<title>c</title>');
});
});
});
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { renderToStaticMarkup } from 'react-dom/server';
import withSideEffect from 'react-side-effect';
import {
clone,
defaults,
forEach
} from './utils';
import { clone, defaults, forEach } from './utils';
import {
canUseDOM,
removeDocumentMeta,
insertDocumentMeta
} from './dom';
import { canUseDOM, removeDocumentMeta, insertDocumentMeta } from './dom';
function reducePropsTostate ( propsList ) {
function reducePropsTostate(propsList) {
const props = {};

@@ -28,7 +19,7 @@

if ( _props.hasOwnProperty('description') ) {
defaults(_props, { meta: { name: { description: _props.description } } } );
if (_props.hasOwnProperty('description')) {
defaults(_props, { meta: { name: { description: _props.description } } });
}
if ( _props.hasOwnProperty('canonical') ) {
defaults(_props, { link: { rel: { canonical: _props.canonical } } } );
if (_props.hasOwnProperty('canonical')) {
defaults(_props, { link: { rel: { canonical: _props.canonical } } });
}

@@ -56,3 +47,3 @@

function ograph ( p ) {
function ograph(p) {
if (!p.meta) {

@@ -66,10 +57,10 @@ p.meta = {};

const group = p.meta.property;
if ( group ) {
if ( p.title && !group['og:title'] ) {
if (group) {
if (p.title && !group['og:title']) {
group['og:title'] = p.title;
}
if ( p.hasOwnProperty('description') && !group['og:description'] ) {
if (p.hasOwnProperty('description') && !group['og:description']) {
group['og:description'] = p.description;
}
if ( p.hasOwnProperty('canonical') && !group['og:url'] ) {
if (p.hasOwnProperty('canonical') && !group['og:url']) {
group['og:url'] = p.canonical;

@@ -81,3 +72,3 @@ }

function parseTags (tagName, props = {}) {
function parseTags(tagName, props = {}) {
const tags = [];

@@ -90,3 +81,3 @@ const contentKey = tagName === 'link' ? 'href' : 'content';

tagName,
[ groupKey ]: group
[groupKey]: group
});

@@ -101,4 +92,4 @@ return;

tagName,
[ groupKey ]: key,
[ contentKey ]: value
[groupKey]: key,
[contentKey]: value
});

@@ -112,22 +103,21 @@ }

function getTags ( _props ) {
return [].concat( parseTags( 'meta', _props.meta ), parseTags( 'link', _props.link ) );
function getTags(_props) {
return [].concat(
parseTags('meta', _props.meta),
parseTags('link', _props.link)
);
}
function render ( meta = {}, opts ) {
if ( typeof opts !== 'object' ) {
return meta;
}
export function render(meta = {}) {
let i = 0;
const tags = [];
function renderTag ( entry ) {
function renderTag(entry) {
const { tagName, ...attr } = entry;
if ( tagName === 'meta' ) {
return ( <meta {...attr} key={ i++ } data-rdm /> );
if (tagName === 'meta') {
return <meta {...attr} key={i++} data-rdm />;
}
if ( tagName === 'link' ) {
return ( <link {...attr} key={ i++ } data-rdm /> );
if (tagName === 'link') {
return <link {...attr} key={i++} data-rdm />;
}

@@ -137,16 +127,10 @@ return null;

if ( meta.title ) {
tags.push( <title key={ i++ }>{ meta.title }</title> );
if (meta.title) {
tags.push(<title key={i++}>{meta.title}</title>);
}
getTags( meta ).reduce(( acc, entry ) => {
tags.push( renderTag(entry) );
return getTags(meta).reduce((acc, entry) => {
tags.push(renderTag(entry));
return tags;
}, tags);
if ( opts.asReact ) {
return tags;
}
return renderToStaticMarkup( <div>{ tags }</div> ).replace(/(^<div>|<\/div>$)/g, '').replace(/data-rdm="true"/g, 'data-rdm');
}

@@ -180,3 +164,3 @@

auto: PropTypes.objectOf(PropTypes.bool)
}
};

@@ -186,3 +170,5 @@ render() {

const count = React.Children.count(children);
return count === 1 ? React.Children.only(children) : ( count ? <div>{ this.props.children }</div> : null );
return count === 1
? React.Children.only(children)
: count ? <div>{this.props.children}</div> : null;
}

@@ -196,14 +182,6 @@ }

DocumentMetaWithSideEffect.renderAsReact = function rewindAsReact () {
return render( DocumentMetaWithSideEffect.rewind(), { asReact: true } );
DocumentMetaWithSideEffect.renderAsReact = function rewindAsReact() {
return render(DocumentMetaWithSideEffect.rewind());
};
DocumentMetaWithSideEffect.renderAsHTML = function rewindAsHTML () {
return render( DocumentMetaWithSideEffect.rewind(), { asHtml: true } );
};
DocumentMetaWithSideEffect.renderToStaticMarkup = function rewindAsHTML () {
return render( DocumentMetaWithSideEffect.rewind(), { asHtml: true } );
};
export default DocumentMetaWithSideEffect;
{
"name": "react-document-meta",
"version": "2.1.2",
"version": "3.0.0-beta.0",
"description": "Declarative, nested and stateful HTML document meta tags for React",

@@ -5,0 +5,0 @@ "main": "./dist/index",

@@ -59,6 +59,5 @@ React Document Meta [![Build Status](https://travis-ci.org/kodyl/react-document-meta.svg)](https://travis-ci.org/kodyl/react-document-meta) [![Coverage Status](https://coveralls.io/repos/github/kodyl/react-document-meta/badge.svg?branch=master)](https://coveralls.io/github/kodyl/react-document-meta?branch=master) [![npm version](https://badge.fury.io/js/react-document-meta.svg)](http://badge.fury.io/js/react-document-meta)

return (
<div>
<DocumentMeta {...meta} />
<DocumentMeta {...meta}>
<h1>Hello World!</h1>
</div>
</DocumentMeta>
);

@@ -65,0 +64,0 @@ }

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