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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ngx-opalbytes-services

v1.2.0

Published

Esta biblioteca destina-se a abrigar serviços (`services`) Angular reutilizáveis que encapsulam lógica de negócios, chamadas de API e outras funcionalidades compartilhadas.

Downloads

274

Readme

📦 ngx-opalbytes-services

Esta biblioteca destina-se a abrigar serviços (services) Angular reutilizáveis que encapsulam lógica de negócios, chamadas de API e outras funcionalidades compartilhadas.


Compatibilidade

|Tecnologia | Versão | Descrição | |------------|----------|-------------------------------------| | Angular | ^21.0.0 | Framework principal da biblioteca |

Instalação

Para instalar a biblioteca, execute o seguinte comando:

npm install ngx-opalbytes-services

Dependências

Esta biblioteca possui as seguintes dependências:

peerDependencies

| Pacote | Versão | | :----- | :----- | | @angular/common | ^21.0.0 | | @angular/core | ^21.0.0 |

dependencies

| Pacote | Versão | | :----- | :----- | | tslib | ^2.3.0 |


Como Usar

Os serviços podem ser injetados nos seus componentes ou outros serviços via injeção de dependência do Angular.

Exemplo de como um serviço seria utilizado:

import { Component, OnInit } from '@angular/core';
import { WebsocketService } from 'ngx-opalbytes-services';

@Component({
  selector: 'app-user-profile',
})
export class UserProfileComponent implements OnInit {
  
  private websocketService = inject(WebsocketService)
  constructor() {}

  ngOnInit() {
    // this.websocketService.connect('ws://localhost:8080');
  }
}

Organização de Pastas

Dentro da pasta src/lib/, os serviços são organizados na pasta services/.

src/
└── lib/
    └── services/
        ├── date-pipe.service.ts
        ├── installer.service.ts
        └── websocket.service.ts


Detalhes dos Serviços

CaoDatePipeService

Um serviço simples que atua como um wrapper para o DatePipe do Angular, facilitando a formatação de datas.

Métodos

| Método | Parâmetros | Retorno | Descrição | | --- | --- | --- | --- | | getConvertedDatePipe | value: Date, transform: string | string | Formata uma data de acordo com a string de formato fornecida. |

Exemplo de Uso

import { CaoDatePipeService } from 'ngx-opalbytes-services';

// ...

constructor(private datePipeService: CaoDatePipeService) {}

formatarData() {
  const dataFormatada = this.datePipeService.getConvertedDatePipe(new Date(), 'dd/MM/yyyy');
  console.log(dataFormatada); // Ex: 22/12/2025
}

CaoInstallationService

Este serviço gerencia o download e a instalação de executáveis ou a abertura de arquivos, comumente usado em cenários de instalação de aplicações desktop a partir de uma aplicação web.

Propriedades

| Propriedade | Tipo | Descrição | | --- | --- | --- | | status$ | Observable<IStatusInstallation> | Emite o status atual da instalação. |

Interfaces

interface IStatusInstallation {
  isInstalled: boolean;
  version?: string;
  lastChecked: Date;
  installationPath?: string;
}

interface IConfigInstallation {
  executableName: string;
  assetPath: string; // URL para o arquivo
}

interface IBlobConfigInstallation {
  executableName: string;
  assetPath: Blob; // Arquivo em formato Blob
}

Métodos

| Método | Parâmetros | Retorno | Descrição | | --- | --- | --- | --- | | downloadAndInstall | config: IConfigInstallation | Observable<boolean> | Inicia o download e a instalação de um executável. | | downloadAndOpenFile | config: IConfigInstallation, isTargetBlank?: boolean | Observable<boolean> | Faz o download e abre um arquivo em uma nova aba. | | downloadBlobFile | configBlob: IBlobConfigInstallation | void | Inicia o download de um arquivo a partir de um objeto Blob. | | reinstall | config: IConfigInstallation | Observable<boolean> | Atalho para o método downloadAndInstall. |


CaoWebSocketService

Gerencia uma conexão WebSocket com um servidor, incluindo lógica de reconexão automática.

Propriedades (Emitters)

| Propriedade | Tipo | Descrição | | --- | --- | --- | | isConnectionEvent | EventEmitter<boolean> | Emite true em sucesso e false em falha de conexão. | | onErrorConnection | EventEmitter<string> | Emite mensagens de erro durante as tentativas de conexão. | | onSuccessConnection| EventEmitter<boolean>| Emite true quando a conexão é estabelecida com sucesso. |

Métodos

| Método | Parâmetros | Retorno | Descrição | | --- | --- | --- | --- | | startConnection | webSocketServer: string | void | Inicia o processo de conexão com o servidor WebSocket. | | connect | webSocketServer: string | void | Lógica principal de conexão, com tentativas de reconexão. | | sendMessage | msg: any | void | Envia uma mensagem para o servidor. | | getMessages | - | Observable<any> | Retorna um Observable que emite as mensagens recebidas do servidor. | | close | - | void | Fecha a conexão com o WebSocket. |

Exemplo de Uso

import { CaoWebSocketService } from 'ngx-opalbytes-services';

// ...
private wsService = inject(CaoWebSocketService)

constructor() {}

ngOnInit() {
  this.wsService.startConnection('wss://meu-servidor.com');

  this.wsService.isConnectionEvent.subscribe(isSuccess => {
    console.log('Status da conexão:', isSuccess);
  });

  this.wsService.getMessages().subscribe(message => {
    console.log('Nova mensagem:', message);
  });
}

enviar() {
  this.wsService.sendMessage({ data: 'Olá, servidor!' });
}

ngOnDestroy() {
  this.wsService.close();
}

📜 Como Contribuir

Para adicionar um novo serviço a esta biblioteca, siga os passos abaixo:

  1. Crie o arquivo do seu serviço dentro da pasta src/lib/services/. Por exemplo: src/lib/services/user.service.ts.

  2. Implemente seu serviço, lembrando de marcá-lo com @Injectable({ providedIn: 'root' }) para que ele seja "tree-shakable".

  3. Exponha o serviço na API pública da biblioteca, adicionando uma linha de exportação no arquivo src/public-api.ts.

    // projects/ngx-opalbytes-services/src/public-api.ts
    export * from './lib/services/user.service'; 
  4. Adicione testes unitários para garantir a qualidade e o funcionamento esperado do seu serviço.

  5. Faça o commit seguindo as regras de commit do projeto, usando o escopo services.

    git commit -m "feat(services): add user service para validacao"