react-document-meta
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -90,8 +90,18 @@ 'use strict'; | ||
var tags = []; | ||
Object.keys(props).forEach(function (prop) { | ||
Object.keys(props[prop]).forEach(function (key) { | ||
var _tags$push; | ||
var contentKey = tagName === 'link' ? 'href' : 'content'; | ||
Object.keys(props).forEach(function (groupKey) { | ||
var group = props[groupKey]; | ||
if (typeof group === 'string') { | ||
tags.push(_defineProperty({ | ||
tagName: tagName }, groupKey, group)); | ||
return; | ||
} | ||
Object.keys(group).forEach(function (key) { | ||
var values = Array.isArray(group[key]) ? group[key] : [group[key]]; | ||
values.forEach(function (value) { | ||
var _tags$push2; | ||
tags.push((_tags$push = { | ||
tagName: tagName }, _defineProperty(_tags$push, prop, key), _defineProperty(_tags$push, 'content', props[prop][key]), _tags$push)); | ||
tags.push((_tags$push2 = { | ||
tagName: tagName }, _defineProperty(_tags$push2, groupKey, key), _defineProperty(_tags$push2, contentKey, value), _tags$push2)); | ||
}); | ||
}); | ||
@@ -197,4 +207,4 @@ }); | ||
canonical: _React2['default'].PropTypes.string, | ||
meta: _React2['default'].PropTypes.objectOf(_React2['default'].PropTypes.objectOf(_React2['default'].PropTypes.string)), | ||
link: _React2['default'].PropTypes.objectOf(_React2['default'].PropTypes.objectOf(_React2['default'].PropTypes.string)), | ||
meta: _React2['default'].PropTypes.objectOf(_React2['default'].PropTypes.oneOfType([_React2['default'].PropTypes.string, _React2['default'].PropTypes.objectOf(_React2['default'].PropTypes.string)])), | ||
link: _React2['default'].PropTypes.objectOf(_React2['default'].PropTypes.objectOf(_React2['default'].PropTypes.oneOfType([_React2['default'].PropTypes.string, _React2['default'].PropTypes.arrayOf(_React2['default'].PropTypes.string)]))), | ||
auto: _React2['default'].PropTypes.objectOf(_React2['default'].PropTypes.bool) | ||
@@ -201,0 +211,0 @@ }, |
@@ -6,2 +6,6 @@ 'use strict'; | ||
}); | ||
/** | ||
* Tools | ||
*/ | ||
exports.clone = clone; | ||
@@ -11,2 +15,3 @@ exports.defaults = defaults; | ||
exports.isValidProp = isValidProp; | ||
exports.removeDocumentMeta = removeDocumentMeta; | ||
@@ -33,2 +38,6 @@ function clone(source) { | ||
/** | ||
* Validation | ||
*/ | ||
var VALID_PROPS = ['title', 'description', 'canonical', 'meta', 'link']; | ||
@@ -39,1 +48,13 @@ | ||
} | ||
/** | ||
* Document manipulation | ||
*/ | ||
function removeNode(node) { | ||
node.parentNode.removeChild(node); | ||
} | ||
function removeDocumentMeta() { | ||
forEach(document.querySelectorAll('head [data-rdm]'), removeNode); | ||
} |
@@ -74,9 +74,21 @@ import React from 'react'; | ||
const tags = []; | ||
Object.keys( props ).forEach(( prop ) => { | ||
Object.keys( props[prop] ).forEach(( key ) => { | ||
const contentKey = tagName === 'link' ? 'href' : 'content'; | ||
Object.keys( props ).forEach(( groupKey ) => { | ||
const group = props[groupKey]; | ||
if (typeof group === 'string') { | ||
tags.push({ | ||
tagName, | ||
[ prop ]: key, | ||
content: props[prop][key] | ||
[ groupKey ]: group | ||
}); | ||
return; | ||
} | ||
Object.keys( group ).forEach(( key ) => { | ||
const values = Array.isArray(group[key]) ? group[key] : [group[key]]; | ||
values.forEach(( value ) => { | ||
tags.push({ | ||
tagName, | ||
[ groupKey ]: key, | ||
[ contentKey ]: value | ||
}); | ||
}); | ||
}); | ||
@@ -172,4 +184,16 @@ }); | ||
canonical: React.PropTypes.string, | ||
meta: React.PropTypes.objectOf(React.PropTypes.objectOf(React.PropTypes.string)), | ||
link: React.PropTypes.objectOf(React.PropTypes.objectOf(React.PropTypes.string)), | ||
meta: React.PropTypes.objectOf( | ||
React.PropTypes.oneOfType([ | ||
React.PropTypes.string, | ||
React.PropTypes.objectOf(React.PropTypes.string) | ||
]) | ||
), | ||
link: React.PropTypes.objectOf( | ||
React.PropTypes.objectOf( | ||
React.PropTypes.oneOfType([ | ||
React.PropTypes.string, | ||
React.PropTypes.arrayOf(React.PropTypes.string) | ||
]) | ||
) | ||
), | ||
auto: React.PropTypes.objectOf(React.PropTypes.bool) | ||
@@ -176,0 +200,0 @@ }, |
@@ -0,1 +1,5 @@ | ||
/** | ||
* Tools | ||
*/ | ||
export function clone ( source ) { | ||
@@ -22,2 +26,6 @@ return JSON.parse( JSON.stringify( source ) ); | ||
/** | ||
* Validation | ||
*/ | ||
const VALID_PROPS = ['title', 'description', 'canonical', 'meta', 'link']; | ||
@@ -27,2 +35,14 @@ | ||
return ~VALID_PROPS.indexOf( propKey ); | ||
} | ||
} | ||
/** | ||
* Document manipulation | ||
*/ | ||
function removeNode ( node ) { | ||
node.parentNode.removeChild(node); | ||
} | ||
export function removeDocumentMeta () { | ||
forEach(document.querySelectorAll('head [data-rdm]'), removeNode); | ||
} |
{ | ||
"name": "react-document-meta", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Declarative, nested and stateful HTML document meta tags for React", | ||
@@ -34,5 +34,5 @@ "main": "./dist/index", | ||
}, | ||
"repository": "danieljuhl/react-document-meta", | ||
"repository": "boligbesked/react-document-meta", | ||
"author": "Daniel Juhl", | ||
"license": "MIT" | ||
} |
Sorry, the diff of this file is not supported yet
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
24486
21
606
44