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

@aalencarv/common-utils

v1.6.1

Published

a common utils functions to use in javascript and node

Downloads

44

Readme

🛠️ common-utils

A lightweight TypeScript utility library providing helper functions for date manipulation, type checking, array operations, GTIN validation, and more.

npm version License: ISC TypeScript

Table of Contents

📦 Instalation

You can install common-utils via npm (assuming it's published) or by cloning the repository.

Using npm

npm install @aalencarv/common-utils

From Source

Clone the repository and install dependencies:

git clone https://github.com/aalencarvz1/libs-js-ts-node-common-utils.git common-utils
cd common-utils
npm install

Usage

Import the functions you need in your TypeScript or JavaScript project:

import { getMoment, toBool, toNumber } from '@aalencarv/common-utils';

// Example: Get current date and time
console.log(getMoment()); // e.g., "26/05/2025 11:39:00.123"

// Example: Convert value to boolean
console.log(toBool("yes")); // true
console.log(toBool("0")); // false

// Example: Convert string to number
console.log(toNumber("123.45")); // 123.45

Functions

The following table lists all exported functions in the common-utils library, including their parameters, return types, and a brief description of their functionality.

| Name | Parameters | Return Type | Description | |--------------------------|------------------------------------------------|-------------|-----------------------------------------------------------------------------| | getMoment | None | string | Returns the current date and time in the format DD/MM/YYYY HH:mm:ss.SSS. | | toBool | pValue: any | boolean | Converts a value to a boolean based on specific rules (e.g., non-zero numbers, non-empty strings). | | typeOf | value: any | string | Returns the type of a value, handling arrays and NodeList specifically. | | isArray | obj: any | boolean | Checks if a value is an array. | | firstValid | arr_valores: any[], check_null: boolean = true | any | Returns the first non-undefined (and optionally non-null) element in an array. | | hasValue | pValue: T \| null \| undefined | boolean | Checks if a value is defined, non-null, and non-empty (for strings, arrays, objects). | | toNumber | v: any | number | Converts a value to a number, handling strings with commas or dots. | | addFullMonths | date: Date, months: number | void | Adds a specified number of months to a Date object, adjusting to the last day if needed. | | arraySplit | array: any[], tamanho: number | any[][] | Splits an array into chunks of a specified size. | | arrayToObject | array?: any, key?: any | any | Converts an array of objects to a nested object based on specified keys. | | currentMonthDateShort | None | string | Returns the current date in YYYY-MM-DD format. | | calculateGtinDigit | code: string | number | Calculates the check digit for a GTIN code. | | getGtinType | code?: any | any | Validates a GTIN code and returns its type (8, 12, 13, or 14) if valid. | | deleteNotExistsProperty| object: any, properties: any | void | Deletes properties from an object that are not in the provided list. | | dateDiffInDays | a: Date, b: Date | number | Calculates the difference in days between two dates. | | deepCopy | arr: any[], subKey: string, key: string, ignoreIds?: any[], replacements?: any[] | any[] | Creates a deep copy of an array of objects, ignoring specified IDs and applying replacements. | | deepFindByKey | arr: any[], key: string, targetId: any, subKey: string, returnArrayKey?: boolean | any | Recursively finds an object in an array by a key, optionally returning the array and index. | | firstMonthDateShort | None | string | Returns the first day of the current month in YYYY-MM-DD format. | | getAllProperties | obj: any | string[] | Returns all properties and methods of an object, including inherited ones. | | getKey | obj: object \| Function \| null \| undefined, key: string | string \| null | Finds a case-insensitive key in an object or function. | | getMethodName | obj: any, methodName: string | string \| null | Finds a case-insensitive method name in an object or its prototype chain. | | isClass | func: any | boolean | Checks if a function is a class (has a constructor in its prototype). | | singleArrayEquals | arr1?: any[], arr2?: any[] | boolean | Checks if two arrays are equal by comparing elements. | | to01 | value?: any | number | Converts a value to 1 (true) or 0 (false) based on toBool. | | toArray | value?: any, delimiter?: string | any[] \| null \| undefined | Converts a value to an array, splitting strings by a delimiter. | | toDate | pValue: any, pFormat?: any | Date | Converts a value to a Date object, supporting various formats. | | toYesNo | value?: any | string | Converts a value to "yes" or "no" based on toBool. | | valueOrNull | value?: any | any | Returns the value if it has a value, otherwise null. | | valueOrUndef | value?: any | any | Returns the value if it has a value, otherwise undefined. | | getTempNumberId | currentData: any[], tempIdPropName: string | number | Generates a unique random number ID for an array of objects, avoiding duplicates based on the specified property name (defaults to 'tempId'). |

🧰 Tecnologies

👤 Author

Aalencar @aalencarvz1

📄 Licence

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