<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohit Kushwah on Medium]]></title>
        <description><![CDATA[Stories by Mohit Kushwah on Medium]]></description>
        <link>https://medium.com/@mkushwah222?source=rss-ea5f8bdddc5e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zOP381HfWOJcnI8mSEERpw.jpeg</url>
            <title>Stories by Mohit Kushwah on Medium</title>
            <link>https://medium.com/@mkushwah222?source=rss-ea5f8bdddc5e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 06:22:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mkushwah222/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[JavaScript : How to build visualization using ELK JS (elk.js)]]></title>
            <link>https://medium.com/@mkushwah222/javascript-how-to-build-visualization-using-elk-js-elk-js-61b0ec7725e8?source=rss-ea5f8bdddc5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/61b0ec7725e8</guid>
            <category><![CDATA[elk]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[network-topology]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[frontend-development]]></category>
            <dc:creator><![CDATA[Mohit Kushwah]]></dc:creator>
            <pubDate>Sun, 28 Jun 2026 12:21:51 GMT</pubDate>
            <atom:updated>2026-06-28T12:21:51.051Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello there,</p><p>When you need to visualize connected systems — network topologies, infrastructure diagrams, dependency graphs — manually positioning nodes and routing edges becomes painful fast.</p><p>ELK (Eclipse Layout Kernel) solves this by automatically calculating optimal positions for nodes and routing edges between them. You give it a JSON graph, it gives you coordinates.</p><p>In this article, we’ll use ELK.js with D3 to build an interactive diagram renderer in JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c0W4KUAJkl2GqH4Wzt0qJw.png" /></figure><p>I’m going to use it in JavaScript but we can use it any where like Angular or JavaScript or create a reusable npm package.</p><p>First include <strong><em>elk js </em></strong>and<strong><em> d3 </em></strong>using package json or CDN</p><p>Now lets see what is the JSON structure require for ELK.</p><pre># ELK.js JSON Structure<br><br>## Root Object<br><br>```json<br>{<br>  &quot;id&quot;: &quot;string&quot;,           // Required: Unique identifier for the root graph<br>  &quot;layoutOptions&quot;: {},      // Optional: Layout configuration options<br>  &quot;children&quot;: [],           // Required: Array of nodes/children<br>  &quot;edges&quot;: []              // Optional: Array of edges connecting nodes<br>}<br>```<br><br>## Layout Options<br><br>Common layout options that control the graph appearance:<br><br>```json<br>&quot;layoutOptions&quot;: {<br>  &quot;elk.algorithm&quot;: &quot;layered&quot;,           // Algorithm: &quot;layered&quot;, &quot;force&quot;, &quot;stress&quot;, etc.<br>  &quot;elk.direction&quot;: &quot;DOWN&quot;,              // Direction: &quot;UP&quot;, &quot;DOWN&quot;, &quot;LEFT&quot;, &quot;RIGHT&quot;<br>  &quot;elk.spacing.nodeNode&quot;: &quot;80&quot;,         // Space between nodes (same layer)<br>  &quot;elk.layered.spacing.nodeNodeBetweenLayers&quot;: &quot;100&quot;,  // Space between layers<br>  &quot;elk.edgeRouting&quot;: &quot;ORTHOGONAL&quot;       // Edge style: &quot;ORTHOGONAL&quot;, &quot;POLYLINE&quot;, &quot;SPLINES&quot;<br>}<br>```<br><br>## Children (Nodes)<br><br>Each node in the graph:<br><br>```json<br>{<br>  &quot;id&quot;: &quot;string&quot;,           // Required: Unique node identifier<br>  &quot;width&quot;: 120,             // Required: Node width in pixels<br>  &quot;height&quot;: 80,             // Required: Node height in pixels<br>  &quot;labels&quot;: [               // Optional: Array of text labels<br>    {<br>      &quot;text&quot;: &quot;Node Label&quot;<br>    }<br>  ],<br>  &quot;ports&quot;: [],              // Optional: Array of connection points<br>  &quot;children&quot;: []            // Optional: Nested child nodes (hierarchical)<br>}<br>```<br><br>## Ports<br><br>Connection points on nodes:<br><br>```json<br>{<br>  &quot;id&quot;: &quot;string&quot;,           // Required: Unique port identifier<br>  &quot;width&quot;: 10,              // Optional: Port width<br>  &quot;height&quot;: 10,             // Optional: Port height<br>  &quot;properties&quot;: {           // Optional: Port positioning<br>    &quot;port.side&quot;: &quot;NORTH&quot;    // Side: &quot;NORTH&quot;, &quot;SOUTH&quot;, &quot;EAST&quot;, &quot;WEST&quot;<br>  },<br>  &quot;labels&quot;: [               // Optional: Port labels<br>    {<br>      &quot;text&quot;: &quot;P1&quot;<br>    }<br>  ]<br>}<br>```<br><br>## Edges<br><br>Connections between nodes or ports:<br><br>```json<br>{<br>  &quot;id&quot;: &quot;string&quot;,           // Required: Unique edge identifier<br>  &quot;sources&quot;: [&quot;node_id&quot;],   // Required: Array of source node/port IDs<br>  &quot;targets&quot;: [&quot;node_id&quot;],   // Required: Array of target node/port IDs<br>  &quot;labels&quot;: [               // Optional: Edge labels<br>    {<br>      &quot;text&quot;: &quot;Connection&quot;<br>    }<br>  ]<br>}<br>```<br><br>## Complete Example<br><br>```json<br>{<br>  &quot;id&quot;: &quot;root&quot;,<br>  &quot;layoutOptions&quot;: {<br>    &quot;elk.algorithm&quot;: &quot;layered&quot;,<br>    &quot;elk.direction&quot;: &quot;RIGHT&quot;<br>  },<br>  &quot;children&quot;: [<br>    {<br>      &quot;id&quot;: &quot;n1&quot;,<br>      &quot;width&quot;: 100,<br>      &quot;height&quot;: 60,<br>      &quot;labels&quot;: [{ &quot;text&quot;: &quot;Node 1&quot; }],<br>      &quot;ports&quot;: [<br>        {<br>          &quot;id&quot;: &quot;n1_p1&quot;,<br>          &quot;properties&quot;: { &quot;port.side&quot;: &quot;EAST&quot; }<br>        }<br>      ]<br>    },<br>    {<br>      &quot;id&quot;: &quot;n2&quot;,<br>      &quot;width&quot;: 100,<br>      &quot;height&quot;: 60,<br>      &quot;labels&quot;: [{ &quot;text&quot;: &quot;Node 2&quot; }],<br>      &quot;ports&quot;: [<br>        {<br>          &quot;id&quot;: &quot;n2_p1&quot;,<br>          &quot;properties&quot;: { &quot;port.side&quot;: &quot;WEST&quot; }<br>        }<br>      ]<br>    }<br>  ],<br>  &quot;edges&quot;: [<br>    {<br>      &quot;id&quot;: &quot;e1&quot;,<br>      &quot;sources&quot;: [&quot;n1_p1&quot;],<br>      &quot;targets&quot;: [&quot;n2_p1&quot;]<br>    }<br>  ]<br>}<br>```<br><br>## Key Points<br><br>- **id**: Must be unique across all nodes, ports, and edges<br>- **width/height**: Required for nodes to calculate layout<br>- **sources/targets**: Can reference node IDs directly or port IDs for precise connections<br>- **layoutOptions**: Extensive options available in ELK documentation<br>- **Hierarchical**: Nodes can contain children for nested layouts</pre><p>Now lets look at the implementation file</p><pre>// src/lib/elk.js<br><br>import ELK from &#39;elkjs/lib/elk.bundled.js&#39;;<br>import * as d3 from &#39;d3&#39;;<br><br>export class ElkViz {<br>  constructor(container, config = {}) {<br>    this.container = d3.select(container);<br>    this.config = {<br>      width: config.width || 800,<br>      height: config.height || 600,<br>      ...config<br>    };<br>    this.elk = new ELK();<br>    this.eventHandlers = {};<br>    this.svg = null;<br>  }<br><br>  on(event, handler) {<br>    this.eventHandlers[event] = handler;<br>    return this;<br>  }<br><br>  emit(event, data) {<br>    if (this.eventHandlers[event]) {<br>      this.eventHandlers[event](data);<br>    }<br>  }<br><br>  async render(data) {<br>    const layout = await this.elk.layout(data);<br>    this.renderLayout(layout);<br>  }<br><br>  renderLayout(layout) {<br>    this.container.selectAll(&#39;*&#39;).remove();<br>    <br>    // Create main SVG container<br>    this.svg = this.container<br>      .append(&#39;svg&#39;)<br>      .attr(&#39;width&#39;, this.config.width)<br>      .attr(&#39;height&#39;, this.config.height);<br><br>    // Create tooltip div<br>    const tooltip = this.container<br>      .append(&#39;div&#39;)<br>      .style(&#39;position&#39;, &#39;absolute&#39;)<br>      .style(&#39;visibility&#39;, &#39;hidden&#39;)<br>      .style(&#39;background-color&#39;, &#39;rgba(0, 0, 0, 0.8)&#39;)<br>      .style(&#39;color&#39;, &#39;#fff&#39;)<br>      .style(&#39;padding&#39;, &#39;8px 12px&#39;)<br>      .style(&#39;border-radius&#39;, &#39;4px&#39;)<br>      .style(&#39;font-size&#39;, &#39;12px&#39;)<br>      .style(&#39;pointer-events&#39;, &#39;none&#39;)<br>      .style(&#39;z-index&#39;, &#39;1000&#39;)<br>      .style(&#39;max-width&#39;, &#39;300px&#39;)<br>      .style(&#39;word-wrap&#39;, &#39;break-word&#39;);<br><br>    // Create group for zoom/pan transformations<br>    const g = this.svg.append(&#39;g&#39;);<br><br>    // Setup zoom behavior (mouse wheel zoom, drag to pan)<br>    const zoom = d3.zoom()<br>      .scaleExtent([0.1, 4])<br>      .on(&#39;zoom&#39;, (event) =&gt; {<br>        g.attr(&#39;transform&#39;, event.transform);<br>      });<br><br>    this.svg.call(zoom);<br><br>    // Define arrow markers for edge endpoints<br>    const defs = g.append(&#39;defs&#39;);<br>    defs.append(&#39;marker&#39;)<br>      .attr(&#39;id&#39;, &#39;elk-arrow&#39;)<br>      .attr(&#39;markerWidth&#39;, 10)<br>      .attr(&#39;markerHeight&#39;, 10)<br>      .attr(&#39;refX&#39;, 8)<br>      .attr(&#39;refY&#39;, 3)<br>      .attr(&#39;orient&#39;, &#39;auto&#39;)<br>      .append(&#39;polygon&#39;)<br>      .attr(&#39;points&#39;, &#39;0 0, 10 3, 0 6&#39;)<br>      .attr(&#39;fill&#39;, &#39;#999&#39;);<br><br>    // Define animated dashed line style<br>    const style = defs.append(&#39;style&#39;);<br>    style.text(`<br>      @keyframes dash {<br>        to {<br>          stroke-dashoffset: -20;<br>        }<br>      }<br>      .animated-edge {<br>        stroke-dasharray: 5, 5;<br>        animation: dash 1s linear infinite;<br>      }<br>    `);<br><br>    // Draw edges (connections between nodes)<br>    if (layout.edges) {<br>      g.append(&#39;g&#39;)<br>        .selectAll(&#39;path&#39;)<br>        .data(layout.edges)<br>        .enter()<br>        .append(&#39;path&#39;)<br>        .attr(&#39;d&#39;, d =&gt; {<br>          const points = d.sections[0].bendPoints || [];<br>          const start = d.sections[0].startPoint;<br>          const end = d.sections[0].endPoint;<br>          return `M ${start.x} ${start.y} ${points.map(p =&gt; `L ${p.x} ${p.y}`).join(&#39; &#39;)} L ${end.x} ${end.y}`;<br>        })<br>        .attr(&#39;stroke&#39;, &#39;#999&#39;)<br>        .attr(&#39;stroke-width&#39;, 2)<br>        .attr(&#39;fill&#39;, &#39;none&#39;)<br>        .attr(&#39;marker-end&#39;, &#39;url(#elk-arrow)&#39;)<br>        .attr(&#39;class&#39;, d =&gt; d.animated ? &#39;animated-edge&#39; : &#39;&#39;)<br>        .style(&#39;cursor&#39;, &#39;pointer&#39;)<br>        .on(&#39;click&#39;, (event, d) =&gt; {<br>          event.stopPropagation();<br>          this.emit(&#39;edgeClick&#39;, d);<br>        })<br>        .on(&#39;mouseover&#39;, (event, d) =&gt; {<br>          event.stopPropagation();<br>          d3.select(event.currentTarget).attr(&#39;stroke&#39;, &#39;#4dabf7&#39;).attr(&#39;stroke-width&#39;, 3);<br>          tooltip.style(&#39;visibility&#39;, &#39;visible&#39;)<br>            .html(`&lt;strong&gt;Edge:&lt;/strong&gt; ${d.id || &#39;Connection&#39;}&lt;br/&gt;${d.sources?.[0] || &#39;&#39;} → ${d.targets?.[0] || &#39;&#39;}`);<br>          this.emit(&#39;edgeHover&#39;, d);<br>        })<br>        .on(&#39;mousemove&#39;, (event) =&gt; {<br>          tooltip.style(&#39;top&#39;, (event.pageY - 10) + &#39;px&#39;)<br>            .style(&#39;left&#39;, (event.pageX + 10) + &#39;px&#39;);<br>        })<br>        .on(&#39;mouseout&#39;, (event, d) =&gt; {<br>          d3.select(event.currentTarget).attr(&#39;stroke&#39;, &#39;#999&#39;).attr(&#39;stroke-width&#39;, 2);<br>          tooltip.style(&#39;visibility&#39;, &#39;hidden&#39;);<br>        });<br>    }<br><br>    // Draw nodes (main rectangles representing equipment)<br>    if (layout.children) {<br>      const nodes = g.append(&#39;g&#39;)<br>        .selectAll(&#39;g&#39;)<br>        .data(layout.children)<br>        .enter()<br>        .append(&#39;g&#39;)<br>        .attr(&#39;transform&#39;, d =&gt; `translate(${d.x},${d.y})`)<br>        .style(&#39;cursor&#39;, &#39;pointer&#39;);<br><br>      // Draw node rectangles (equipment boxes)<br>      nodes.append(&#39;rect&#39;)<br>        .attr(&#39;width&#39;, d =&gt; d.width)<br>        .attr(&#39;height&#39;, d =&gt; d.height)<br>        .attr(&#39;fill&#39;, &#39;#69b3a2&#39;)<br>        .attr(&#39;stroke&#39;, &#39;#333&#39;)<br>        .attr(&#39;stroke-width&#39;, 2)<br>        .style(&#39;cursor&#39;, &#39;pointer&#39;)<br>        .on(&#39;click&#39;, (event, d) =&gt; {<br>          event.stopPropagation();<br>          this.emit(&#39;nodeClick&#39;, d);<br>        })<br>        .on(&#39;mouseover&#39;, (event, d) =&gt; {<br>          event.stopPropagation();<br>          d3.select(event.currentTarget).attr(&#39;fill&#39;, &#39;#51cf66&#39;);<br>          const tooltipContent = d.tooltip ? d.tooltip.join(&#39;&lt;br/&gt;&#39;) : <br>                                 (d.display ? d.display.join(&#39;&lt;br/&gt;&#39;) : <br>                                 `&lt;strong&gt;Node:&lt;/strong&gt; ${d.id}`);<br>          tooltip.style(&#39;visibility&#39;, &#39;visible&#39;).html(tooltipContent);<br>          this.emit(&#39;nodeHover&#39;, d);<br>        })<br>        .on(&#39;mousemove&#39;, (event) =&gt; {<br>          tooltip.style(&#39;top&#39;, (event.pageY - 10) + &#39;px&#39;)<br>            .style(&#39;left&#39;, (event.pageX + 10) + &#39;px&#39;);<br>        })<br>        .on(&#39;mouseout&#39;, (event, d) =&gt; {<br>          d3.select(event.currentTarget).attr(&#39;fill&#39;, &#39;#69b3a2&#39;);<br>          tooltip.style(&#39;visibility&#39;, &#39;hidden&#39;);<br>        });<br><br>      // Draw node labels (equipment IDs/names)<br>      nodes.append(&#39;text&#39;)<br>        .attr(&#39;text-anchor&#39;, &#39;middle&#39;)<br>        .attr(&#39;x&#39;, d =&gt; d.width / 2)<br>        .attr(&#39;y&#39;, d =&gt; d.height / 2)<br>        .attr(&#39;dy&#39;, &#39;0.3em&#39;)<br>        .attr(&#39;fill&#39;, &#39;#fff&#39;)<br>        .attr(&#39;font-size&#39;, &#39;12px&#39;)<br>        .style(&#39;pointer-events&#39;, &#39;none&#39;)<br>        .text(d =&gt; d.labels?.[0]?.text || &#39;&#39;);<br><br>      // Draw ports (small rectangles on nodes representing connection points)<br>      const self = this;<br>      nodes.each(function(d) {<br>        if (d.ports &amp;&amp; d.ports.length &gt; 0) {<br>          const nodeGroup = d3.select(this);<br>          <br>          d.ports.forEach(port =&gt; {<br>            // Draw port rectangle with larger hit area<br>            const portRect = nodeGroup.append(&#39;rect&#39;)<br>              .attr(&#39;x&#39;, port.x)<br>              .attr(&#39;y&#39;, port.y)<br>              .attr(&#39;width&#39;, port.width)<br>              .attr(&#39;height&#39;, port.height)<br>              .attr(&#39;fill&#39;, &#39;#ff6b6b&#39;)<br>              .attr(&#39;stroke&#39;, &#39;#c92a2a&#39;)<br>              .attr(&#39;stroke-width&#39;, 1)<br>              .style(&#39;cursor&#39;, &#39;pointer&#39;);<br><br>            // Add invisible larger hit area for better interaction<br>            const padding = 5;<br>            nodeGroup.append(&#39;rect&#39;)<br>              .attr(&#39;x&#39;, port.x - padding)<br>              .attr(&#39;y&#39;, port.y - padding)<br>              .attr(&#39;width&#39;, port.width + padding * 2)<br>              .attr(&#39;height&#39;, port.height + padding * 2)<br>              .attr(&#39;fill&#39;, &#39;transparent&#39;)<br>              .style(&#39;cursor&#39;, &#39;pointer&#39;)<br>              .on(&#39;click&#39;, function(event) {<br>                event.stopPropagation();<br>                portRect.attr(&#39;fill&#39;, &#39;#ff8787&#39;);<br>                self.emit(&#39;portClick&#39;, { node: d, port: port });<br>              })<br>              .on(&#39;mouseover&#39;, function(event) {<br>                event.stopPropagation();<br>                portRect.attr(&#39;fill&#39;, &#39;#ff8787&#39;);<br>                const tooltipContent = port.tooltip || <br>                                      `&lt;strong&gt;Port:&lt;/strong&gt; ${port.id}&lt;br/&gt;&lt;strong&gt;Manufacture:&lt;/strong&gt; ${port.portManufacture || &#39;N/A&#39;}`;<br>                tooltip.style(&#39;visibility&#39;, &#39;visible&#39;).html(tooltipContent);<br>                self.emit(&#39;portHover&#39;, { node: d, port: port });<br>              })<br>              .on(&#39;mousemove&#39;, function(event) {<br>                tooltip.style(&#39;top&#39;, (event.pageY - 10) + &#39;px&#39;)<br>                  .style(&#39;left&#39;, (event.pageX + 10) + &#39;px&#39;);<br>              })<br>              .on(&#39;mouseout&#39;, function(event) {<br>                portRect.attr(&#39;fill&#39;, &#39;#ff6b6b&#39;);<br>                tooltip.style(&#39;visibility&#39;, &#39;hidden&#39;);<br>              });<br><br>            // Draw port label (port number/name)<br>            if (port.labels &amp;&amp; port.labels[0]) {<br>              nodeGroup.append(&#39;text&#39;)<br>                .attr(&#39;x&#39;, port.x + port.width / 2)<br>                .attr(&#39;y&#39;, port.y + port.height / 2)<br>                .attr(&#39;text-anchor&#39;, &#39;middle&#39;)<br>                .attr(&#39;dy&#39;, &#39;0.3em&#39;)<br>                .attr(&#39;fill&#39;, &#39;#fff&#39;)<br>                .attr(&#39;font-size&#39;, &#39;8px&#39;)<br>                .style(&#39;pointer-events&#39;, &#39;none&#39;)<br>                .text(port.labels[0].text);<br>            }<br>          });<br>        }<br>      });<br>    }<br><br>    // Auto-fit: Calculate bounds and set initial zoom/pan to fit entire graph<br>    const bounds = this.calculateBounds(layout);<br>    const scale = Math.min(<br>      this.config.width / bounds.width,<br>      this.config.height / bounds.height<br>    ) * 0.9;<br>    <br>    const translateX = (this.config.width - bounds.width * scale) / 2 - bounds.minX * scale;<br>    const translateY = (this.config.height - bounds.height * scale) / 2 - bounds.minY * scale;<br>    <br>    this.svg.call(zoom.transform, d3.zoomIdentity.translate(translateX, translateY).scale(scale));<br>  }<br><br>  calculateBounds(layout) {<br>    if (!layout.children || layout.children.length === 0) {<br>      return { minX: 0, minY: 0, width: 100, height: 100 };<br>    }<br><br>    let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;<br>    <br>    layout.children.forEach(node =&gt; {<br>      minX = Math.min(minX, node.x);<br>      minY = Math.min(minY, node.y);<br>      maxX = Math.max(maxX, node.x + node.width);<br>      maxY = Math.max(maxY, node.y + node.height);<br>    });<br><br>    return {<br>      minX,<br>      minY,<br>      width: maxX - minX,<br>      height: maxY - minY<br>    };<br>  }<br>}</pre><p>This implementation file is appending elements using D3 JS to the diagram created by ELK , this can be modified as per the requirements.<br>Using this I have created a simple JS package and using it rendering the JSON [How to create JS package — <a href="https://medium.com/@mkushwah222/javascript-how-to-build-a-simple-js-npm-package-df9d9f52ee1c">https://medium.com/@mkushwah222/javascript-how-to-build-a-simple-js-npm-package-df9d9f52ee1c</a>]</p><pre>//package.json<br>{<br>  &quot;name&quot;: &quot;visualizer&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;main&quot;: &quot;dist/visualizer.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;dev&quot;: &quot;webpack serve --mode development&quot;,<br>    &quot;build&quot;: &quot;webpack --mode production&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;webpack&quot;: &quot;^5.89.0&quot;,<br>    &quot;webpack-cli&quot;: &quot;^5.1.4&quot;,<br>    &quot;webpack-dev-server&quot;: &quot;^4.15.1&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;d3&quot;: &quot;^7.8.5&quot;,<br>    &quot;elkjs&quot;: &quot;^0.9.0&quot;<br>  },<br>  &quot;peerDependencies&quot;: {<br>    &quot;d3&quot;: &quot;^7.0.0&quot;,<br>    &quot;elkjs&quot;: &quot;^0.9.0&quot;<br>  }<br>}</pre><pre>// webpack.config.js<br><br>const path = require(&#39;path&#39;);<br><br>module.exports = {<br>  entry: &#39;./src/index.js&#39;,<br>  output: {<br>    path: path.resolve(__dirname, &#39;dist&#39;),<br>    filename: &#39;visualizer.js&#39;,<br>    library: &#39;Visualizer&#39;,<br>    libraryTarget: &#39;umd&#39;,<br>    globalObject: &#39;this&#39;<br>  },<br>  devServer: {<br>    static: [&#39;./&#39;, &#39;./demo&#39;],<br>    port: 8080,<br>    hot: true<br>  },<br>  externals: {<br>    d3: &#39;d3&#39;,<br>    &#39;elkjs/lib/elk.bundled.js&#39;: &#39;ELK&#39;<br>  }<br>};<br><br>// We mark d3 and elkjs as externals in webpack. This means they won&#39;t be <br>// bundled into visualizer.js — instead, the consuming application provides<br>// them. This keeps our package lightweight and avoids version conflicts. <br>// In the demo, we load them separately via CDN scripts. If someone installs <br>// our package via npm, they&#39;d install d3 and elkjs themselves <br>// (that&#39;s what peerDependencies in package.json signals).</pre><pre>// src/lib/elk.js [code explaind above as implementation]</pre><pre>&lt;!-- demo/index.html --&gt;<br><br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br><br>&lt;head&gt;<br>  &lt;title&gt;D3 Layout Renderer Demo&lt;/title&gt;<br>  &lt;style&gt;<br>    body {<br>      font-family: Arial, sans-serif;<br>      padding: 16px;<br>    }<br>  &lt;/style&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br><br>  &lt;div id=&quot;container&quot;&gt;&lt;/div&gt;<br>  &lt;div id=&quot;events&quot;&gt;<br>    &lt;h3 style=&quot;margin-top: 0;&quot;&gt;Events:&lt;/h3&gt;<br>    &lt;div id=&quot;event-log&quot;&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br><br>  &lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;<br>  &lt;script src=&quot;https://unpkg.com/elkjs@0.9.0/lib/elk.bundled.js&quot;&gt;&lt;/script&gt;<br>  &lt;script src=&quot;../dist/visualizer.js&quot;&gt;&lt;/script&gt;<br>  &lt;script&gt;<br>    const config = { width: 800, height: 600 };<br><br><br><br>    let currentRenderer = null;<br><br>    async function renderExample(type) {<br>      document.getElementById(&#39;container&#39;).innerHTML = &#39;&#39;;<br><br>      currentRenderer = new Visualizer.ElkViz(&#39;#container&#39;, { width: 1200, height: 800 });<br>      currentRenderer<br>        .on(&#39;nodeClick&#39;, d =&gt; {<br>          document.getElementById(&#39;event-log&#39;).innerHTML = `Node Clicked: ${d.id}`;<br>        })<br>        .on(&#39;nodeHover&#39;, d =&gt; {<br>          document.getElementById(&#39;event-log&#39;).innerHTML = `Node Hovered: ${d.id}`;<br>        })<br>        .on(&#39;edgeClick&#39;, d =&gt; {<br>          document.getElementById(&#39;event-log&#39;).innerHTML = `Edge Clicked: ${d.id || &#39;edge&#39;}`;<br>        })<br>        .on(&#39;edgeHover&#39;, d =&gt; {<br>          document.getElementById(&#39;event-log&#39;).innerHTML = `Edge Hovered: ${d.id || &#39;edge&#39;}`;<br>        })<br>        .on(&#39;portClick&#39;, data =&gt; {<br>          document.getElementById(&#39;event-log&#39;).innerHTML = `Port Clicked: ${data.port.id} on Node: ${data.node.id}`;<br>        })<br>        .on(&#39;portHover&#39;, data =&gt; {<br>          document.getElementById(&#39;event-log&#39;).innerHTML = `Port Hovered: ${data.port.id} on Node: ${data.node.id}`;<br>        });<br>      const response = await fetch(&#39;./elk-example.json&#39;);<br>      const elkJsonData = await response.json();<br>      await currentRenderer.render(elkJsonData);<br>    }<br><br>    renderExample(&#39;elkJson&#39;);<br>  &lt;/script&gt;<br>&lt;/body&gt;<br><br>&lt;/html&gt;</pre><pre>// demo/elk-example.json<br>{<br>    &quot;id&quot;: &quot;root&quot;,<br>    &quot;layoutOptions&quot;: {<br>        &quot;elk.algorithm&quot;: &quot;layered&quot;,<br>        &quot;elk.direction&quot;: &quot;DOWN&quot;,<br>        &quot;elk.spacing.nodeNode&quot;: &quot;80&quot;,<br>        &quot;elk.layered.spacing.nodeNodeBetweenLayers&quot;: &quot;100&quot;,<br>        &quot;elk.edgeRouting&quot;: &quot;ORTHOGONAL&quot;<br>    },<br>    &quot;children&quot;: [<br>        {<br>            &quot;id&quot;: &quot;node1&quot;,<br>            &quot;width&quot;: 120,<br>            &quot;height&quot;: 80,<br>            &quot;labels&quot;: [<br>                {<br>                    &quot;text&quot;: &quot;API Gateway&quot;<br>                }<br>            ],<br>            &quot;ports&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node1_port1&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;SOUTH&quot;,<br>                        &quot;port.index&quot;: &quot;0&quot;<br>                    },<br>                    &quot;labels&quot;: [{&quot;text&quot;: &quot;P1&quot;}]<br>                },<br>                {<br>                    &quot;id&quot;: &quot;node1_port2&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;SOUTH&quot;,<br>                        &quot;port.index&quot;: &quot;1&quot;<br>                    },<br>                    &quot;labels&quot;: [{&quot;text&quot;: &quot;P2&quot;}]<br>                },<br>                {<br>                    &quot;id&quot;: &quot;node1_port3&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;SOUTH&quot;,<br>                        &quot;port.index&quot;: &quot;2&quot;<br>                    },<br>                    &quot;labels&quot;: [{&quot;text&quot;: &quot;P3&quot;}]<br>                }<br>            ]<br>        },<br>        {<br>            &quot;id&quot;: &quot;node2&quot;,<br>            &quot;width&quot;: 120,<br>            &quot;height&quot;: 80,<br>            &quot;labels&quot;: [<br>                {<br>                    &quot;text&quot;: &quot;Auth Service&quot;<br>                }<br>            ],<br>            &quot;ports&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node2_port1&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;NORTH&quot;<br>                    }<br>                },<br>                {<br>                    &quot;id&quot;: &quot;node2_port2&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;SOUTH&quot;<br>                    }<br>                }<br>            ]<br>        },<br>        {<br>            &quot;id&quot;: &quot;node3&quot;,<br>            &quot;width&quot;: 120,<br>            &quot;height&quot;: 80,<br>            &quot;labels&quot;: [<br>                {<br>                    &quot;text&quot;: &quot;User Service&quot;<br>                }<br>            ],<br>            &quot;ports&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node3_port1&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;NORTH&quot;<br>                    }<br>                },<br>                {<br>                    &quot;id&quot;: &quot;node3_port2&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;SOUTH&quot;<br>                    }<br>                }<br>            ]<br>        },<br>        {<br>            &quot;id&quot;: &quot;node4&quot;,<br>            &quot;width&quot;: 300,<br>            &quot;height&quot;: 200,<br>            &quot;labels&quot;: [<br>                {<br>                    &quot;text&quot;: &quot;Order Service&quot;<br>                }<br>            ],<br>            &quot;ports&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node4_port1&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;NORTH&quot;<br>                    },<br>                    &quot;labels&quot;: [{&quot;text&quot;: &quot;IN&quot;}]<br>                },<br>                {<br>                    &quot;id&quot;: &quot;node4_port2&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;SOUTH&quot;,<br>                        &quot;port.index&quot;: &quot;0&quot;<br>                    },<br>                    &quot;labels&quot;: [{&quot;text&quot;: &quot;DB&quot;}]<br>                },<br>                {<br>                    &quot;id&quot;: &quot;node4_port3&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;SOUTH&quot;,<br>                        &quot;port.index&quot;: &quot;1&quot;<br>                    },<br>                    &quot;labels&quot;: [{&quot;text&quot;: &quot;PAY&quot;}]<br>                },<br>                {<br>                    &quot;id&quot;: &quot;node4_port4&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;SOUTH&quot;,<br>                        &quot;port.index&quot;: &quot;2&quot;<br>                    },<br>                    &quot;labels&quot;: [{&quot;text&quot;: &quot;MSG&quot;}]<br>                }<br>            ],<br>            &quot;children&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node4_child1&quot;,<br>                    &quot;width&quot;: 80,<br>                    &quot;height&quot;: 40,<br>                    &quot;labels&quot;: [{&quot;text&quot;: &quot;Validator&quot;}]<br>                },<br>                {<br>                    &quot;id&quot;: &quot;node4_child2&quot;,<br>                    &quot;width&quot;: 80,<br>                    &quot;height&quot;: 40,<br>                    &quot;labels&quot;: [{&quot;text&quot;: &quot;Processor&quot;}]<br>                },<br>                {<br>                    &quot;id&quot;: &quot;node4_child3&quot;,<br>                    &quot;width&quot;: 80,<br>                    &quot;height&quot;: 40,<br>                    &quot;labels&quot;: [{&quot;text&quot;: &quot;Logger&quot;}]<br>                }<br>            ],<br>            &quot;edges&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;internal_edge1&quot;,<br>                    &quot;sources&quot;: [&quot;node4_child1&quot;],<br>                    &quot;targets&quot;: [&quot;node4_child2&quot;]<br>                },<br>                {<br>                    &quot;id&quot;: &quot;internal_edge2&quot;,<br>                    &quot;sources&quot;: [&quot;node4_child2&quot;],<br>                    &quot;targets&quot;: [&quot;node4_child3&quot;]<br>                }<br>            ]<br>        },<br>        {<br>            &quot;id&quot;: &quot;node5&quot;,<br>            &quot;width&quot;: 120,<br>            &quot;height&quot;: 80,<br>            &quot;labels&quot;: [<br>                {<br>                    &quot;text&quot;: &quot;Payment Service&quot;<br>                }<br>            ],<br>            &quot;ports&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node5_port1&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;NORTH&quot;<br>                    }<br>                },<br>                {<br>                    &quot;id&quot;: &quot;node5_port2&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;SOUTH&quot;<br>                    }<br>                }<br>            ]<br>        },<br>        {<br>            &quot;id&quot;: &quot;node6&quot;,<br>            &quot;width&quot;: 120,<br>            &quot;height&quot;: 80,<br>            &quot;labels&quot;: [<br>                {<br>                    &quot;text&quot;: &quot;User Database&quot;<br>                }<br>            ],<br>            &quot;ports&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node6_port1&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;NORTH&quot;<br>                    }<br>                }<br>            ]<br>        },<br>        {<br>            &quot;id&quot;: &quot;node7&quot;,<br>            &quot;width&quot;: 120,<br>            &quot;height&quot;: 80,<br>            &quot;labels&quot;: [<br>                {<br>                    &quot;text&quot;: &quot;Order Database&quot;<br>                }<br>            ],<br>            &quot;ports&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node7_port1&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;NORTH&quot;<br>                    }<br>                }<br>            ]<br>        },<br>        {<br>            &quot;id&quot;: &quot;node8&quot;,<br>            &quot;width&quot;: 120,<br>            &quot;height&quot;: 80,<br>            &quot;labels&quot;: [<br>                {<br>                    &quot;text&quot;: &quot;Cache Server&quot;<br>                }<br>            ],<br>            &quot;ports&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node8_port1&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;NORTH&quot;<br>                    }<br>                }<br>            ]<br>        },<br>        {<br>            &quot;id&quot;: &quot;node9&quot;,<br>            &quot;width&quot;: 120,<br>            &quot;height&quot;: 80,<br>            &quot;labels&quot;: [<br>                {<br>                    &quot;text&quot;: &quot;Message Queue&quot;<br>                }<br>            ],<br>            &quot;ports&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node9_port1&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;NORTH&quot;<br>                    }<br>                }<br>            ]<br>        },<br>        {<br>            &quot;id&quot;: &quot;node10&quot;,<br>            &quot;width&quot;: 120,<br>            &quot;height&quot;: 80,<br>            &quot;labels&quot;: [<br>                {<br>                    &quot;text&quot;: &quot;Notification Service&quot;<br>                }<br>            ],<br>            &quot;ports&quot;: [<br>                {<br>                    &quot;id&quot;: &quot;node10_port1&quot;,<br>                    &quot;width&quot;: 10,<br>                    &quot;height&quot;: 10,<br>                    &quot;properties&quot;: {<br>                        &quot;port.side&quot;: &quot;NORTH&quot;<br>                    }<br>                }<br>            ]<br>        }<br>    ],<br>    &quot;edges&quot;: [<br>        {<br>            &quot;id&quot;: &quot;edge1&quot;,<br>            &quot;sources&quot;: [&quot;node1_port1&quot;],<br>            &quot;targets&quot;: [&quot;node2_port1&quot;],<br>            &quot;animated&quot;: true<br>        },<br>        {<br>            &quot;id&quot;: &quot;edge2&quot;,<br>            &quot;sources&quot;: [&quot;node1_port2&quot;],<br>            &quot;targets&quot;: [&quot;node3_port1&quot;]<br>        },<br>        {<br>            &quot;id&quot;: &quot;edge3&quot;,<br>            &quot;sources&quot;: [&quot;node1_port3&quot;],<br>            &quot;targets&quot;: [&quot;node4_port1&quot;]<br>        },<br>        {<br>            &quot;id&quot;: &quot;edge4&quot;,<br>            &quot;sources&quot;: [&quot;node3_port2&quot;],<br>            &quot;targets&quot;: [&quot;node6_port1&quot;]<br>        },<br>        {<br>            &quot;id&quot;: &quot;edge5&quot;,<br>            &quot;sources&quot;: [&quot;node4_port2&quot;],<br>            &quot;targets&quot;: [&quot;node7_port1&quot;]<br>        },<br>        {<br>            &quot;id&quot;: &quot;edge6&quot;,<br>            &quot;sources&quot;: [&quot;node4_port3&quot;],<br>            &quot;targets&quot;: [&quot;node5_port1&quot;],<br>            &quot;animated&quot;: true<br>        },<br>        {<br>            &quot;id&quot;: &quot;edge7&quot;,<br>            &quot;sources&quot;: [&quot;node2_port2&quot;],<br>            &quot;targets&quot;: [&quot;node8_port1&quot;]<br>        },<br>        {<br>            &quot;id&quot;: &quot;edge8&quot;,<br>            &quot;sources&quot;: [&quot;node5_port2&quot;],<br>            &quot;targets&quot;: [&quot;node9_port1&quot;]<br>        },<br>        {<br>            &quot;id&quot;: &quot;edge9&quot;,<br>            &quot;sources&quot;: [&quot;node4_port4&quot;],<br>            &quot;targets&quot;: [&quot;node10_port1&quot;]<br>        }<br>    ]<br>}</pre><p>To run the package demo =<strong><em> npm install</em></strong> -&gt; <strong><em>npm run build</em></strong> -&gt; <strong><em>npm run dev</em></strong></p><p>Hope its useful for building such kind of visualization.</p><p>Thanks cheers!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61b0ec7725e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript : Write your own Browser(Edge/Chrome) Extension]]></title>
            <link>https://medium.com/@mkushwah222/javascript-write-your-own-browser-edge-chrome-extension-3e7fbb1b9478?source=rss-ea5f8bdddc5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e7fbb1b9478</guid>
            <category><![CDATA[edge]]></category>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[browser-extension]]></category>
            <dc:creator><![CDATA[Mohit Kushwah]]></dc:creator>
            <pubDate>Sat, 02 May 2026 10:16:20 GMT</pubDate>
            <atom:updated>2026-05-02T10:16:20.718Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello there</p><p>This is for all web developers, sometime we all have been keep looking for a browser extension that can help us in development.</p><p>So here we are , why can’t we just write our own one, I have took example for <strong><em>Color Picker</em></strong></p><p>Step 1 : Create a folder eg. <strong><em>browser-extension</em></strong></p><p>Step 2 : create <strong><em>manifest.json, </em></strong>I have this icon.png in the folder</p><pre>{<br>  &quot;manifest_version&quot;: 3,<br>  &quot;name&quot;: &quot;Color Picker&quot;,<br>  &quot;version&quot;: &quot;1.0&quot;,<br>  &quot;description&quot;: &quot;Pick a color and preview it with HEX and RGB values.&quot;,<br>  &quot;permissions&quot;: [<br>    &quot;activeTab&quot;<br>  ],<br>  &quot;action&quot;: {<br>    &quot;default_popup&quot;: &quot;popup.html&quot;,<br>    &quot;default_icon&quot;: {<br>      &quot;48&quot;: &quot;icon.png&quot;,<br>      &quot;128&quot;: &quot;icon.png&quot;<br>    }<br>  },<br>  &quot;icons&quot;: {<br>    &quot;48&quot;: &quot;icon.png&quot;,<br>    &quot;128&quot;: &quot;icon.png&quot;<br>  }<br>}</pre><p>Step 3 : create <strong><em>popup.html</em></strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot; /&gt;<br>  &lt;title&gt;Color Picker&lt;/title&gt;<br>  &lt;link rel=&quot;stylesheet&quot; href=&quot;popup.css&quot; /&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;h2&gt;Color Picker&lt;/h2&gt;<br>  &lt;button id=&quot;pickBtn&quot;&gt;🎯 Pick from Page&lt;/button&gt;<br>  &lt;div id=&quot;preview&quot;&gt;&lt;/div&gt;<br>  &lt;div class=&quot;values&quot;&gt;<br>    &lt;span id=&quot;hexVal&quot;&gt;—&lt;/span&gt;<br>    &lt;span id=&quot;rgbVal&quot;&gt;—&lt;/span&gt;<br>  &lt;/div&gt;<br>  &lt;button id=&quot;copyBtn&quot; disabled&gt;Copy HEX&lt;/button&gt;<br>  &lt;script src=&quot;popup.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Step 4 : create <strong><em>popup.css</em></strong></p><pre>body {<br>  width: 220px;<br>  padding: 16px;<br>  font-family: sans-serif;<br>  text-align: center;<br>}<br><br>h2 {<br>  margin: 0 0 12px;<br>  font-size: 16px;<br>}<br><br>#pickBtn {<br>  width: 100%;<br>  padding: 8px;<br>  font-size: 14px;<br>  cursor: pointer;<br>  border: none;<br>  border-radius: 6px;<br>  background: #3b82f6;<br>  color: white;<br>  margin-bottom: 12px;<br>}<br><br>#pickBtn:hover {<br>  background: #2563eb;<br>}<br><br>#preview {<br>  width: 100%;<br>  height: 80px;<br>  border-radius: 8px;<br>  border: 1px solid #ddd;<br>  background-color: #f0f0f0;<br>  transition: background-color 0.2s;<br>  margin-bottom: 10px;<br>}<br><br>.values {<br>  display: flex;<br>  justify-content: space-between;<br>  font-size: 12px;<br>  color: #444;<br>  margin-bottom: 10px;<br>}<br><br>#copyBtn {<br>  width: 100%;<br>  padding: 6px;<br>  cursor: pointer;<br>  border: 1px solid #aaa;<br>  border-radius: 4px;<br>  background: #f5f5f5;<br>  font-size: 13px;<br>}<br><br>#copyBtn:disabled {<br>  opacity: 0.4;<br>  cursor: default;<br>}<br><br>#copyBtn:not(:disabled):hover {<br>  background: #e0e0e0;<br>}</pre><p>Step 5 : create <strong><em>popup.js</em></strong></p><pre>const pickBtn = document.getElementById(&quot;pickBtn&quot;);<br>const preview = document.getElementById(&quot;preview&quot;);<br>const hexVal = document.getElementById(&quot;hexVal&quot;);<br>const rgbVal = document.getElementById(&quot;rgbVal&quot;);<br>const copyBtn = document.getElementById(&quot;copyBtn&quot;);<br><br>function hexToRgb(hex) {<br>  const r = parseInt(hex.slice(1, 3), 16);<br>  const g = parseInt(hex.slice(3, 5), 16);<br>  const b = parseInt(hex.slice(5, 7), 16);<br>  return `rgb(${r}, ${g}, ${b})`;<br>}<br><br>function setColor(hex) {<br>  preview.style.backgroundColor = hex;<br>  hexVal.textContent = hex;<br>  rgbVal.textContent = hexToRgb(hex);<br>  copyBtn.disabled = false;<br>}<br><br>pickBtn.addEventListener(&quot;click&quot;, async () =&gt; {<br>  if (!window.EyeDropper) {<br>    hexVal.textContent = &quot;Not supported&quot;;<br>    return;<br>  }<br>  try {<br>    const result = await new EyeDropper().open();<br>    setColor(result.sRGBHex);<br>  } catch {<br>    // user cancelled<br>  }<br>});<br><br>copyBtn.addEventListener(&quot;click&quot;, () =&gt; {<br>  navigator.clipboard.writeText(hexVal.textContent).then(() =&gt; {<br>    copyBtn.textContent = &quot;Copied!&quot;;<br>    setTimeout(() =&gt; (copyBtn.textContent = &quot;Copy HEX&quot;), 1500);<br>  });<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*mKsHoRB_2NCgX_oRROCD8w.png" /></figure><p>That’s it, its done, we can add it in edge/chrome by following —</p><p>Go to Extensions -&gt; Manage Extensions -&gt; Enable developer mode -&gt; load unpacked -&gt; select the folder <em>browser-extension, </em>we can pin it too, if we want.</p><p>This is just a example, we can customize it , add anything we want.</p><p>Thanks!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e7fbb1b9478" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular : Documentation webapp using Angular 18 and Storybook]]></title>
            <link>https://medium.com/@mkushwah222/angular-documentation-webapp-using-angular-18-and-storybook-2a4965bcf8ca?source=rss-ea5f8bdddc5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a4965bcf8ca</guid>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[storybook]]></category>
            <dc:creator><![CDATA[Mohit Kushwah]]></dc:creator>
            <pubDate>Sat, 25 Apr 2026 13:19:48 GMT</pubDate>
            <atom:updated>2026-04-25T13:34:38.391Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello there</p><p>We have lot of ways to arrange documentation about code components or simple text or anything else.</p><p>Today we will build a webapp for documentation which includes <strong><em>reading , preview and interacting</em></strong> using storybook.</p><p><strong>## Project Structure</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*hO95QFPgUeGsu6lBKJNvMg.png" /></figure><p><strong>## Step 1: Scaffold the Angular 18 Project</strong></p><p>create fresh angular 18 app and update package.json and angular.json to add <strong><em>prime ng</em></strong> and <strong><em>storybook</em></strong></p><pre>// package.json<br>{<br>  &quot;name&quot;: &quot;storybook&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;context&quot;: &quot;storybook-app&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;ng&quot;: &quot;ng&quot;,<br>    &quot;start&quot;: &quot;npm run storybook&quot;,<br>    &quot;build&quot;: &quot;npm run build-storybook&quot;,<br>    &quot;storybook&quot;: &quot;ng run storybook-app:storybook&quot;,<br>    &quot;build-storybook&quot;: &quot;ng run storybook-app:build-storybook&quot;<br>  },<br>  &quot;private&quot;: true,<br>  &quot;dependencies&quot;: {<br>    &quot;@angular/animations&quot;: &quot;^18.2.0&quot;,<br>    &quot;@angular/common&quot;: &quot;^18.2.0&quot;,<br>    &quot;@angular/compiler&quot;: &quot;^18.2.0&quot;,<br>    &quot;@angular/core&quot;: &quot;^18.2.0&quot;,<br>    &quot;@angular/forms&quot;: &quot;^18.2.0&quot;,<br>    &quot;@angular/platform-browser&quot;: &quot;^18.2.0&quot;,<br>    &quot;@angular/platform-browser-dynamic&quot;: &quot;^18.2.0&quot;,<br>    &quot;@angular/router&quot;: &quot;^18.2.0&quot;,<br>    &quot;ngx-toastr&quot;: &quot;^19.0.0&quot;,<br>    &quot;@primeng/themes&quot;: &quot;^18.0.2&quot;,<br>    &quot;primeicons&quot;: &quot;^7.0.0&quot;,<br>    &quot;primeng&quot;: &quot;^18.0.2&quot;,<br>    &quot;rxjs&quot;: &quot;~7.8.0&quot;,<br>    &quot;tslib&quot;: &quot;^2.3.0&quot;,<br>    &quot;zone.js&quot;: &quot;~0.14.10&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;@angular-devkit/build-angular&quot;: &quot;^18.2.21&quot;,<br>    &quot;@angular/cli&quot;: &quot;^18.2.21&quot;,<br>    &quot;@angular/compiler-cli&quot;: &quot;^18.2.0&quot;,<br>    &quot;@compodoc/compodoc&quot;: &quot;^1.1.26&quot;,<br>    &quot;@storybook/addon-actions&quot;: &quot;^9.0.8&quot;,<br>    &quot;@storybook/addon-essentials&quot;: &quot;^8.4.4&quot;,<br>    &quot;@storybook/angular&quot;: &quot;^8.4.4&quot;,<br>    &quot;@types/jasmine&quot;: &quot;~5.1.0&quot;,<br>    &quot;jasmine-core&quot;: &quot;~5.2.0&quot;,<br>    &quot;karma&quot;: &quot;~6.4.0&quot;,<br>    &quot;karma-chrome-launcher&quot;: &quot;~3.2.0&quot;,<br>    &quot;karma-coverage&quot;: &quot;~2.2.0&quot;,<br>    &quot;karma-jasmine&quot;: &quot;~5.1.0&quot;,<br>    &quot;karma-jasmine-html-reporter&quot;: &quot;~2.1.0&quot;,<br>    &quot;storybook&quot;: &quot;^8.4.4&quot;,<br>    &quot;typescript&quot;: &quot;~5.5.2&quot;<br>  },<br>  &quot;overrides&quot;: {<br>    &quot;chokidar&quot;: &quot;3.5.3&quot;<br>  }<br>}</pre><pre>// angular.json<br>{<br>  &quot;$schema&quot;: &quot;./node_modules/@angular/cli/lib/config/schema.json&quot;,<br>  &quot;version&quot;: 1,<br>  &quot;newProjectRoot&quot;: &quot;projects&quot;,<br>  &quot;projects&quot;: {<br>    &quot;storybook-app&quot;: {<br>      &quot;projectType&quot;: &quot;application&quot;,<br>      &quot;schematics&quot;: {<br>        &quot;@schematics/angular:component&quot;: {<br>          &quot;style&quot;: &quot;scss&quot;,<br>          &quot;skipTests&quot;: true<br>        },<br>        &quot;@schematics/angular:class&quot;: {<br>          &quot;skipTests&quot;: true<br>        },<br>        &quot;@schematics/angular:directive&quot;: {<br>          &quot;skipTests&quot;: true<br>        },<br>        &quot;@schematics/angular:guard&quot;: {<br>          &quot;skipTests&quot;: true<br>        },<br>        &quot;@schematics/angular:interceptor&quot;: {<br>          &quot;skipTests&quot;: true<br>        },<br>        &quot;@schematics/angular:pipe&quot;: {<br>          &quot;skipTests&quot;: true<br>        },<br>        &quot;@schematics/angular:resolver&quot;: {<br>          &quot;skipTests&quot;: true<br>        },<br>        &quot;@schematics/angular:service&quot;: {<br>          &quot;skipTests&quot;: true<br>        }<br>      },<br>      &quot;root&quot;: &quot;&quot;,<br>      &quot;sourceRoot&quot;: &quot;src&quot;,<br>      &quot;prefix&quot;: &quot;app&quot;,<br>      &quot;architect&quot;: {<br>        &quot;build&quot;: {<br>          &quot;builder&quot;: &quot;@angular-devkit/build-angular:application&quot;,<br>          &quot;options&quot;: {<br>            &quot;outputPath&quot;: {<br>              &quot;base&quot;: &quot;dist/storybook-app&quot;,<br>              &quot;browser&quot;: &quot;&quot;<br>            },<br>            &quot;index&quot;: &quot;src/index.html&quot;,<br>            &quot;browser&quot;: &quot;src/main.ts&quot;,<br>            &quot;polyfills&quot;: [<br>              &quot;zone.js&quot;<br>            ],<br>            &quot;tsConfig&quot;: &quot;tsconfig.app.json&quot;,<br>            &quot;inlineStyleLanguage&quot;: &quot;scss&quot;,<br>            &quot;assets&quot;: [<br>              {<br>                &quot;glob&quot;: &quot;**/*&quot;,<br>                &quot;input&quot;: &quot;public&quot;<br>              }<br>            ],<br>            &quot;styles&quot;: [<br>              &quot;node_modules/primeicons/primeicons.css&quot;,<br>              &quot;src/styles.scss&quot;<br>            ],<br>            &quot;scripts&quot;: []<br>          },<br>          &quot;configurations&quot;: {<br>            &quot;production&quot;: {<br>              &quot;budgets&quot;: [<br>                {<br>                  &quot;type&quot;: &quot;initial&quot;,<br>                  &quot;maximumWarning&quot;: &quot;500kB&quot;,<br>                  &quot;maximumError&quot;: &quot;1MB&quot;<br>                },<br>                {<br>                  &quot;type&quot;: &quot;anyComponentStyle&quot;,<br>                  &quot;maximumWarning&quot;: &quot;2kB&quot;,<br>                  &quot;maximumError&quot;: &quot;4kB&quot;<br>                }<br>              ],<br>              &quot;outputHashing&quot;: &quot;all&quot;,<br>              &quot;optimization&quot;: true,<br>              &quot;sourceMap&quot;: false<br>            },<br>            &quot;development&quot;: {<br>              &quot;optimization&quot;: true,<br>              &quot;extractLicenses&quot;: false,<br>              &quot;sourceMap&quot;: false<br>            }<br>          },<br>          &quot;defaultConfiguration&quot;: &quot;production&quot;<br>        },<br>        &quot;serve&quot;: {<br>          &quot;builder&quot;: &quot;@angular-devkit/build-angular:dev-server&quot;,<br>          &quot;configurations&quot;: {<br>            &quot;production&quot;: {<br>              &quot;buildTarget&quot;: &quot;storybook-app:build:production&quot;<br>            },<br>            &quot;development&quot;: {<br>              &quot;buildTarget&quot;: &quot;storybook-app:build:development&quot;<br>            }<br>          },<br>          &quot;defaultConfiguration&quot;: &quot;development&quot;<br>        },<br>        &quot;extract-i18n&quot;: {<br>          &quot;builder&quot;: &quot;@angular-devkit/build-angular:extract-i18n&quot;<br>        },<br>        &quot;test&quot;: {<br>          &quot;builder&quot;: &quot;@angular-devkit/build-angular:karma&quot;,<br>          &quot;options&quot;: {<br>            &quot;polyfills&quot;: [<br>              &quot;zone.js&quot;,<br>              &quot;zone.js/testing&quot;<br>            ],<br>            &quot;tsConfig&quot;: &quot;tsconfig.spec.json&quot;,<br>            &quot;inlineStyleLanguage&quot;: &quot;scss&quot;,<br>            &quot;assets&quot;: [<br>              {<br>                &quot;glob&quot;: &quot;**/*&quot;,<br>                &quot;input&quot;: &quot;public&quot;<br>              }<br>            ],<br>            &quot;styles&quot;: [<br>              &quot;node_modules/primeicons/primeicons.css&quot;,<br>              &quot;src/styles.scss&quot;<br>            ],<br>            &quot;scripts&quot;: []<br>          }<br>        },<br>        &quot;storybook&quot;: {<br>          &quot;builder&quot;: &quot;@storybook/angular:start-storybook&quot;,<br>          &quot;options&quot;: {<br>            &quot;configDir&quot;: &quot;.storybook&quot;,<br>            &quot;browserTarget&quot;: &quot;storybook-app:build&quot;,<br>            &quot;port&quot;: 6006,<br>            &quot;styles&quot;: [<br>              &quot;node_modules/primeicons/primeicons.css&quot;,<br>              &quot;src/styles.scss&quot;<br>            ]<br>          }<br>        },<br>        &quot;build-storybook&quot;: {<br>          &quot;builder&quot;: &quot;@storybook/angular:build-storybook&quot;,<br>          &quot;options&quot;: {<br>            &quot;configDir&quot;: &quot;.storybook&quot;,<br>            &quot;browserTarget&quot;: &quot;storybook-app:build&quot;,<br>            &quot;outputDir&quot;: &quot;dist/storybook-app&quot;,<br>            &quot;styles&quot;: [<br>              &quot;node_modules/primeicons/primeicons.css&quot;,<br>              &quot;src/styles.scss&quot;<br>            ]<br>          }<br>        }<br>      }<br>    }<br>  }<br>}</pre><p><strong>## Step 2 : </strong>Now run this npx storybook@8.4.4 init to add storybook related file and folder or manually add .storybook and stories folders.</p><p>Manual: .storybook folder at root with these files</p><pre>// .storybook/main.ts<br>import type { StorybookConfig } from &#39;@storybook/angular&#39;;<br><br>const config: StorybookConfig = {<br>  stories: [<br>    &#39;../src/**/*.stories.@(ts|mdx)&#39;,<br>    &#39;../src/**/*.mdx&#39;,<br>  ],<br>  addons: [&#39;@storybook/addon-essentials&#39;],<br>  framework: { name: &#39;@storybook/angular&#39;, options: {} },<br>  docs: { autodocs: &#39;tag&#39; },<br>  staticDirs: [&#39;../.storybook/public&#39;],<br>};<br><br>export default config;</pre><pre>// .storybook/manager.ts<br>import { addons } from &#39;@storybook/manager-api&#39;;<br>import { create } from &#39;@storybook/theming/create&#39;;<br><br>console.log(&#39;Storybook init&#39;);<br><br>addons.setConfig({<br>  theme: create({<br>    base: &quot;light&quot;,<br>    brandTitle: &#39;Docs&#39;,<br>    brandImage: &#39;test.svg&#39;, // put this at .storybook/public/test.svg<br>    brandUrl: &#39;#&#39;,<br>  }),<br>});</pre><pre>// .storybook/preview-head.html<br><br>&lt;link rel=&quot;icon&quot; type=&quot;image/x-icon&quot; href=&quot;/favicon.ico&quot; /&gt;<br>&lt;title&gt;Storybook&lt;/title&gt;<br>&lt;style&gt;<br>  /* Make the story area give the viz room */<br>  #storybook-root,<br>  #root {<br>    height: 100%;<br>  }<br><br>  .viz-container {<br>    width: 100%;<br>    height: 100%;<br>    min-height: 600px;<br>  }<br>&lt;/style&gt;</pre><pre>// .storybook/preview.ts<br>import { bootstrapApplication } from &#39;@angular/platform-browser&#39;;<br>import { applicationConfig, type Preview } from &#39;@storybook/angular&#39;;<br>import { AppComponent } from &#39;../src/app/app.component&#39;;<br>import { appConfig } from &#39;../src/app/app.config&#39;;<br><br>const appRoot = document.createElement(&#39;app-root&#39;);<br>document.body.appendChild(appRoot);<br>bootstrapApplication(AppComponent, appConfig).catch(console.error);<br><br><br>const preview: Preview = {<br>  decorators: [<br>    applicationConfig(appConfig)<br>  ],<br>  parameters: {<br>    options: {<br>      storySort: {<br>        order: [<br>          &#39;Application&#39;,<br>          [<br>            &#39;Introduction&#39;,<br><br>            &#39;Group&#39;,<br>            [<br>              &#39;Introduction&#39;,<br><br>              &#39;Story1&#39;,<br>              [<br>                &#39;Introduction&#39;,<br>                &#39;Component&#39;,<br>              ],<br><br>              &#39;Story2&#39;,<br>              [<br>                &#39;Introduction&#39;,<br>                &#39;Component&#39;,<br>              ],<br>              &#39;*&#39;<br>            ]<br>          ],<br>        ],<br>      },<br>    },<br>  },<br>};<br><br>export default preview;</pre><p><strong>## Step 3 : </strong>Manual: Now inside src folder create <strong><em>stories </em></strong>folder</p><p>In my example i have these stories</p><pre>// stories/Application/Introduction.mdx<br>import { Meta } from &#39;@storybook/blocks&#39;;<br><br>&lt;Meta title=&quot;Application/Introduction&quot; /&gt;<br><br># Sample Component Library<br><br>A sample Angular 18 component library documented with Storybook.<br><br>## Structure<br><br>- [**Components**](?path=/docs/application-group-introduction--docs) — Reusable UI building blocks<br>  - [**Button**](?path=/docs/application-group-story1-introduction--docs) — Configurable button with variants<br>  - [**Card**](?path=/docs/application-group-story2-introduction--docs) — Content container with header and actions<br><br>## Tech Stack<br><br>- Angular 18 (standalone components)<br>- Storybook 8<br>- PrimeNG</pre><pre>// stories/Application/Group/Introduction.mdx<br>import { Meta } from &#39;@storybook/blocks&#39;;<br><br>&lt;Meta title=&quot;Application/Group/Introduction&quot; /&gt;<br><br># Components<br><br>Reusable UI components included in this sample library.<br><br>| Component | Description |<br>| --------- | ----------- |<br>| [Button](?path=/docs/application-group-story1-introduction--docs) | A styled button with primary, secondary, and danger variants |<br>| [Card](?path=/docs/application-group-story2-introduction--docs) | A content container with optional header, body, and footer sections |<br><br>Each component is standalone and can be imported directly into any Angular 18 application.</pre><pre>// stories/Application/Group/story1/Introduction.mdx<br>import { Meta } from &#39;@storybook/blocks&#39;;<br><br>&lt;Meta title=&quot;Application/Group/Story1/Introduction&quot; /&gt;<br><br># Button<br><br>A configurable button component with multiple style variants and sizes.<br><br>---<br><br>## Variants<br><br>| Variant | Description |<br>| ------- | ----------- |<br>| `primary` | Main call-to-action style |<br>| `secondary` | Subtle, outlined style |<br>| `danger` | Destructive action style |<br><br>## Usage<br><br>```html<br>&lt;app-button variant=&quot;primary&quot; size=&quot;md&quot; (clicked)=&quot;onSave()&quot;&gt;<br>  Save<br>&lt;/app-button&gt;<br>```<br><br>## Inputs<br><br>| Input | Type | Default | Description |<br>| ----- | ---- | ------- | ----------- |<br>| `variant` | `string` | `&#39;primary&#39;` | Button style variant |<br>| `size` | `string` | `&#39;md&#39;` | Size — `sm`, `md`, or `lg` |<br>| `disabled` | `boolean` | `false` | Disables the button |<br><br>## Events<br><br>| Event | Description |<br>| ----- | ----------- |<br>| `clicked` | Emitted on button click |</pre><pre>// stories/Application/Group/story1/story1.stories.ts<br>import type { Meta, StoryObj } from &#39;@storybook/angular&#39;;<br>import { moduleMetadata } from &#39;@storybook/angular&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br>import { Component as NgComponent, Input, Output, EventEmitter } from &#39;@angular/core&#39;;<br><br>@NgComponent({<br>  selector: &#39;app-button&#39;,<br>  standalone: true,<br>  imports: [CommonModule],<br>  template: `<br>    &lt;button<br>      [disabled]=&quot;disabled&quot;<br>      (click)=&quot;clicked.emit($event)&quot;<br>      [ngStyle]=&quot;getStyles()&quot;&gt;<br>      {{ label }}<br>    &lt;/button&gt;<br>  `,<br>})<br>class ButtonComponent {<br>  @Input() variant: &#39;primary&#39; | &#39;secondary&#39; | &#39;danger&#39; = &#39;primary&#39;;<br>  @Input() size: &#39;sm&#39; | &#39;md&#39; | &#39;lg&#39; = &#39;md&#39;;<br>  @Input() disabled = false;<br>  @Input() label = &#39;Click Me&#39;;<br>  @Output() clicked = new EventEmitter&lt;Event&gt;();<br><br>  getStyles() {<br>    const colors: Record&lt;string, { bg: string; color: string; border: string }&gt; = {<br>      primary: { bg: &#39;#3b82f6&#39;, color: &#39;#fff&#39;, border: &#39;none&#39; },<br>      secondary: { bg: &#39;transparent&#39;, color: &#39;#3b82f6&#39;, border: &#39;1px solid #3b82f6&#39; },<br>      danger: { bg: &#39;#ef4444&#39;, color: &#39;#fff&#39;, border: &#39;none&#39; },<br>    };<br>    const sizes: Record&lt;string, { padding: string; fontSize: string }&gt; = {<br>      sm: { padding: &#39;4px 12px&#39;, fontSize: &#39;12px&#39; },<br>      md: { padding: &#39;8px 20px&#39;, fontSize: &#39;14px&#39; },<br>      lg: { padding: &#39;12px 28px&#39;, fontSize: &#39;16px&#39; },<br>    };<br>    const c = colors[this.variant];<br>    const s = sizes[this.size];<br>    return {<br>      background: c.bg,<br>      color: c.color,<br>      border: c.border,<br>      padding: s.padding,<br>      &#39;font-size&#39;: s.fontSize,<br>      &#39;border-radius&#39;: &#39;6px&#39;,<br>      cursor: this.disabled ? &#39;not-allowed&#39; : &#39;pointer&#39;,<br>      &#39;font-weight&#39;: &#39;500&#39;,<br>      opacity: this.disabled ? &#39;0.5&#39; : &#39;1&#39;,<br>    };<br>  }<br>}<br><br>const meta: Meta = {<br>  title: &#39;Application/Group/Story1/Component&#39;,<br>  decorators: [<br>    moduleMetadata({<br>      imports: [CommonModule, ButtonComponent],<br>    }),<br>  ],<br>  parameters: {<br>    layout: &#39;centered&#39;,<br>  },<br>  argTypes: {<br>    variant: {<br>      control: &#39;select&#39;,<br>      options: [&#39;primary&#39;, &#39;secondary&#39;, &#39;danger&#39;],<br>    },<br>    size: {<br>      control: &#39;select&#39;,<br>      options: [&#39;sm&#39;, &#39;md&#39;, &#39;lg&#39;],<br>    },<br>    disabled: { control: &#39;boolean&#39; },<br>    label: { control: &#39;text&#39; },<br>    clicked: { action: &#39;clicked&#39; },<br>  },<br>  args: {<br>    variant: &#39;primary&#39;,<br>    size: &#39;md&#39;,<br>    disabled: false,<br>    label: &#39;Click Me&#39;,<br>  },<br>};<br><br>export default meta;<br><br>type Story = StoryObj;<br><br>export const Primary: Story = {<br>  name: &#39;Primary&#39;,<br>  render: (args) =&gt; ({<br>    props: { ...args },<br>    template: `&lt;app-button [variant]=&quot;variant&quot; [size]=&quot;size&quot; [disabled]=&quot;disabled&quot; [label]=&quot;label&quot; (clicked)=&quot;clicked($event)&quot;&gt;&lt;/app-button&gt;`,<br>  }),<br>};<br><br>export const Secondary: Story = {<br>  name: &#39;Secondary&#39;,<br>  args: { variant: &#39;secondary&#39; },<br>  render: (args) =&gt; ({<br>    props: { ...args },<br>    template: `&lt;app-button [variant]=&quot;variant&quot; [size]=&quot;size&quot; [disabled]=&quot;disabled&quot; [label]=&quot;label&quot; (clicked)=&quot;clicked($event)&quot;&gt;&lt;/app-button&gt;`,<br>  }),<br>};<br><br>export const Danger: Story = {<br>  name: &#39;Danger&#39;,<br>  args: { variant: &#39;danger&#39; },<br>  render: (args) =&gt; ({<br>    props: { ...args },<br>    template: `&lt;app-button [variant]=&quot;variant&quot; [size]=&quot;size&quot; [disabled]=&quot;disabled&quot; [label]=&quot;label&quot; (clicked)=&quot;clicked($event)&quot;&gt;&lt;/app-button&gt;`,<br>  }),<br>};<br><br>export const Disabled: Story = {<br>  name: &#39;Disabled&#39;,<br>  args: { disabled: true },<br>  render: (args) =&gt; ({<br>    props: { ...args },<br>    template: `&lt;app-button [variant]=&quot;variant&quot; [size]=&quot;size&quot; [disabled]=&quot;disabled&quot; [label]=&quot;label&quot; (clicked)=&quot;clicked($event)&quot;&gt;&lt;/app-button&gt;`,<br>  }),<br>};</pre><p>I have just added code for story1 , in similar way we can add code in story 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8LIwEAOO60Ru7eoi1DKQ1w.png" /></figure><p>That&#39;s it, we can add as many as stories we want and same order we need to maintain in folder inside <strong><em>stories</em></strong> folder and in <strong><em>preview.ts</em></strong></p><p>For running and build both command are available in package.json.</p><p>Thanks!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a4965bcf8ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript : How to build a simple JS npm package]]></title>
            <link>https://medium.com/@mkushwah222/javascript-how-to-build-a-simple-js-npm-package-df9d9f52ee1c?source=rss-ea5f8bdddc5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/df9d9f52ee1c</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mohit Kushwah]]></dc:creator>
            <pubDate>Sat, 25 Apr 2026 09:14:46 GMT</pubDate>
            <atom:updated>2026-04-25T09:14:46.150Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello there</p><p>Today we will build JS package which can be used in any UI application.</p><p>First create a folder with package.json</p><pre>//package.json<br>{<br>  &quot;name&quot;: &quot;d3-layout-renderer&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;main&quot;: &quot;dist/d3-layout-renderer.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;dev&quot;: &quot;webpack serve --mode development&quot;,<br>    &quot;build&quot;: &quot;webpack --mode production&quot;,<br>    &quot;package&quot;: &quot;npm run build &amp;&amp; cp package.json dist/package.json &amp;&amp; cd dist &amp;&amp; npm publish&quot;,<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;webpack&quot;: &quot;^5.89.0&quot;,<br>    &quot;webpack-cli&quot;: &quot;^5.1.4&quot;,<br>    &quot;webpack-dev-server&quot;: &quot;^4.15.1&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;d3&quot;: &quot;^7.8.5&quot;<br>  }<br>}</pre><p>Run npm install to install dependencies.<br>I’m using d3.js for example inside my library</p><p>Now lets write the source code in index.js inside src folder</p><pre>// src/index.js<br>import * as d3 from &#39;d3&#39;;<br><br>export class LayoutRenderer {<br>  constructor(container, config = {}) {<br>    this.container = d3.select(container);<br>    this.config = {<br>      width: config.width || 800,<br>      height: config.height || 600,<br>      shapeSize: config.shapeSize || 50,<br>      ...config<br>    };<br>    this.eventHandlers = {};<br>    this.svg = null;<br>  }<br><br>  on(event, handler) {<br>    this.eventHandlers[event] = handler;<br>    return this;<br>  }<br><br>  emit(event, data) {<br>    if (this.eventHandlers[event]) {<br>      this.eventHandlers[event](data);<br>    }<br>  }<br><br>  render(data) {<br>    this.container.selectAll(&#39;*&#39;).remove();<br>    <br>    this.svg = this.container<br>      .append(&#39;svg&#39;)<br>      .attr(&#39;width&#39;, this.config.width)<br>      .attr(&#39;height&#39;, this.config.height);<br><br>    const defs = this.svg.append(&#39;defs&#39;);<br>    defs.append(&#39;marker&#39;)<br>      .attr(&#39;id&#39;, &#39;arrowhead&#39;)<br>      .attr(&#39;markerWidth&#39;, 10)<br>      .attr(&#39;markerHeight&#39;, 10)<br>      .attr(&#39;refX&#39;, 8)<br>      .attr(&#39;refY&#39;, 3)<br>      .attr(&#39;orient&#39;, &#39;auto&#39;)<br>      .append(&#39;polygon&#39;)<br>      .attr(&#39;points&#39;, &#39;0 0, 10 3, 0 6&#39;)<br>      .attr(&#39;fill&#39;, &#39;#999&#39;);<br><br>    if (data.connections) {<br>      this.renderConnections(data.connections, data.shapes);<br>    }<br><br>    if (data.shapes) {<br>      this.renderShapes(data.shapes);<br>    }<br>  }<br><br>  renderConnections(connections, shapes) {<br>    const shapeMap = new Map(shapes.map(s =&gt; [s.id, s]));<br><br>    this.svg.append(&#39;g&#39;)<br>      .selectAll(&#39;line&#39;)<br>      .data(connections)<br>      .enter()<br>      .append(&#39;line&#39;)<br>      .attr(&#39;x1&#39;, d =&gt; shapeMap.get(d.from).x)<br>      .attr(&#39;y1&#39;, d =&gt; shapeMap.get(d.from).y)<br>      .attr(&#39;x2&#39;, d =&gt; shapeMap.get(d.to).x)<br>      .attr(&#39;y2&#39;, d =&gt; shapeMap.get(d.to).y)<br>      .attr(&#39;stroke&#39;, d =&gt; d.color || &#39;#999&#39;)<br>      .attr(&#39;stroke-width&#39;, 2)<br>      .attr(&#39;marker-end&#39;, &#39;url(#arrowhead)&#39;);<br>  }<br><br>  renderShapes(shapes) {<br>    const group = this.svg.append(&#39;g&#39;)<br>      .selectAll(&#39;g&#39;)<br>      .data(shapes)<br>      .enter()<br>      .append(&#39;g&#39;)<br>      .attr(&#39;transform&#39;, d =&gt; `translate(${d.x},${d.y})`)<br>      .on(&#39;click&#39;, (event, d) =&gt; this.emit(&#39;click&#39;, d))<br>      .on(&#39;mouseover&#39;, (event, d) =&gt; this.emit(&#39;hover&#39;, d))<br>      .style(&#39;cursor&#39;, &#39;pointer&#39;);<br><br>    group.each(function(d) {<br>      const el = d3.select(this);<br>      if (d.type === &#39;circle&#39;) {<br>        el.append(&#39;circle&#39;)<br>          .attr(&#39;r&#39;, d.size || 25)<br>          .attr(&#39;fill&#39;, d.color || &#39;#69b3a2&#39;);<br>      } else {<br>        el.append(&#39;rect&#39;)<br>          .attr(&#39;width&#39;, d.size || 50)<br>          .attr(&#39;height&#39;, d.size || 50)<br>          .attr(&#39;x&#39;, -(d.size || 50) / 2)<br>          .attr(&#39;y&#39;, -(d.size || 50) / 2)<br>          .attr(&#39;fill&#39;, d.color || &#39;#69b3a2&#39;);<br>      }<br>      <br>      if (d.label) {<br>        el.append(&#39;text&#39;)<br>          .attr(&#39;text-anchor&#39;, &#39;middle&#39;)<br>          .attr(&#39;dy&#39;, &#39;0.3em&#39;)<br>          .attr(&#39;fill&#39;, &#39;#fff&#39;)<br>          .text(d.label);<br>      }<br>    });<br>  }<br>}</pre><p>Now lets write the build config in webpack.config.js</p><pre>// webpack.config.js<br>const path = require(&#39;path&#39;);<br><br>module.exports = {<br>  entry: &#39;./src/index.js&#39;,<br>  output: {<br>    path: path.resolve(__dirname, &#39;dist&#39;),<br>    filename: &#39;d3-layout-renderer.js&#39;,<br>    library: &#39;D3LayoutRenderer&#39;,<br>    libraryTarget: &#39;umd&#39;,<br>    globalObject: &#39;this&#39;<br>  },<br>  devServer: {<br>    static: [&#39;./&#39;, &#39;./demo&#39;],<br>    port: 8080,<br>    hot: true<br>  },<br>  externals: {<br>    d3: &#39;d3&#39;<br>  }<br>};</pre><p>Now to test this locally, i have added demo folder in webpack config, with index.html</p><pre>// demo/index.html<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;title&gt;D3 Layout Renderer Demo&lt;/title&gt;<br>  &lt;style&gt;<br>    body { font-family: Arial, sans-serif; margin: 20px; }<br>    #container { border: 1px solid #ccc; }<br>    #events { margin-top: 20px; padding: 10px; background: #f5f5f5; }<br>  &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;h1&gt;D3 Layout Renderer Demo&lt;/h1&gt;<br>  &lt;div id=&quot;container&quot;&gt;&lt;/div&gt;<br>  &lt;div id=&quot;events&quot;&gt;<br>    &lt;h3&gt;Events:&lt;/h3&gt;<br>    &lt;div id=&quot;event-log&quot;&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br><br>  &lt;script src=&quot;https://d3js.org/d3.v7.min.js&quot;&gt;&lt;/script&gt;<br>  &lt;script src=&quot;../dist/d3-layout-renderer.js&quot;&gt;&lt;/script&gt;<br>  &lt;script&gt;<br>    const config = { width: 800, height: 600 };<br>    const data = {<br>      shapes: [<br>        { id: 1, x: 100, y: 100, type: &#39;circle&#39;, label: &#39;A&#39;, color: &#39;#69b3a2&#39; },<br>        { id: 2, x: 300, y: 100, type: &#39;rect&#39;, label: &#39;B&#39;, color: &#39;#404080&#39; },<br>        { id: 3, x: 200, y: 300, type: &#39;circle&#39;, label: &#39;C&#39;, color: &#39;#e74c3c&#39; }<br>      ],<br>      connections: [<br>        { from: 1, to: 2 },<br>        { from: 2, to: 3 },<br>        { from: 1, to: 3, color: &#39;#3498db&#39; }<br>      ]<br>    };<br><br>    const renderer = new D3LayoutRenderer.LayoutRenderer(&#39;#container&#39;, config);<br>    <br>    renderer<br>      .on(&#39;click&#39;, d =&gt; {<br>        document.getElementById(&#39;event-log&#39;).innerHTML = `Clicked: ${d.label} (id: ${d.id})`;<br>      })<br>      .on(&#39;hover&#39;, d =&gt; {<br>        document.getElementById(&#39;event-log&#39;).innerHTML = `Hovered: ${d.label} (id: ${d.id})`;<br>      });<br><br>    renderer.render(data);<br>  &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>That’s it, just run</p><blockquote>npm run dev</blockquote><p>And open <a href="http://localhost:8080/">http://localhost:8080</a> and you will see working code.</p><p>If you wish to publish this as npm package , set <em>publishConfig </em>in package.json and run this command</p><blockquote>npm run package</blockquote><p>My folder structure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*bLMUdyh-_7oXMv4ANDwbPQ.png" /></figure><p>Thanks!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df9d9f52ee1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular: Assets management, Static file server for serving static files to UI applications]]></title>
            <link>https://medium.com/@mkushwah222/angular-assets-management-static-file-server-for-serving-static-files-to-ui-applications-934b54044d82?source=rss-ea5f8bdddc5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/934b54044d82</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[file-server]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Mohit Kushwah]]></dc:creator>
            <pubDate>Sat, 16 Aug 2025 10:41:25 GMT</pubDate>
            <atom:updated>2025-08-16T10:41:25.172Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello there,</p><p>In most UI applications, we use static files such as images, JSON, PDFs, etc. These files can vary in size — some are small, while others are large. As the application grows, the number and size of these static files also increase, which leads to a larger bundle size in the build.</p><p>To address this issue, we can create a simple server using Node.js and Express.js to serve static files. Let’s see how we can do that.</p><p>This is my <strong><em>package.json</em></strong></p><pre>{<br>  &quot;name&quot;: &quot;nodejs-app&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;dummy backend&quot;,<br>  &quot;main&quot;: &quot;app.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,<br>    &quot;start&quot;: &quot;nodemon app.js&quot;<br>  },<br>  &quot;author&quot;: &quot;mohit kushwah&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;binary-extensions&quot;: &quot;^3.1.0&quot;,<br>    &quot;body-parser&quot;: &quot;^1.20.2&quot;,<br>    &quot;dotenv&quot;: &quot;^16.3.1&quot;,<br>    &quot;express&quot;: &quot;^4.18.2&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;nodemon&quot;: &quot;^2.0.22&quot;<br>  }<br>}</pre><p>This is my <strong><em>app.js</em></strong></p><pre>var express = require(&#39;express&#39;);<br>const path = require(&#39;path&#39;);<br>var app = express();<br>var bodyParser = require(&#39;body-parser&#39;);<br>require(&#39;dotenv&#39;).config();<br>var port = 3001;<br><br>app.use(bodyParser.urlencoded({ extended: false }));<br>app.use(bodyParser.json());<br><br>// start static file server for all the files in static folder<br>app.use(&#39;/fileserver&#39;, express.static(path.join(__dirname, &#39;static&#39;)));<br>// basepath and foldername can be changed<br><br><br>require(&#39;./routes&#39;)(app);<br>app.listen(port, function () {<br>  console.log(&#39;nodejs-app is running on &#39; + port);<br>});</pre><p>Here all the files available in static folder will be available using this <br>URL = ‘<a href="http://localhost:3001/fileserver/$file_name_with_subfolder&#39;">http://localhost:3001/fileserver/$file_name_with_subfolder&#39;</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*dzqTjbGlqVCwEsERlcIe8g.png" /></figure><p>For eg — <a href="http://localhost:3001/fileserver/$file_name_with_subfolder&#39;"><em>http://localhost:3001/fileserver/</em></a><em>images/test.jpg</em></p><p>Additionally I have added routes to handle any API, just in case if want to implement.</p><p>This is my <strong><em>routes.js</em></strong></p><pre>const controller = require(&#39;./controllers/controller&#39;);<br><br><br>module.exports = function (app) {<br>  // controller apis<br>  app.post(&#39;/api&#39;, controller.handleAPi);<br>};</pre><p>This is my <strong><em>controllers/controller.js</em></strong></p><pre>module.exports = {<br>  handleAPi: async (req, res) =&gt; {<br>    try {<br>      res.status(200).json({<br>        &quot;data&quot;: []<br>      });<br>    } catch (error) {<br>      res.status(500).json({<br>        message: &quot;Something went wrong!&quot;<br>      });<br>    }<br>  }<br>}</pre><p>Using <strong>npm start</strong> we can the run the app.</p><p>Thanks!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=934b54044d82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GIT CI/CD with Sonar Scanner and real time issues count and control pipeline based on number of…]]></title>
            <link>https://medium.com/@mkushwah222/git-ci-cd-with-sonar-scanner-and-real-time-issues-count-and-control-pipeline-based-on-number-of-f5c41a6b2486?source=rss-ea5f8bdddc5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5c41a6b2486</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Mohit Kushwah]]></dc:creator>
            <pubDate>Fri, 15 Aug 2025 08:06:55 GMT</pubDate>
            <atom:updated>2025-08-15T08:08:20.868Z</atom:updated>
            <content:encoded><![CDATA[<h3>GIT CI/CD with Sonar Scanner and real time issues count and control pipeline based on number of issues</h3><p>Hello there,</p><p>To write sonar free code while development we should have sonar integrated in the IDE itself, but as a reviewer or approver how to verify whether MR/PR is sonar free or not?</p><p>So I was thinking , if its possible to run sonar scan and read the issues in the GIT pipeline itself and break it if exceeds the threshold, so let’s see how i have achieved it.</p><p>Here is my <em>.gitlab-ci.yml </em>for Angular application.</p><pre>stages:<br>    - build<br><br>before_script:<br>  - echo `pwd`<br>  - echo $HOME<br><br><br>code_LINT_TEST_BUILD_SONAR_verification:<br>    stage: build<br>    script:<br>        - echo &quot;This will run in merge request to test the compilation!!&quot;<br>        - npm install --legacy-peer-deps<br>        - npm run lint<br>        - ./node_modules/.bin/ng test<br>        - npm run build<br>        - npm run sonar-scanner<br>        - chmod +x sonar-analysis.sh<br>        - ./sonar-analysis.sh<br><br>    only:<br>        - merge_requests<br><br>    tags:</pre><p>This will run sonar-scanner after build command, once the sonar-scanner is done, it should read the report from sonar server and print the issues count in real time, but even after analysis is done, sonar server takes about a minute or so to reflect the updated results in sonar server.</p><p>So instead of read it directly, we need to wait till analysis is completed and reflected in the sonar server then using sonar api we can get the results.</p><p>So i have added one script after sonar-scanner which is <strong><em>sonar-analysis.sh </em></strong>make sure to give permission to the file before execute, here is the script</p><pre>#!/bin/bash<br><br>SONAR_HOST=&quot;&quot;<br>SONAR_TOKEN=&quot;&quot;<br>PROJECT_KEY=&quot;&quot;<br><br># Read ceTaskId from report-task.txt<br>ceTaskId=$(grep &quot;ceTaskId&quot; .scannerwork/report-task.txt | cut -d&#39;=&#39; -f2)<br><br># Poll until task is complete<br>while true; do<br>  status=$(curl -s -u $SONAR_TOKEN: &quot;$SONAR_HOST/api/ce/task?id=$ceTaskId&quot; | jq -r &#39;.task.status&#39;)<br>  if [ &quot;$status&quot; == &quot;SUCCESS&quot; ]; then<br>    break<br>  fi<br>  echo &quot;Waiting for SonarQube analysis to complete...&quot;<br>  sleep 5<br>done<br><br>echo &quot;Fetching issues grouped by severity from SonarQube...&quot;<br>response=$(curl -s -u $SONAR_TOKEN: &quot;$SONAR_HOST/api/issues/search?componentKeys=$PROJECT_KEY&amp;resolved=false&amp;facets=severities&quot;)<br>echo &quot;$response&quot; | jq -r &#39;<br>  .facets[] | select(.property == &quot;severities&quot;) | .values[] |<br>  &quot;\(.val): \(.count) issues&quot;<br>&#39;<br><br>#Here jq is the command-line JSON processor, which should be there in the machine</pre><p>This script will wait until sonar analysis is done then, in the next step using sonar api it will print the results something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*aL2ps4Ihq7WL9cgMnb9k3A.png" /></figure><p>This will help reviewer/approver to check the count of issues after this code.</p><p>Or if we want to break the pipeline itself in case of it doesn&#39;t matches the threshold, we can update our <strong><em>sonar-analysis.sh</em></strong></p><pre>#!/bin/bash<br><br>SONAR_HOST=&quot;&quot;<br>SONAR_TOKEN=&quot;&quot;<br>PROJECT_KEY=&quot;&quot;<br><br># Read ceTaskId from report-task.txt<br>ceTaskId=$(grep &quot;ceTaskId&quot; .scannerwork/report-task.txt | cut -d&#39;=&#39; -f2)<br><br># Poll until task is complete<br>while true; do<br>  status=$(curl -s -u $SONAR_TOKEN: &quot;$SONAR_HOST/api/ce/task?id=$ceTaskId&quot; | jq -r &#39;.task.status&#39;)<br>  if [ &quot;$status&quot; == &quot;SUCCESS&quot; ]; then<br>    break<br>  fi<br>  echo &quot;Waiting for SonarQube analysis to complete...&quot;<br>  sleep 5<br>done<br><br>echo &quot;Fetching issues grouped by severity from SonarQube...&quot;<br>response=$(curl -s -u $SONAR_TOKEN: &quot;$SONAR_HOST/api/issues/search?componentKeys=$PROJECT_KEY&amp;resolved=false&amp;facets=severities&quot;)<br>echo &quot;$response&quot; | jq -r &#39;<br>  .facets[] | select(.property == &quot;severities&quot;) | .values[] |<br>  &quot;\(.val): \(.count) issues&quot;<br>&#39;<br><br># Get issue count<br>issue_count=$(curl -s -u $SONAR_TOKEN: &quot;$SONAR_HOST/api/issues/search?componentKeys=$PROJECT_KEY&amp;resolved=false&quot; | jq &#39;.total&#39;)<br>echo &quot;Total unresolved issues: $issue_count&quot;<br><br># Fail pipeline if issue count exceeds threshold<br>THRESHOLD=2<br>if [ &quot;$issue_count&quot; -gt &quot;$THRESHOLD&quot; ]; then<br>  echo &quot;❌ Issue count ($issue_count) exceeds threshold ($THRESHOLD). Failing pipeline.&quot;<br>  exit 1<br>else<br>  echo &quot;✅ Issue count ($issue_count) is within acceptable threshold ($THRESHOLD).&quot;<br>fi<br><br>#Here jq is the command-line JSON processor, which should be there in the machine</pre><p>Here I’m using three variables defined in script itself, we can define that in GIT CI/CD variables.</p><p>Thanks!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5c41a6b2486" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular: Intermediate layer between route trigger and component rendering — Route Resolvers]]></title>
            <link>https://medium.com/@mkushwah222/angular-intermediate-layer-between-route-trigger-and-component-rendering-route-resolvers-16fd262a3ba4?source=rss-ea5f8bdddc5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/16fd262a3ba4</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[preloading]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[router]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Mohit Kushwah]]></dc:creator>
            <pubDate>Sun, 10 Aug 2025 07:35:56 GMT</pubDate>
            <atom:updated>2025-08-20T05:22:02.257Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular: Middleware between route trigger and component rendering — <strong>Route Resolvers</strong></h3><p>Hello there,</p><p>Let’s see how can we create a intermediate layer between trigger a route and loading that route, so that we can put any condition or fetch any data as preload to render that component faster.</p><p>First define resolve parameter in router config where our route is defined</p><pre>import { NgModule } from &#39;@angular/core&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br>import { RouteResolverComponent } from &#39;./route-resolver.component&#39;;<br>import { RouterModule, Routes } from &#39;@angular/router&#39;;<br>import { DataResolver } from &#39;./data.resolver&#39;;<br><br>const routes: Routes = [<br>  {<br>    path: &#39;&#39;,<br>    component: RouteResolverComponent,<br>    resolve: {<br>      userData: DataResolver<br>    }<br>  }<br>];<br><br>@NgModule({<br>  declarations: [<br>    RouteResolverComponent<br>  ],<br>  imports: [<br>    CommonModule,<br>    RouterModule.forChild(routes)<br>  ]<br>})<br>export class RouteResolverModule { }</pre><p>Here i have defined <strong>DataResolver</strong></p><p>Now create a file named as <strong><em>data.resolver.ts </em></strong>manually or by cmd and this code</p><pre>import { Injectable } from &#39;@angular/core&#39;;<br>import { ActivatedRouteSnapshot, Resolve, Router } from &#39;@angular/router&#39;;<br>import { Observable, of } from &#39;rxjs&#39;;<br>import { catchError, tap } from &#39;rxjs/operators&#39;;<br>import { HttpClient } from &#39;@angular/common/http&#39;;<br><br><br>@Injectable({<br>  providedIn: &#39;root&#39;<br>})<br>export class DataResolver implements Resolve&lt;any&gt; {<br>  constructor(<br>    private http: HttpClient,<br>    private router: Router<br>  ) { }<br>  resolve(route: ActivatedRouteSnapshot): Observable&lt;any&gt; {<br>    return this.http.get(&#39;https://dummy-api&#39;).pipe(<br>      tap((data: any) =&gt; {<br>        console.log(&#39;DataResolver data&#39;, data);<br>        if (data[&#39;id&#39;] === 2) {<br>          this.router.navigate([&#39;dashboard&#39;]);<br>          return;<br>        }<br>      }),<br>      catchError(error =&gt; {<br>        return of(&#39;No data&#39;);<br>      })<br>    );<br>  }<br>}</pre><p>Here we can write any condition, call API, navigate to any other route if condition doesn’t match.</p><p>Now in the component of the route we can get the data directly from the route.</p><pre>import { Component } from &#39;@angular/core&#39;;<br>import { ActivatedRoute } from &#39;@angular/router&#39;;<br><br>@Component({<br>  selector: &#39;app-route-resolver&#39;,<br>  templateUrl: &#39;./route-resolver.component.html&#39;,<br>  styleUrl: &#39;./route-resolver.component.scss&#39;<br>})<br>export class RouteResolverComponent {<br>  constructor(<br>    private activatedRoute: ActivatedRoute<br>  ) {<br>    console.log(&#39;RouteResolverComponent&#39;);<br>    this.activatedRoute.data.subscribe(data =&gt; {<br>      console.log(&#39;RouteResolverComponent data&#39;, data);<br>    });<br>  }<br>}</pre><p>Thanks!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16fd262a3ba4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular : How to add package.json version in browser DOM]]></title>
            <link>https://medium.com/@mkushwah222/angular-how-to-add-package-json-version-in-browser-dom-cb79856c2390?source=rss-ea5f8bdddc5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb79856c2390</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[version]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Mohit Kushwah]]></dc:creator>
            <pubDate>Fri, 08 Aug 2025 15:02:18 GMT</pubDate>
            <atom:updated>2025-08-08T15:02:18.772Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular : How to add package.json version in browser DOM</h3><p>Hello there,</p><p>Today we are going to see how can we add the <strong><em>package.json</em></strong> version in component template to visible in DOM to verify if correct version is published/deployed.</p><h3>In Angular Application</h3><p>It’s pretty straight forward</p><p>Define the version in <strong><em>package.json</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*XhMAGPI-u3sO4WZIQROSJg.png" /></figure><p>In <strong><em>app.component.ts</em></strong> file</p><pre>import { Component, OnInit } from &#39;@angular/core&#39;;<br>import packageConfig from &#39;../../package.json&#39;;<br><br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrl: &#39;./app.component.scss&#39;<br>})<br>export class AppComponent implements OnInit {<br>  version: string = packageConfig.version;<br><br>  constructor(  ) {  }<br><br>  ngOnInit(): void {}<br>}</pre><p>In <strong><em>app.component.html</em></strong> file</p><pre>&lt;div class=&quot;version&quot;&gt;{{version}}&lt;/div&gt;</pre><p>Using css we can show/hide this version.</p><p>Add these in <strong><em>tsconfig.json</em></strong> file under <strong><em>compilerOptions</em></strong></p><pre>    &quot;resolveJsonModule&quot;: true,<br>    &quot;esModuleInterop&quot;: true,</pre><p>This is done.</p><h3>In Angular library add version from library package.json</h3><p>This is not straight forward to use <strong><em>package.json</em></strong> of library inside library code, so this is how I have done it.</p><p>In <strong><em>projects/my-lib/package.json </em></strong>add version</p><pre>{<br>  &quot;name&quot;: &quot;my-lib&quot;,<br>  &quot;version&quot;: &quot;1.0.3&quot;<br>}</pre><p>Create a file <strong><em>projects/my-lib/src/lib/lib.version.ts </em></strong>and add this</p><pre>export let LIB_VERSION = &#39;1.0.0&#39;;</pre><p>Now, what we will do is, will use this <strong>LIB_VERSION </strong>in library code to render the version</p><p>In <strong><em>my-lib.component.ts</em></strong></p><pre>import { LIB_VERSION } from &#39;./lib.version&#39;;<br><br>version = LIB_VERSION;</pre><p>In <strong><em>my-lib.component.html</em></strong></p><pre>&lt;div class=&quot;version&quot;&gt;{{version}}&lt;/div&gt;</pre><p>Now will write a script to update this <strong>lib.version.ts</strong> file from <strong>package.json </strong>that we will run before building the library to interpret correct version.</p><p>Create the file <strong><em>update-version.js</em></strong> at root and add this</p><pre>const fs = require(&#39;fs&#39;);<br>const path = require(&#39;path&#39;);<br><br>const pkg = require(&#39;./projects/my-lib/package.json&#39;);<br><br>// Path to the TypeScript file<br>const filePath = path.join(__dirname, &#39;./projects/my-lib/src/lib/lib.version.ts&#39;);<br><br>// Read the file<br>fs.readFile(filePath, &#39;utf8&#39;, (err, data) =&gt; {<br>  if (err) {<br>    console.error(&#39;Error reading file:&#39;, err);<br>    return;<br>  }<br><br>  // Replace the old version with the new version<br>  const updatedData = `export let LIB_VERSION = &#39;${pkg.version}&#39;;`;<br><br>  // Write the updated content back to the file<br>  fs.writeFile(filePath, updatedData, &#39;utf8&#39;, (err) =&gt; {<br>    if (err) {<br>      console.error(&#39;Error writing file:&#39;, err);<br>      return;<br>    }<br><br>    console.log(`✅ Updated version to ${pkg.version}`);<br>  });<br>});</pre><p>Now update the build command of library</p><pre>node update-version.js &amp;&amp; ng build my-lib</pre><p>Thanks!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb79856c2390" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 17/18: Build without browser folder]]></title>
            <link>https://medium.com/@mkushwah222/angular-17-18-build-without-browser-folder-be4128df2c2a?source=rss-ea5f8bdddc5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/be4128df2c2a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[dist]]></category>
            <category><![CDATA[build]]></category>
            <category><![CDATA[outputpath]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Mohit Kushwah]]></dc:creator>
            <pubDate>Wed, 16 Jul 2025 12:17:41 GMT</pubDate>
            <atom:updated>2025-07-16T12:17:41.766Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello There,</p><p>Today we are going to see dist folder structure in Angular 17/18</p><p>So by default in <em>angular.json </em>outputPath is given as</p><pre>&quot;outputPath&quot;: &quot;dist/my-app-18&quot;</pre><p>On build which will generate something like this <strong><em>dist/path/browser/files</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/0*fgHjPRlYQoH7C_DE.png" /></figure><p>If we want to build inside directly path provided or inplace of browser folder something else, we need to change in <em>angular.json</em></p><pre>&quot;outputPath&quot;: {<br>              &quot;base&quot;: &quot;dist/my-app-18&quot;,<br>              &quot;browser&quot;: &quot;&quot;<br>            },</pre><p>Here I have given browser as “”, which by default it takes as “browser”, now as i have given it as “”, it will create build files directly inside path. If we want some other path we can provide the value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*elHPhLLDuk9HkJeI.png" /></figure><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be4128df2c2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular: Disable console.log, error, warn, and info in production]]></title>
            <link>https://medium.com/@mkushwah222/angular-disable-console-log-error-warn-and-info-in-production-be011bf5e5f6?source=rss-ea5f8bdddc5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/be011bf5e5f6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[console]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[debugging]]></category>
            <dc:creator><![CDATA[Mohit Kushwah]]></dc:creator>
            <pubDate>Wed, 16 Jul 2025 12:04:28 GMT</pubDate>
            <atom:updated>2025-07-16T12:04:28.867Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello there,</p><p>As part of development we all use <strong><em>console.log </em></strong>or similar console statement in most of the code for debugging purpose, which don’t look good in production environment.</p><p>So lets see how can control it.</p><p>In angular there is a <strong>main.ts </strong>file which is the entry point of Angular application, Here we can control it.</p><pre>if (production) {<br>  const methods = [&#39;log&#39;, &#39;debug&#39;, &#39;info&#39;, &#39;warn&#39;, &#39;error&#39;];<br>  methods.forEach(ele =&gt; {<br>    console[ele] = () =&gt; { };<br>  });<br>}</pre><p>Here this production flag can be defined in environment file or external env.js file.</p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be011bf5e5f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>