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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sg-avatar

v0.0.3

Published

sg-avatar-component

Downloads

1

Readme

title

Sg-Avatar Component

This package is used to add the avatar easily in your applications.

Getting Started

Use the below command to add your package in your application

npm i sg-avatar

you can consume it in your application as shown below:

<sg-avatar name="John Smith"></sg-avatar>

Options

| Property | Attribute | Type | Description | | ------------- | ---------------- | --------- | :-----------------------------------------------------------------: | | name | name | string | (Required) The name used to generate initials. | | avatar | face or initial| string | (Optional) Used to Specify the type of avatar (Face or Initial), Default: initial | | background | background | string | (Optional) Used to specify background color of the avatar (Face or Initial), Default: f0e9e9 | | color | color | string | (Optional) Hex color for the font, without the hash (#). Default: 8b5d5d | | fontSize | font-size | number | (Optional) Font size for initial avatar in percentage of size. Between 0.1 and 1. Default: 0.5 | | length | length | number | (Optional) Length of the generated initials. Default: 2 | | rounded | rounded | boolean | (Optional) Boolean specifying if the returned image should be a circle. Default: false | | size | size | number | (Optional) Avatar image size in pixels. Between: 16 and 512. Default: 64 | | datasrc | datasrc | string | (Required) Specifies the path to the image, Use along with avatar = 'face' attribute. | | sex | sex | string | (Optional) Used to specify the sex of the avatar image, Default: female |

Example:

screenshot-1

Usage

Now we will see how to integrate this libiary in your applications.

Angular

Add an import to main.js

import { defineCustomElements} from '../node_modules/sg-avatar/loader';

And somewhere near the bottom we'll call this function.

defineCustomElements();

Configure the angular.json file. You’ll add this configuration under the projects > yourProjectName > architect > build > options > assets section:

"input": "node_modules/sg-avatar/dist/components/assets/",
"output": "/assets/"

This will copy the images from the component into your application assets folder.

Next, in app.module.ts add the CUSTOM_ELEMENTS_SCHEMA.

import {CUSTOM_ELEMENTS_SCHEMA} from `@angular/core`;

and then

schemas: [
    CUSTOM_ELEMENTS_SCHEMA
]

Your app.module.ts should look like this:

import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
  declarations: [],
  imports: [],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }

Please Note: schemas: [ CUSTOM_ELEMENTS_SCHEMA ] need to be added to each component where you are using custom HTML tags.

Now, in app.component.html you utilize your new custom element.

<sg-avatar name="John Smith"></sg-avatar>

React

Now we'll add an import to index.js

import { defineCustomElements} from '../node_modules/sg-avatar/loader';

And somewhere near the bottom we'll call this function.

defineCustomElements();

Install the following package to Copying assets from a component node module

npm install --save-dev copy-webpack-plugin

Now, Update your webpack configuration (webpack.config.js):

const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  // ... other webpack config
  plugins: [
    new CopyWebpackPlugin({
      patterns: [
        { 
          from: node_modules/sg-avatar/dist/components/assets/', 
          to: 'assets' 
        }
      ]
    })
  ]
};

Next, in app.js you utilize your new custom element

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
            <sg-avatar name="John Smith"></sg-avatar>
      </header>
    </div>
  );
}

Vue

Add defineCustomElements to one of our main files. Specifically main.js for Vue.

import { defineCustomElements} from '../node_modules/sg-avatar/loader';

And somewhere near the bottom we'll call this function.

defineCustomElements();

Now, to copy the images from the component node_module into your application use the following command

npm i vite-plugin-static-copy

Add viteStaticCopy plugin to vite.config.js / vite.config.ts and add the component assets location as shown below.

import { viteStaticCopy } from 'vite-plugin-static-copy'

export default {
  plugins: [
    viteStaticCopy({
      targets: [
        {
          src: 'node_modules/sg-avatar/dist/components/assets/*',
          dest: 'assets'
        }
      ]
    })
  ]
}

Next, in App.Vue you consume the custom element.

<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <sg-avatar name="John Smith"></sg-avatar>
  </div>
</template>

<script>
export default {
  name: 'App',
}
</script>

Please Note: If you are using multiple component then you can define the defineCustomElements as shown below:

import { defineCustomElements as defineCustomElements1} from '../node_modules/sg-copyright/loader';
import { defineCustomElements as defineCustomElements2} from '../node_modules/sg-avatar/loader';
.
.
.
defineCustomElements1();
defineCustomElements2();