npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

symplasm

v0.0.1

Published

HTML to JSON parser

Downloads

1

Readme

Symplasm

https://github.com/lancetipton/symplasm

Parse HTML into td-VDom JS Object

Works in browser and Node.js

Example

Input HTML String

<div class="post post-featured">
  <p>Symplasm feels good...</p>
  <!-- ...like a dream come true. -->
</div>

Export JS Object

{
  0: 'div',
  1: {}
  2: [
    {
      0: 'div',
      1: {
        class: 'post post-featured'
      },
      2: [
        {
          0: 'p',
          1: {},
          2: 'Symplasm feels good...'
        },
        '<!--...like a dream come true.-->',
      ]

    }
  ]
}

To Use

symplasm.parse

  • params
    • htmlString - string of html content
    • Options - JS object ( See options below )
const symplasm = require('symplasm')

const jsObject = symplasm.parse(html, options)

symplasm.stringify

  • params
    • jsObject - a td-VDom formatted object to be converted into an html string
const htmlString = symplasm.stringify(jsObject)

Options

Symplasm.parse Default Options

{
  root: {
    0: 'div',
  },
  tagConvert: {},
  attrKeyConvert: {},
  attrValueConvert: {},
  attrKeyAdd: {},
  trim: false,
  lowerCaseTag: true,
  attrCamelCase: false,
}
  • root

    • Override the default div object
    • Must be in td-VDom format
    • Any children add in the 2 position, will be added first
  • tagConvert

    • Key / value pair of tags to be converted during the parse
    • Key is the tag to be converted
    • Value is the tag to convert to
      • Can be tag type / element selector as a string / function / td-VDom object
      • Function must retrun a tag type as a string or td-VDom object
      • Any children of the td-VDom object will be added before other children
      • Example
          {
            // only paragraph with span-text class with be converted to spans
            'p.span-text': 'span',
            // all articles will be converted to section, and have the class article
            article: {
              0: 'section',
              1: { class: 'article' },
              2: 'I am added as the first child'
            },
            // all buttons will be converted into div's
            button: function(element, key, value, allNodes, children, options){
              return 'div'
            }
          }
  • attrKeyConvert

    • Key / value pair of property keys to be converted during the parse
    • Key is the key to be converted
      • Select multiple elements by using a comma
    • Value is the property key to convert to
      • Can be string / function / object
        • Functions must retrun a string
        • If it's an object
          • Sub items can be defined to allow only updating the specified elements
          • Must be a Key / value pair to be converted during the parse
          • Key must be an tag type / element selector as a string
          • Value can be a string / function - must retrun a string
    • Example
        {
          // All class attributes will be converted to className
          class: 'className',
          id: {
            // all input id key property will be converted to td-input attribute
            input: function(element, key, value, allNodes, children, options){
              return 'td-input'
            },
            // all selects with the class 'no-id', will have their id converted to no-select-id attribute
            'select.no-id': 'no-select-id'
            // al buttons and divs will have their id converted to updates-both-elements
            'button,div': 'updates-both-elements'
          }
        }
  • attrValueConvert

    • Same as attrKeyConvert, but for the value
      • Select multiple elements by using a comma
    • Example
        {
          class: {
            // buttons with the td-button attribute, and divs with td-root attribue will have their
            // class  attribute value updated to 'td-replaced-' + element[0]
            'button[td-button],div[td-root]': function(element, key, value, allNodes, children, options){
              return 'td-replaced-' + element[0]
            },
          },
          name: {
            // all inputs will have their name attribute value updated to 'td-' + element[0]
            input: function(element, key, value, allNodes, children, options){
              return 'td-' + element[0]
            },
            'select.class-select': 'td-select-name'
          }
        }
  • attrKeyAdd

    • Same as attrKeyConvert, but to add a key value pair
    • Example
        {
          'onclick': {
            // all buttons with the td-button attribute will have an onclick attribute added
            'button[td-button]': 'buttonClick(event)'
          }
          'id': {
            // all inputs with the class add-id will get an id added
            // and the value will be what the function returns
            'input.add-id': function(element, key, value, allNodes, children, options){
              return uuid.v4()
            },
          }
        }
  • trim

    • Removes all white space from text
  • lowerCaseTag

    • Converts all dom node tags to lowercase
    • I.E. Div => div || IMG => img
  • attrCamelCase

    • Converts node properties to camelcase
    • Based off ReactDom

Symplasm.stringify Default Options

{
  attrLowerCase: false,
  styleAsCss: false
}
  • attrLowerCase

    • Converts node properties to lowercase
    • Does the reverse of ReactDom
  • styleAsCss

    • Converts JS CSS styles to Standard CSS
    • Breaks the string at all uppercase letters, adds -, then lowercases the string
    • I.E. marginTop:'20px' => margin-top: 20px