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

ngx-core-utility

v1.0.1

Published

A collection of utilities for Angular applications including enums, constants, string, object, and array utilities.

Downloads

8

Readme

ngx-core-utility

ngx-core-utility is a utility library for Angular that provides commonly used enums, constants, and utility methods for arrays, strings, and objects. This package helps you improve the efficiency and readability of your Angular code.

Installation

To install the package, run the following command in your Angular project directory:

npm install ngx-core-utility

Usage

1. Import the Package

In your Angular components, services, or any other file, you can import the utilities like this:

import { HttpStatusCode, HttpMethod } from 'ngx-core-utility';
import { AUTH_LABELS } from 'ngx-core-utility';
import { ArrayUtil, StringUtil, ObjectUtil } from 'ngx-core-utility';

2. Use the Enums, Constants, & Utility Methods

Example 1: Using Enums

You can use the enums like HttpStatusCode and HttpMethod to manage HTTP status codes and methods:

// Example GET request
getPosts(): Observable<any> {
    return this.makeRequest<any>(HttpMethod.GET, 'posts');
}

// Example POST request
createPost(postData: any): Observable<any> {
    return this.makeRequest<any>(HttpMethod.POST, 'posts', postData);
}

// Example PUT request
updatePost(postId: number, postData: any): Observable<any> {
    return this.makeRequest<any>(HttpMethod.PUT, `posts/${postId}`, postData);
}

// Example DELETE request
deletePost(postId: number): Observable<any> {
    return this.makeRequest<any>(HttpMethod.DELETE, `posts/${postId}`);
}

private handleError(error: HttpErrorResponse) {
    let errorMessage = '';
    if (error.status === HttpStatusCode.BAD_REQUEST) {
      errorMessage = 'Bad request. Please check the input data.';
    } else if (error.status === HttpStatusCode.NOT_FOUND) {
      errorMessage = 'The requested resource was not found.';
    } else if (error.status === HttpStatusCode.INTERNAL_SERVER_ERROR) {
      errorMessage = 'Internal server error. Please try again later.';
    } else {
      errorMessage = 'An unknown error occurred.';
    }
    return throwError(errorMessage);
}  

Example 2: Using Constants

Constants like AUTH_LABELS can help you standardize common labels:

// login.component.ts
import { Component } from '@angular/core';
import { AUTH_LABELS } from './auth-labels.constants';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
})
export class LoginComponent {
  labels = AUTH_LABELS;
}

<!-- login.component.html -->
<form>
  <label for="username">{{ labels.USERNAME }}</label>
  <input type="text" id="username" name="username" required />

  <label for="password">{{ labels.PASSWORD }}</label>
  <input type="password" id="password" name="password" required />

  <button type="submit">{{ labels.LOGIN }}</button>
</form>
<p><a href="#">{{ labels.SIGNUP }}</a></p>

Example 3: Using Array Utilities

The groupBy method allows you to group an array by a specific property:

const users = [
    { id: 1, role: 'admin' },
    { id: 2, role: 'user' },
    { id: 3, role: 'admin' },
];

const groupedUsers = ArrayUtil.groupBy(users, 'role');
console.log(groupedUsers);
// Output:
// {
//   admin: [{ id: 1, role: 'admin' }, { id: 3, role: 'admin' }],
//   user: [{ id: 2, role: 'user' }]
// }

Example 4: Using String Utilities

You can validate if a string is valid JSON using isValidJSON:

const jsonStr = '{"name":"John", "age":30}';
console.log(StringUtil.isValidJSON(jsonStr));  // Output: true

You can also convert numbers to words using amountToWords:

console.log(StringUtil.amountToWords(123));  // Output: 'One Hundred Twenty Three'

Example 5: Using Object Utilities

Find keys with null or undefined values in an object:

const user = { name: 'John', email: null, age: undefined, address: 'New York' };
const nullUndefinedKeys = ObjectUtil.findNullUndefinedKeys(user);
console.log(nullUndefinedKeys);  // Output: ['email', 'age']

Convert an object to a query string:

const queryParams = { name: 'John', age: 30, city: 'New York' };
console.log(ObjectUtil.objectToQueryString(queryParams));
// Output: 'name=John&age=30&city=New%20York'

License

This project is licensed under the MIT License - see the LICENSE file for details.