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

@candourorg/utils

v1.0.64

Published

Candour utilities.

Readme

Candour Utilities Library

A utility library with functions for string manipulation, date formatting, number conversion, and more.


Installation

Install the library using npm or yarn:

bun add @candourorg/utils
yarn add @candourorg/utils
npm install @candourorg/utils

Examples of How to Use Functions from the Candour Utilities Library


1. CapitalizeFirstLetter

Description: Capitalizes the first letter of a string.

Example Usage:

import { CapitalizeFirstLetter } from '@candourorg/utils';

const text = 'hello world';
const capitalized = CapitalizeFirstLetter(text);

console.log(capitalized); // Output: "Hello world"

2. FormatDate

Description: Formats a date string into the format DD-MMM-YYYY.

Example Usage:

import { FormatDate } from '@candour-utils/react';

const date = '2025-01-21';
const formattedDate = FormatDate(date);

console.log(formattedDate); // Output: "21-Jan-2025"

3. FormatDateWithTime

Description: Formats a date string into the format DD-MMM-YYYY, HH:MM AM/PM.

Example Usage:

import { FormatDateWithTime } from '@candour-utils/react';

const date = '2025-01-21T14:30:00';
const formattedDateWithTime = FormatDateWithTime(date);

console.log(formattedDateWithTime); // Output: "21-Jan-2025, 02:30 PM"

Conversion Functions

Conversion utility functions:

  1. CapitalizeFirstLetter Capitalizes the first letter of a given string.

  2. ConvertDateWithTimeStamp Converts a timestamp into a formatted date string.

  3. ConvertNumberToKFormat Converts large numbers to a shortened "K" format (e.g., 12001.2K).

  4. FormatDate Formats a date object or string into a human-readable date.

  5. FormatDateWithTime Formats a date object or string, including the time.

  6. FormatDateRange Formats date range e.g paymentStartDate in payslip.

  7. FormatDocumentType Converts a document type code to a human-readable string.

  8. FormatNumberWithCommas This function convert numbers to string format and add commas to a number for better readability. You can optionally pass currencySymbol as second argument if you want to prefix currency before the number. You an equally pass a third argument withSpace if you want to put space between the currencySymbol and the number. (e.g., 10001,000) | (1000$1,000) | (1000$ 1,000)

  9. HexToRgba Converts a hexadecimal color code to an RGBA format.

  10. MaskEmail Masks an email address, hiding part of it (e.g., [email protected]u***@example.com).

  11. SterilizeNumberInputs Removes invalid characters from number inputs.

  12. UserInitials Extracts the initials from a user's full name.

  13. truncateToTwoDecimals formats a floating point number to two decimal places

  14. truncateText truncate text and a add '...' (e.g,. Interdominational -> interdom...).

  15. BackgroundColor Provides utility for determining or managing background colors.

  16. CheckPathname Checks if a given pathname matches specific patterns or criteria.

  17. Encrypt Encrypts sensitive data for secure storage or transfer.

  18. Decrypt Decrypts previously encrypted data.

  19. ObfuscateValues Obfuscates sensitive values to prevent unauthorized access.

  20. DeobfuscateValues Reverses the obfuscation process to retrieve the original values.

  21. ExtractDocumentType Extracts the document type from a given input.

  22. GenerateRandomKey Generates a random key for various use cases.

  23. HandleEnterKeyDown Handles the Enter key press for specific user input scenarios.

  24. HandleOTPKeyDown Manages key events for one-time password (OTP) inputs.

  25. HandleInputChange Handles changes in input fields, especially for OTP-like input systems.

  26. HandlePaste Handles paste events for input fields, ensuring proper formatting and data.

  27. GetStatusClasses Provides utility for retrieving status-specific CSS classes.

  28. GetStatusText Retrieves the text representation of a specific status.

  29. Status A type definition for status labels.

  30. UserDataProps A type definition for user data properties.

  31. formatSlugName formats slug name and replace whitespace with -

  32. formatChartsNumber Formats chart number

  33. createInitials This function creates business name initial

  34. getTokenExpiration Helper function to decode a JWT and get its expiration time in seconds

  35. formatTokenExpiration Helper function to convert seconds into days, hours, minutes, and seconds

  36. getCurrencySymbol This function helps to get the currency symbol

  37. getTaxFields This function helps to display the correct country tax fields depending on the country pass to it

  38. countriesArray This is an array of countries with currency symbol and country code

  39. countryCurrencies This is an array of contries with their currency code, currency name, currency symbol

  40. countriesCurrenciesArray This function is used to map through the countryCurrencies array and modify to return another arrays of object label, value and country

  41. GetOrdinalWord Converts a number into its ordinal word form (e.g., 1First).

  42. formatEmployeeTaxDetailsLabel Format employee tax details label (e.g., taxIdentificationNumberTax identification number).

  43. getBankCodeField Maps a currency symbol to its corresponding bank code field (e.g., £ → sortCode).

  44. formatEmployeeTaxDetails Converts an array of tax details into a key-value object with camelCase keys.

  45. toCamelCaseTitle Converts a space-separated string into camelCase format.

  46. toCamelCase Checks if a string is already in camelCase; if not, converts it.

  47. isValuePresent
    Checks if a value is not null, undefined, or an empty string.

  48. getCurrencyLabelAndCode
    Returns the currency label and corresponding bank code based on the provided payment currency.