npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nxt-widget-1

v1.0.0

Published

An example Web Component <nxt-widget1> created from an Angular project.

Downloads

2

Readme

NxtWidget1

An example Web Component created from an Angular project. Importing this declares a new custom element <nxt-widget1>

<nxt-widget1 height="400" width="300" user-preferences='{"color": "#444", "background": "#F1F8FF"}'></nxt-widget1>

Parameters:

  • width - width of the widget, px.

  • height - height of the widget, px.

  • user-preferences - other options, is should be a valid json object

    {
      color: string; // text color
      background: string; // widget background
    }

Usage

  • Statically

    <nxt-widget1 height="400" width="300" user-preferences='{"color": "#444", "background": "#F1F8FF"}'></nxt-widget1>
  • Dynamically

    const widgetElement: HttpElement = document.createElement('nxt-widget1') as HttpElement;
    
    widgetElement.width = this.widgetMetadata.width;
    widgetElement.height = this.widgetMetadata.height;
    widgetElement.userPreferences = this.widgetMetadata.userPreferences;
    
    this.wrapperElement.appendChild(widgetElement);
    

Usage inside an Angular application

Resolve external dependencies

For this you'll need to plug-in an importmap with links to hosted dependency files.

  • As a separate project:

    Plug in the external dependencies as a link to an importmap in the <head> of your root project's index.html (the example contains a local hosting case).

    <script type="systemjs-importmap" src="http://localhost:5000/importmap.json"></script>

    Run the Common Dependencies project. Change a link to the hosted importmap if necessary.

  • As a local importmap:

    Add this tag to the <head> of your root project:

    <script type="systemjs-importmap">
      {
        "imports": {
            "rxjs": "https://unpkg.com/@esm-bundle/rxjs/system/rxjs.min.js",
            "rxjs/operators": "https://unpkg.com/@esm-bundle/rxjs/system/rxjs-operators.min.js",
            "zone": "https://cdn.jsdelivr.net/npm/zone.js/dist/zone.min.js",
            "@angular/core": "https://cdn.jsdelivr.net/npm/@angular/[email protected]/bundles/core.umd.js",
            "@angular/common": "https://cdn.jsdelivr.net/npm/@angular/[email protected]/bundles/common.umd.min.js",
            "@angular/compiler": "https://cdn.jsdelivr.net/npm/@angular/[email protected]/bundles/compiler.umd.js",
            "@angular/forms": "https://cdn.jsdelivr.net/npm/@angular/[email protected]/bundles/forms.umd.min.js",
            "@angular/platform-browser": "https://cdn.jsdelivr.net/npm/@angular/[email protected]/bundles/platform-browser.umd.min.js",
            "@angular/platform-browser-dynamic": "https://cdn.jsdelivr.net/npm/@angular/[email protected]/bundles/platform-browser-dynamic.umd.min.js",
            "@angular/animations": "https://cdn.jsdelivr.net/npm/@angular/[email protected]/bundles/animations.umd.min.js",
            "@angular/router": "https://cdn.jsdelivr.net/npm/@angular/[email protected]/bundles/router.umd.min.js",
            "moment": "https://cdn.jsdelivr.net/npm/[email protected]/moment.min.js"
        }
      }
    </script>

Add Web Components support to a hosting application

  1. Set compiler options

    Add the following option to the root tsconfig.json:

    {
      compilerOptions: {
        "allowJs": true
      }
    }
  2. Enable custom elements

    Add to src/app/app.module.ts:

    schemas: [CUSTOM_ELEMENTS_SCHEMA],
    bootstrap: []
  3. Add polyfills for older browsers

    • Install webcomponents

      npm install --save-dev @webcomponents/webcomponentsjs
    • In angular.json add this object to the assets array:

      {
        "glob": "**/*.js",
        "input": "node_modules/@webcomponents/webcomponentsjs",
        "output": "webcomponents/"
      }
    • Add to polyfils.ts

      import '@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js';
      import '@webcomponents/webcomponents-loader.js';

Install your component to the project

  1. Install the widget from npm

    npm i --save nxt-widget-1
  2. Import widget inside app.module.ts

    import 'nxt-widget-1';

Use it as usually.