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

dom-filenameify

v1.2.1

Published

Add filenames as attributes to your DOM elements to help locate them in code via inspect element

Downloads

15

Readme

dom-filenameify npm version Build Status experimental

A browserify transform that adds filenames as attributes to your DOM elements to help locate them in code via inspect element

Initial Motivation

If you've ever helped with onboarding someone onto a team you've likely gotten a flood of "How do I find BLANK?" questions.

dom-filenameify hopes to address part of this problem by annotating DOM nodes in your browser with an attribute that tells you where to find it in code.


How?

dom-filenameify alters your hyperscript style DOM builder calls and tagged template literal DOM builder calls in order to make them generate DOM notes that have a data-filename attribute with a value of the file's filepath.

It does this by walking your AST and inserting filename attributes appropriately.

To Install

You should really only use this transform in development. Especially since it's stability:experimental at this time.

To install the CLI use

npm install --save-dev dom-filenameify

To install the API use

npm install --save dom-filenameify

Examples

Here are some examples of what happens when you use this transform

// Handles nested DOM elements
var html = require('choo/html')

html`<div><span id='some-id'>hello world</span></div>`
// -> <div filename="/app/some-component.js"><span filename="/app/some-component.js" id="some-id">hello world</span></div>
var vdom = require('virtual-dom')
// Recognizes the `h` property on your `virtual-dom` variable
var h = vdom.h

h('div', {
  style: {color: 'red'}
}, 'foo')
// -> <div filename="/app/my-component.js" style="color: red;"></div>
// Variable name doesn't matter
var xyzw = require('react')

xyzw.createElement('span', 'hello')
// -> <span filename='/src/some-file.js'>hello</span>
var react = require('react')
var hx = require('hyperx')(react.createElement)

hx`<b>A bold element</b>`
// -> <b filename="/app/bold-elements/a-bold-element.js"></b>

CLI Usage

browserify index.js -t dom-filenameify > bundle.js

API Usage

var browserify = require('browserify')
var domFilenameify = require('dom-filenameify')

var b = browserify('index.js')
b.transform(domFilenameify)

// Writes output to console
b.bundle().pipe(process.stdout)

Something broke!

Sorry about that! You get a golden star if you open up a failing PR that highlights what's going wrong. You get a slightly less shiny silver star if you open up an issue describing the error. At any rate, let's get this fixed!

To Test:

$ npm run test

TODO:

  • [ ] Handle <img></img> issues. This breaks dom-filenameify. Should just skip over these incorrectly used

Notes

What is the hyperscript API?

The hyperscript API is domBuilder(htmlSelector, properties, children)

See hyperscript api

// hyperscript API examples
h('span', {style: {color: 'blue'}, id: 1}, 'foo bar')
react.createElement('div', [
  'a text node',
  react.createElement('span', {
  }, 'a span node'),
  'another text node'
])

See Also

  • falafel - transform a JavaScript AST

License

MIT