0.0.14 • Published 3 years ago

tag-object-converter v0.0.14

Weekly downloads
1
License
MIT
Repository
github
Last release
3 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

3 years ago

0.0.13

3 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.1

4 years ago