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

bluebird-helpers

v1.1.6

Published

A collection of reusable React and React Native hooks

Downloads

17

Readme

/* README.md */

bluebird-helpers

bluebird-helpers is a collection of reusable React and React Native hooks designed to simplify utility operations across various domains, including date manipulation, string handling, validation, and UI behaviors. Whether you need to format dates, validate inputs, or manipulate strings, this library provides easy-to-use hooks for developers to streamline their work and avoid reinventing the wheel.

Key Features

Date Utilities: Includes functions for formatting and manipulating dates (e.g., relative day calculations, date suffixes, and multiple date formats).

String Utilities: Offers functions for string manipulation like checking emptiness, trimming, case conversion, and special character detection.

Optimized Performance: Memoized functions ensure minimal recalculations and improved performance, especially in re-render-heavy applications.

Simple Integration: Easy to install and integrate into any React/React Native project.

Installation

npm install bluebird-helpers

or

yarn add bluebird-helpers

Available Hooks

useDateUtils Hook

A custom React hook that provides various utility functions to manipulate and format dates. It allows you to get date suffixes, calculate relative days (like "Today", "Tomorrow", "Yesterday"), and format dates in multiple styles.

Usage:

Functions

getDateInDDMMYYYY

Returns a formatted date in the DD/MM/YYYY format.

Example


/**
 *getDateInDDMonthYYYY
 * @param {number} dateTimeStamp
 * @returns {DateString} Date in dd/mm/yyyy
 */
import { useDateUtils } from "bluebird-helpers";
const { getDateInDDMMYYYY } = useDateUtils();
const formattedDate = getDateInDDMMYYYY(1633017600000);
console.log(formattedDate); // Output: '01/10/2021'

/**
 * getDateInReverseKebabCase
 * @param {number} dateTimeStamp
 * @returns {LocalDate} Date in yyyy-mm--dd
 */
const { getDateInReverseKebabCase } = useDateUtils();
const formattedDate = getDateInReverseKebabCase(1633017600000);
console.log(formattedDate); // Output: '2021-10-05'

/**
 * getDateInSentence
 * @param {number} dateTimeStamp
 * @returns {DateString} Date in 08th November 2024
 */
const { getDateInSentence } = useDateUtils();
const sentenceDate = getDateInSentence(1633017600000);
console.log(sentenceDate); // Output: '1st October 2021'

/**
 * getRelativeDay
 * @param {number} dateTimeStamp
 * @returns {DateString} Day relative to today e.g Today, Tomorrow, Yesterday
 */
const { getRelativeDay } = useDateUtils();
const relativeDay = getRelativeDay(1633017600000);
console.log(relativeDay); // Output: 'Today' (if the date is today) or 1m (if called after 1 minute)

/**
 * Get date suffix e.g. "st" in 21st
 * @param {number} date - date of a month gotten from date.getDate()
 * @returns {'st' | 'nd' | 'rd' | 'th'}
 */
export const formatDate = dateString => {
  const date = new Date(dateString);

  return (
    getRelativeDay(dateString) ||
    dayjs(dateString).format(`dddd, D[${getDateSuffix(date)}] MMMM`)
  );
};

useStringUtils Hook

Description

A custom React hook that provides various utility functions to manipulate strings. It allows you to check if a string is empty, trim whitespace, convert to upper or lowercase, and capitalize the first letter.

Functions

isEmpty

Returns true if the string is empty or only contains whitespace, and false otherwise.

Example

import { useStringUtils } from "bluebird-helpers";
const { isEmpty } = useStringUtils();
const result = isEmpty('   ');
console.log(result); // Output: true```

### `trimString`
Returns the string with leading and trailing whitespace removed.

const { trimString } = useStringUtils();
const trimmed = trimString('  hello  ');
console.log(trimmed); // Output: 'hello'


### `toUpperCase`
Returns the string with leading and trailing whitespace removed.

const { toUpperCase } = useStringUtils();
const upper = toUpperCase('hello');
console.log(upper); // Output: 'HELLO'


### `toLowerCase`
Returns the string with leading and trailing whitespace removed.

const { toLowerCase } = useStringUtils();
const lower = toLowerCase('HELLO');
console.log(lower); // Output: 'hello'


### `capitalizeFirstLetter`
Returns the string with the first letter capitalized.

const { capitalizeFirstLetter } = useStringUtils();
const capitalized = capitalizeFirstLetter('hello');
console.log(capitalized); // Output: 'Hello'


### `hasSpecialCharacter`
Checks if the string contains any special characters (e.g., !@#$%^&*).

const { hasSpecialCharacter } = useStringUtils();
console.log(hasSpecialCharacter('Hello@World')); // true
console.log(hasSpecialCharacter('HelloWorld')); // false

### `maskSensitiveInfo`
Checks

const { maskSensitiveInfo } = useStringUtils();
console.log(maskSensitiveInfo("1234567890")); // ******7890

### `isValidEmail`
Checks if the email is valid.

const { isValidEmail } = useStringUtils();
console.log(isValidEmail("[email protected]")); // true

### Check to sanitize input (remove dangerous characters)
const { sanitizeInput } = useStringUtils();

console.log(sanitizeInput('<script>alert("x")</script>')); // scriptalert("x")script

### `isValidCardNumber`
Checks if the cardNumber is valid.

const { isValidCardNumber } = useStringUtils();
console.log(isValidCardNumber('4111 1111 1111 1111')); // true

### `validvalidatePasswordStrength`
const { validvalidatePasswordStrength } = useStringUtils();

console.log(validvalidatePasswordStrength('MyStr0ngP@ss!')); // true

### `slugify`
Replace spaces and non-word characters with hyphens

const { slugify } = useStringUtils();
console.log(slugify("Hello World! This is a test.")); // Output: "hello-world-this-is-a-test"

### `generateReferenceID`
Generate reference id 

const { generateReferenceID } = useStringUtils();
console.log(generateReferenceID("TXN")); // "TXN-k7j6f-8xk3"

### `calculateAgeFromDOB`
calculate age from Date of birth
const { calculateAgeFromDOB } = useStringUtils();
console.log(calculateAgeFromDOB("1997-04-20")); // e.g., 28

Contributing

Feel free to open issues or PRs for new utility suggestions or improvements.

License

MIT