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

@neofacto/ngx-ethereum

v0.1.0

Published

The goal of this library is to be published as npm packages and we can import it in multiple Apps, also it will enhance code reusability and avoid various bad practices or architectural mistakes that can make it difficult to decouple and reuse code in the

Downloads

4

Readme

NgxEthereum

The goal of this library is to be published as npm packages and we can import it in multiple Apps, also it will enhance code reusability and avoid various bad practices or architectural mistakes that can make it difficult to decouple and reuse code in the future.

Summary

General Information

Libraries extend Angular's base functionality and can be used locally in your workspace, or it can be published as npm packages to share with other projects or other Angular developers.

Technologies Used

Angular CLI version 14.1.1.

Getting Started

These instructions will cover the basics of building an Angular component library and publishing it to the npm store.

Setup

Run ng new ethereum-utils-module --no-create-application and ng generate library ngx-ethereum to generate a new library skeleton in a new workspace.

Note: The ng generate command creates the projects/ngx-ethereum folder in your workspace, which contains a component and a service inside an NgModule.

Run ng generate component component-name --project ngx-ethereum to generate a new component.

Note: Don't forget to add --project ngx-ethereum or else it will be added to the default project in your angular.json file.

Note: The public-api.ts will be used to export all the entities (like modules, components, services or directives) that belong to the particular sub-entry, it makes library code reusable.

Build

Run ng build ngx-ethereum to build the project. The build artifacts will be stored in the dist/ directory.

Publishing

After building your library, go to the dist folder cd dist/ngx-ethereum and run npm publish.

Running unit tests

Run ng test ngx-ethereum to execute the unit tests via Karma.

Usage Examples

This library exposes an account component which allows us to display the account address and copy it.

Here we have a little code demonstration :

We set this code block in account.component.ts :

export class AccountComponent {
  @Input()
  accountAddress: string = '';

  @ViewChild(MatTooltip)
  tooltip!: MatTooltip;

  message = 'Copy the address';

  async onCopyToClipboard() {
    await navigator.clipboard.writeText(this.accountAddress).then(() => {
      this.tooltip.show();
      this.message = 'copied !';
      setTimeout(() => {
        this.message = 'Copy the address';
      }, 3000);
    });
  }
}

And we set this code block in account.component.html :

 <span
    [title]="accountAddress"
    #tooltip
    matTooltipPosition="below"
    [matTooltip]="message"
    (click)="onCopyToClipboard()">
    {{ accountAddress | shortAddress }}
  </span>

Also, this library exposes a short address pipe which allows us to reduce the size of the account address.

@Pipe({
  name: 'shortAddress',
})
export class ShortAddressPipe implements PipeTransform {
  static readonly ADDRESS_MAX_LENGTH = 42;

  transform(value: string | null | undefined): string {
    if (value === null) {
      return '';
    }
    if (value === undefined) {
      return '';
    }
    if (value === '') {
      return '';
    }
    if (value.length !== ShortAddressPipe.ADDRESS_MAX_LENGTH) {
      // not a valid address
      return '';
    }
    return `${value.substring(0, 6)}...${value.slice(-4)}`;
  }
}

Further Help

To get more help on the Angular CLI use ng help, or go check out the Angular CLI Overview and Command Reference and (https://angular.io/guide/creating-libraries) pages.