New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

reshape-component

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reshape-component - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

16

lib/index.js

@@ -16,4 +16,6 @@ /* eslint-disable complexity */

* @param {ReshapeAstNode} componentNode - '<component>' node
* @param {boolean|string} preserveType - If 'true', the 'type' attributed will preserved; if a string value
* the 'type' attribute will be copied to an attribute named by the value
*/
function copyAttributes (templateAst, componentNode) {
function copyAttributes (templateAst, componentNode, preserveType) {
for (let attributeName in componentNode.attrs) {

@@ -30,2 +32,12 @@ if (!(attributeName in skippedAttributes)) {

}
if (preserveType) {
const typeAttribute = preserveType === true ? 'type' : preserveType;
const typeAttributeValue = componentNode.attrs.type;
if (typeAttributeValue) {
templateAst[0].attrs = templateAst[0].attrs || {};
templateAst[0].attrs[typeAttribute] = typeAttributeValue;
}
}
}

@@ -195,3 +207,3 @@ }

const templateAst = parser(src, { filename: componentPath }, { filename: componentPath });
copyAttributes(templateAst, node);
copyAttributes(templateAst, node, options.preserveType);
const tokenPromise = replaceTokens(templateAst, node);

@@ -198,0 +210,0 @@

2

package.json
{
"name": "reshape-component",
"description": "Include components in reshape templates",
"version": "1.0.5",
"version": "1.0.6",
"author": "msssk",

@@ -6,0 +6,0 @@ "bugs": "https://github.com/mkdecisiondev/reshape-component/issues",

@@ -66,10 +66,35 @@ # Reshape Component

The path is configurable in the options passed to the plugin via the `componentPath` property. The default value is:
The path is configurable in the options passed to the plugin via the `componentPath` property.
## Options
Name | Default | Description
----------------- | ------- | -----------
`componentPath` | 'components/$type/$type.html' | Specifies the path to use to include components specified by the `type` attribute. Any occurrences of `$type` in the path will be replaced with the value of the `type` attribute.
`preserveType` | false | If `true` the `type` attribute will be copied from the `component` tag to the first top-level node in the template. If a string value is provided it will be used as the name of the target attribute. This can be useful for JavaScript that wants to query the DOM for component nodes.
### `preserveType` example
```javascript
// configuring reshape-component:
reshapeComponent({ preserveType: 'data-component-type' })
```
'components/$type/$type.html'
```html
<!-- defining a component template: -->
<div>
<p>${content}</p>
</div>
<!-- using a component -->
<component type="Card">
<content>Card One</content>
</component>
<!-- result -->
<div data-component-type="Card">
<p>Card One</p>
</div>
```
Any occurrences of `$type` in the path will be replaced with the value of the `type` attribute.
## Token substitution

@@ -76,0 +101,0 @@

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