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

create-element-ns

v3.3.1

Published

dom createElement hyperscript with svg, namespace and selector support

Downloads

5

Readme

create-element-ns

dom createElement and createElementNS hyperscript with svg, namespace and selector support

ExampleFeaturesAPILicense

Example

var CE = require('create-element-ns')
var el = CE.el

// selectors or attributes
var divEl1 = el('div.c1#i1[style="color:blue"].c2', {onclick: function() {}})(),
    divEl2 = el('div.i1', {style: {color: 'blue'}, props:{className: 'c1 c2', , onclick: function() {}}})(),
    divEl3 = el('div.c1#i1[style="color:blue"].c2')({onclick: function() {}}),

// namespace in different ways
var circleEl1 = el('svg:circle')(),
    circleEl2 = el.svg('circle')(),
    circleEl3 = el('circle[xmlns=http://www.w3.org/2000/svg]')
    circleEl3 = el('circle', {xmlns : 'http://www.w3.org/2000/svg'})

// partial application to create multiple modified clones
var pFn = el('p'),
    pEl = pFn({textContent: 'x'})

// factory functions can be nested, with or without arrays
var olFn = el('ol', el('li', 'one'), [el('li', 'two'), el('li', 'three')]),
    olEl = pFn()

Features

  • namespaced tag and namespaced attribute support
  • svg namespace and utility functions pre-defined
  • w3 string selector API, including attributes
  • element decorators for element properties and attributes
  • ability to inject a document API for server and/or testing (e.g. jsdom)
  • ability to create an element or an element factory
  • ability to create additional namespaces and utility namespaced functions

There are many hyperscript modules out there (docrel, create-element-from-selector, domator, makeelement, simpel to name a few) but they either don't support namespaces, like svg or are more oriented to virtual-dom applications.

API

Main methods

To create an element factory (function that return a DOM Element):

  • el(definition [, options][, content]) => elementFactory
  • el.svg(definition [, options][, content]) => elementFactory
  • elementFactory([optionObject]) => DOM Element

Parameters and outputs

  • definition: a string selector, elementFactory or DOM Element
  • options: {properties:{}, attributes:{}, style:{}, dataset:{}} or {props:{}, attrs:{}, style:{}, dataset:{}}
  • content: optional series or array of string, Element or elementFactory

Optional additional utilities

  • CE.global.document injects an external document API like jsdom. Uses the global document if not specified.
  • CE.namespaces adds additional namespace prefix (svg is already defined). E.g. CE.namespaces.xlink: 'http://www.w3.org/1999/xlink'
  • CE.decorators to add element decorators E.g. CE.decorators.a = CE.decorators.attributes

License

MIT © Hugo Villeneuve