0.0.14 • Published 4 years ago

tag-object-converter v0.0.14

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

tag-object-converter

change log

The parameters of 'obj2tag' method is changed from v0.0.2

convert tag to object

const { tag2obj } = require('tag-object-converter');

tag2obj('<tagName attr1="value1" attr2="value2" />');
// or
tag2obj('<tagName attr1="value1" attr2="value2">');

/** output
{
  tagName: 'tagName',
  attrs: {
    'attr1': 'value1',
    'attr2.': 'value2'
  },
  attrOrder: [
    'attr1',
    'attr2'
  ],
  isClosing: false
}
*/
tag2obj('</tagName>');

/** output
{
  tagName: 'tagName',
  attrs: {},
  attrOrder: [],
  isClosing: true
}
*/

convert object to tag

const { obj2tag } = require('tag-object-converter');

const obj = {
  tagName: 'tagName',
  attrs: {
    'attr1': 'value1',
    'attr2.': 'value2'
  },
  // attrOrder is optional.
  // If attrOrder is not given, the attributes will be ordered by default in outputted tag
  attrOrder: [
    'attr2',
    'attr1'
  ]
};

const options = {
  isSelfClosing: true, // Boolean. Default => TRUE
  finalSpace: true // Boolean. Default => TRUE. If 'isSelfClosing' is FALSE, this option will always be FALSE.
};

obj2tag(obj, options);
// output
// <tagName attr2="value2" attr1="value1" />
0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.5

5 years ago

0.0.6

5 years ago

0.0.1

5 years ago