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

xtal-json-merge

v0.2.42

Published

Web component designed to deep merge JSON objects into other objects

Downloads

30

Readme

Published on webcomponents.org

<xtal-json-merge>

xtal-json-merge merges predefined json with some dynamic json.

These two components can also be useful for declarative custom elements, or template-based components, and demo pages that use html markup as the primary way of demonstrating the functionality of specific types of components, which we categorize below.

Demo

Mission

Many complex components, like grids or charts, require a large amount of declarative configuration, beyond what is optimally configured via attributes.

I would venture that 50% of UI Screens in the world consist of the following workflow:

  1. Get data
  2. Merge with configuration (and/or other manipulation of the data, not discussed here)
  3. Render using some specialized renderer (like a grid or chart component).

We assume here that step 3 is:

  1. done with another third party web component. For simplicity we'll assume it's called my-grid
  2. defined via some form of template markup i.e. <my-grid>

Some components, like the Vaadin grid, choose to be configured via light DOM elements (a perfectly fine approach). This component is of no help in those circumstances.

Other components tend to view themselves primarily as a JavaScript api, and then just quickly put a web component wrapper around it. Often that api consists of a single function or two, with a single parameter, where declarative JSON is expected to be passed. These components are designed to facilitate working with such components.

These components, xtal-insert-json and xtal-json-merge, enforce the declarative, optimized, side-effect free, XSS safe principles by insisting that the content is strictly compliant JSON. See other examples of embedding JSON as part of the markup.

Note that someone (Νίκος) has kindly provided a nice VSCode extension, that makes editing JSON much easier.

The JSON needs to be wrapped inside a script tag with type application/json, as shown below.

<xtal-insert-json>
<script type="application/json">
//JSON goes here
</script>
</xtal-insert-json>

Example

  <xtal-json-merge input={} with-path=rowData>
    <script type="application/json">
    [
      {
          "formula": "NaCl",
          "meltingPoint": 801,
          "boilingPoint": 1413
      },
      {
          "formula": "CaF2",
          "meltingPoint": 1418,
          "boilingPoint": 1533
      }
    ]
    </script>
  </xtal-json-merge>
  <p-d on=value-changed to=[-value] val=detail.value init-val=value m=1></p-d>
  <p-d on=value-changed to=[-input] val=detail.value init-val=value m=1></p-d>
  <xtal-editor -value key="Xtal Data"></xtal-editor>
  <div>Merge with</div>
  <code>
    [{
      "columns":[
          {"name": "Formula",         "field": "formula"},
          {"name": "Melting Point",   "field": "meltingPoint"},
          {"name": "BoilingPoint",    "field": "boilingPoint"}
      ],
      "gridOptions":{
          "enableCellNavigation": true,
          "enableColumnReorder": false
      }
    }]              
  </code>
  <xtal-json-merge -input id="insertData">
  <script type="application/json">
    {
      "columns":[
          {"name": "Formula",         "field": "formula"},
          {"name": "Melting Point",   "field": "meltingPoint"},
          {"name": "BoilingPoint",    "field": "boilingPoint"}
      ],
      "gridOptions":{
          "enableCellNavigation": true,
          "enableColumnReorder": false
      }
    }
  </script>
  </xtal-json-merge>

Running xtal-json-merge

  1. Install node.js
  2. Fork or clone this repo.
  3. Open command and navigate to location of fork or clone.
  4. Issue the following commands:
$ npm install
$ npm run serve
  1. Open your browser to (typically) http://localhost:3030/demo/dev.html