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

js-create-element

v1.2.4

Published

Library to create a DOM element with inline CSS using pure JS

Downloads

36

Readme

js-create-element

Library to create a DOM element with inline CSS using pure JS.

GitHub license npm version Travis


Latest Release Notes

Version 1.2.x implements the following breaking changes:

  • Fixes a bug where babel plugins needed to be installed explicitly to use the library.
  • Cleaned up npmignore
  • Arguments structure has been changed to accept only two arguments: type and options. Please refer to the docs.

Installation

npm

npm install js-create-element

Browser

The minified version of the script can be found here.

<script type="text/javascript" src="jsCreateElement.min.js"></script>

Node

import { createElement } from 'js-create-element';

Usage

createElement([type], [options])

Returns the DOM element.

Arguments

| | Type | Default | -------------------------- | ------ | --------| | type | string | 'div' | | options | object | {} |

type

The type of the DOM element. For SVG elements, the type will look like svg:[elementType].

Example: a, p, span, svg:circle

options

The options argument contains attributes and styles of the DOM Element. Contains the following arguments:

Properties

| | Type | Default | -------------------------- | ------ | --------| | style | object | {} | | text | string | null | | pseudoElementBefore | object | null | | pseudoElementAfter | object | null | | ...attributes | object | null |

style

The list of styles for the DOM element.

Example:

style: {
     width: '100px',
     color: 'white',
     padding: '10px',
     backgroundColor: 'blue'
}

text

The inner text for the DOM element.

Example:

text: This is some text I want inside the element.

pseudoElementBefore

pseudoElementBefore replicates the behavior of CSS pseudo-element ::before via a span element. content property is required as per W3 (reference).

Example:

pseudoBefore: {
     content: 'sample-content',
     width: '10px',
     height: '10px',
     backgroundColor: 'red'
}

pseudoElementAfter

pseudoElementAfter replicates the behavior of CSS pseudo-element ::after via a span element. content property is required as per W3 (reference).

Example:

pseudoAfter: {
     content: 'sample-content',
     width: '10px',
     height: '10px',
     backgroundColor: 'red'
}

attributes

The attributes for the DOM Element (such as id, class, etc.). This is implemented as a spread operator so any key-value pair mentioned other than the ones mentioned above will attempt to be set as an attribute on the element. Several online resources such as MDN Web Docs provide good documentation on which attributes are acceptable for a given element type.

Demo

A really simple demo can be found here. A Codepen playground can be found here.

Dev Tools

Lint

ESLint is used for linting.

Command: make lint / npm run lint

Tests

Mocha and Chai are used as testing frameworks. Coverage is handled though Istanbul. Runs lint as well.

Command: make test / npm test

For CI: npm run test:ci

Docs

JSDoc is used for documentation. Documentation can be found here.

Command: make docs / npm run docs

Code formatter

Prettier is used for code formatting.

Command: make prettier / npm run prettier

Build

Webpack is used for build purposes. Runs lint, tests, code formatter and docs as well.

Command: make build / npm run build

Contributing

Pull requests are welcome and appreciated. Contributing guidelines can be found here.

License

Licensed under MIT. Can be found here.