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

discodip

v1.5.3

Published

Embeddable HTML components generator.

Downloads

8

Readme

Discodip

discodip

Embeddable-HTML-components generator.

Transforms a set of component name/description/HTML-source objects into separate .html-files, along with .json-files containing component meta information. Can be used for embedding standalone components inside a ~design-system~ ~styleguide~ ~pattern~ ~library~ thing.


Install

First you need to install discodip.

> npm i discodip --save-dev

Generate components.json

This is what the json file containing all components should look like. Use any tool you like to gather the necessary data, for example Collect Components, Pug-doc or Gather Components.

[
  {
    "meta": {
      "name": "my-component",
      "description": "this is my component description"
    },
    "output": "<div class=\"some-tag\">this is some html</div><div class=\"some-tag\">this is some more html</div>",
    "fragments": [
      {
        "meta": {
          "name": "my-component",
          "description": "this is my component description"
        },
        "output": "<div class=\"some-tag\">this is some more html</div>"
      }
    ]
  }
]

Build

const build = require("discodip");

build({
  output: "httpdocs/my-components/",
  components: "httpdocs/components.json",
  headHtml: "<style>body{background:red}</style>",
  bodyHtml: "<script>alert('hello')</script>",
  prerender: {
    port: 3000,
    path: "my-components/",
    serveFolder: "httpdocs/"
  },
  onComplete: () => {
    console.log("complete");
  }
});

Now you can iframe them wherever you like or use javascript to get the metadata first.

<iframe src="/my-components/component1.html" frameborder="0" scrolling="no"></iframe>

Options

| option | default | type | description | | --------------------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | output | null | string | output directory | | components | null | string | .json-file holding all components | | headHtml | "" | string | string of html to include in the body | | bodyHtml | "" | string | string of html to include in the head | | prerender | null | object | prerender all components to get their heights (at 1200px wide browser window, using Puppeteer). This speeds up the user interface and makes it less jumpy. However, this makes compiling slower because it needs to open all components in a headless browser. | | prerender.port | "" | number | static server port for rendering components (http://localhost:{port}) | | prerender.path | "" | string | path to folder (http://localhost:{port}/{path}) | | prerender.serveFolder | 3000 | string | directory to start the static file server in | | onComplete | () => {} | function | function to be called when done | | silent | false | boolean | shut the terminal up | | force | false | boolean | always update all components. This disables smart checking for component re-evaluation. |


Output

For every component one .html file and one .json file will be generated inside the options.output folder. Also .config.json is generated to store configuration.

/output/
- /output/.config.json
- /output/component1.json
- /output/component1.html
- /output/component2.json
- /output/component2.html
<!DOCTYPE html>
  <html style="margin: 0; padding: 0px;">
  <head>
    <base target="_blank">
    <title>component1</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.6.0/iframeResizer.contentWindow.min.js"></script>
    <script>(function templatePolyfill(){if("content"in document.createElement("template")){return false}var templates=document.getElementsByTagName("template");var plateLen=templates.length;for(var x=0;x<plateLen;++x){var template=templates[x];var content=template.childNodes;var fragment=document.createDocumentFragment();while(content[0]){fragment.appendChild(content[0])}template.content=fragment}})();</script>
    <style>template {  display: none !important; }</style>
    <style>body{background:red}</style>
  </head>
  <body style="margin: 0px; padding: 0px;">
    <p style='height: 111px'>this is component 3</p>
    <script>alert('hello')</script>
  </body>
</html>
{
  "name": "component1",
  "slug": "component1",
  "height": 111,
  "description": "<p>this is component 1 description</p>",
  "source": "<p style='height: 111px'>this is component 1</p>"
}