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-magic

v1.1.0

Published

simple ES6 utilities to manipulate browsers DOM

Downloads

31

Readme

dom-magic

Simple ES6 utilities to manipulate DOM

Features

  • JSX compatible, standalone createElement method (no react)
  • Show/hide elements
  • Add event listeners
  • Native ES6 module (requires babel/rollup to be used within browser)

Installation

$ npm install dom-magic --save
$ yarn add dom-magic

ES6 Transpiler Setup

File: gulpfile.js


const _rollup_babel = require('rollup-plugin-babel');
const _rollup_resolve = require('@rollup/plugin-node-resolve');

_gulp.task('es6-transpile', async function(){
    const bundle = await _rollup.rollup({
        input: './src/browser/EnlighterJS.js',
        plugins: [
            _rollup_resolve(),
            _rollup_babel()
        ]
    });

    // write the bundle to disk
    await bundle.write({
        format: 'iife',
        name: 'EnlighterJS',
        file: './.tmp/enlighterjs.js'
    });
});

File: babel.config.json

{
    "plugins": [
        ["@babel/plugin-transform-react-jsx", {
        }]
    ],
    "presets": [
        [
            "@babel/preset-env",
            {
                "targets": {
                    "browsers": [
                        "safari >= 7",
                        "IE >= 9",
                        "ios >= 9",
                        "firefox >= 50",
                        "chrome >= 50",
                        "edge >= 11"
                    ]
                },
                "debug": false
            }
        ]
    ]
}

Examples

JSX Component

File: button.jsx

// Internal "ReactDOM"
import * as React from 'dom-magic';

export function Button(props){

    // button css classes
    const classes = ['enlighter-btn'];

    // name set ?
    if (props.name){
        classes.push('enlighter-btn-' + props.name);
    }

    // create button
    return <div 
            className={classes.join(' ')} 
            onClick={props.onClick}
        >
            {props.text||null}
        </div>
}

Transpiled JSX

createElement is provided by dom-magic

function Button(props) {
    // button css classes
    var classes = ['enlighter-btn']; // name set ?

    if (props.name) {
    classes.push('enlighter-btn-' + props.name);
    } // create button


    return createElement("div", {
    className: classes.join(' '),
    onClick: props.onClick
    }, props.text || null);
}

Browser (abstract example)

var domMagic = require('dom-magic');

// get target container
var targetEl = domMagic.getElement('#container-a');

// create element
var buttonEl = Button({
    text: "hello world",
    name: "test"
});

// inject
domMagic.insertBefore(targetEl, buttonEl);

Full Examples

License

dom-magic is OpenSource and licensed under the Terms of MPL 2.0 - your're welcome to contribute