posthtml-component 1.0.0-beta.12 → 1.0.0-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthtml-component",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.14",
4
4
  "description": "PostHTML Components Blade-like with slots, attributes as props and custom tag",
5
5
  "license": "MIT",
6
6
  "repository": "thewebartisan7/posthtml-components",
package/src/index.js CHANGED
@@ -10,6 +10,7 @@ const processProps = require('./process-props');
10
10
  const processAttributes = require('./process-attributes');
11
11
  const {processPushes, processStacks} = require('./process-stacks');
12
12
  const {setFilledSlots, processSlotContent, processFillContent} = require('./process-slots');
13
+ const each = require('lodash/each');
13
14
  const defaults = require('lodash/defaults');
14
15
  const assignWith = require('lodash/assignWith');
15
16
  const mergeWith = require('lodash/mergeWith');
@@ -57,6 +58,7 @@ module.exports = (options = {}) => tree => {
57
58
  options.attrsParserRules = options.attrsParserRules || {};
58
59
  options.strict = typeof options.strict === 'undefined' ? true : options.strict;
59
60
  options.utilities = options.utilities || {
61
+ each,
60
62
  defaults,
61
63
  assign: assignWith,
62
64
  merge: mergeWith,
@@ -9,6 +9,8 @@ const union = require('lodash/union');
9
9
  const each = require('lodash/each');
10
10
  const has = require('lodash/has');
11
11
  const extend = require('lodash/extend');
12
+ const isString = require('lodash/isString');
13
+ const isObject = require('lodash/isObject');
12
14
 
13
15
  /**
14
16
  * Map component attributes that it's not defined as props to first element of node
@@ -60,5 +62,15 @@ module.exports = (currentNode, attributes, props, options) => {
60
62
  delete attributes[key];
61
63
  });
62
64
 
65
+ // Remove an attribute if value is 'null' or 'undefined'
66
+ // so we can conditionally add an attribute
67
+ each(nodeAttrs, (value, key) => {
68
+ if (['undefined', 'null'].includes(value)) {
69
+ delete nodeAttrs[key];
70
+ } else if (key !== 'compose' && !isObject(nodeAttrs[key]) && !isString(nodeAttrs[key])) {
71
+ nodeAttrs[key] = nodeAttrs[key].toString();
72
+ }
73
+ });
74
+
63
75
  mainNode.attrs = nodeAttrs.compose();
64
76
  };