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

femdom

v0.0.3

Published

Stringify HTML elements to JSON and domify them back to your page.

Downloads

2

Readme

FEMDOM

Note: this package was intended as a joke a long time ago but it should actually work perfectly fine.

FEMDOM is a simple FORMATTER / ENCODER / MARKUPIFIER for DOCUMENT OBJECT MODEL nodes. Easy interconversion between DOM nodes, EcmaScript object and JSON strings.

JOI | JAVASCRIPT OBJECT INTERCONVERSION

Easily convert EcmaScript HTML Nodes to JSON and back.

Acquire

Simple as that.

npm i femdom 
/* Node */
const femdom = require('femdom')
/* Browser */
<script src="femdom.js"></script>

Methods

FEMDOM has three methods.

  • objectify(htmlNode)
  • domify(object)
  • stringify(object or htmlNode, indentation)

OBJECTIFY

Isolates only the nodeName, nodeValue, childNodes and attributes of a DOM node. Returns 'abstraction' of the HTML element as regular EcmaScript object.

<div id="women" class="fancy">
... some user info here ...
</div>
/* Find element with id = 'women' */
let women = document.getElementById('women')
let result = FEMDOM.objectify(women)

Your result is an abstract representation of whatever is inside your HTML element. It could look something like this:

var result = {
   "nodeType": 1,
   "tagName": "div",
   "attributes": [
      [
         "id",
         "women"
      ]
   ],
   "childNodes": [
      {
         "nodeType": 1,
         "tagName": "table",
         "attributes": [
            [
               "class",
               "table"
            ]
         ],
         "childNodes": [
            {
               "nodeType": 1,
               "tagName": "caption",
               "attributes": [],
               "childNodes": [
                  {
                     "nodeType": 3,
                     "nodeName": "#text",
                     "nodeValue": "Women",
                     "childNodes": []
                  }
               ]
            },
            {
               "nodeType": 1,
               "tagName": "thead",
               "attributes": [],
               "childNodes": [
                  {
                     "nodeType": 1,
                     "tagName": "tr",
                     "attributes": [],
                     "childNodes": [
                        {
                           "nodeType": 1,
                           "tagName": "th",
                           "attributes": [],
                           "childNodes": [
                              {
                                 "nodeType": 3,
                                 "nodeName": "#text",
                                 "nodeValue": "Name",
                                 "childNodes": []
                              }
                           ]
                        },
                        {
                           "nodeType": 1,
                           "tagName": "th",
                           "attributes": [],
                           "childNodes": [
                              {
                                 "nodeType": 3,
                                 "nodeName": "#text",
                                 "nodeValue": "Age",
                                 "childNodes": []
                              }
                           ]
                        }
                     ]
                  }
               ]
            },
            {
               "nodeType": 1,
               "tagName": "tbody",
               "attributes": [],
               "childNodes": [
                  {
                     "nodeType": 1,
                     "tagName": "tr",
                     "attributes": [],
                     "childNodes": [
                        {
                           "nodeType": 1,
                           "tagName": "td",
                           "attributes": [],
                           "childNodes": [
                              {
                                 "nodeType": 3,
                                 "nodeName": "#text",
                                 "nodeValue": "Kylie Star",
                                 "childNodes": []
                              }
                           ]
                        },
                        {
                           "nodeType": 1,
                           "tagName": "td",
                           "attributes": [],
                           "childNodes": [
                              {
                                 "nodeType": 3,
                                 "nodeName": "#text",
                                 "nodeValue": "@kyliestar",
                                 "childNodes": []
                              }
                           ]
                        }
                     ]
                  },
                  {
                     "nodeType": 1,
                     "tagName": "tr",
                     "attributes": [],
                     "childNodes": [
                        {
                           "nodeType": 1,
                           "tagName": "td",
                           "attributes": [],
                           "childNodes": [
                              {
                                 "nodeType": 3,
                                 "nodeName": "#text",
                                 "nodeValue": "Princess Rene",
                                 "childNodes": []
                              }
                           ]
                        },
                        {
                           "nodeType": 1,
                           "tagName": "td",
                           "attributes": [],
                           "childNodes": [
                              {
                                 "nodeType": 3,
                                 "nodeName": "#text",
                                 "nodeValue": "@worshiprenee",
                                 "childNodes": []
                              }
                           ]
                        }
                     ]
                  },
                  {
                     "nodeType": 1,
                     "tagName": "tr",
                     "attributes": [],
                     "childNodes": [
                        {
                           "nodeType": 1,
                           "tagName": "td",
                           "attributes": [],
                           "childNodes": [
                              {
                                 "nodeType": 3,
                                 "nodeName": "#text",
                                 "nodeValue": "Amai Liu",
                                 "childNodes": []
                              }
                           ]
                        },
                        {
                           "nodeType": 1,
                           "tagName": "td",
                           "attributes": [],
                           "childNodes": [
                              {
                                 "nodeType": 3,
                                 "nodeName": "#text",
                                 "nodeValue": "@amailiu",
                                 "childNodes": []
                              }
                           ]
                        }
                     ]
                  }
               ]
            }
         ]
      }
   ]
}
/* Observe that when using jQuery, you simply do this */
FEMDOM.objectify(
    $('#women')[0] // the zero means first result of this query
)

DOMIFY

As the name suggests, domify() will successfully render your exported string or object back to the DOM.

/* Basically dupliates our user table */
document.body.appendChild(
    FEMDOM.domify(result)
)

STRINGIFY

Simply wraps JSON.stringify() and returns a JSON string representation. The second argument for indentation is optional and is the same as the third argument of JSON.stringify. You can stringify both objectified nodes and HTML nodes directly, it can tell the difference.

/* This will internally simply call JSON stringify on your result object */
let jsonString = FEMDOM.stringify(result)

/* Stringify HTML element directly */
FEMDOM.stringify(
    document.querySelector('#stuff')
)