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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rebatlabs/ui-funs

v1.0.4

Published

Use this repo for shared javascript functions well suitable for frontend projects

Downloads

386

Readme

UI Functions Library

This library provides a collection of utility functions designed to assist with various common tasks in JavaScript projects, particularly those related to frontend development. It is structured to be a shared resource for projects using a monorepo setup.

Installation

To install this package, use npm:

npm install @rebatlabs/ui-funs

Usage

Import the functions you need from the library:

import { obscureNIN, snakeCase, camelCase, capitalizeWords, delay, createInitials, convertDateToUnix, unixTimeStampNow, formatCurrency } from '@rebatlabs/ui-funs';

Functions

String Utilities

  • obscureNIN(input: string): string

    • Obscures a National Identification Number (NIN) by masking the middle characters.
  • snakeCase(value: string): string

    • Converts a string to snake_case.
  • camelCase(value: string): string

    • Converts a string to camelCase.
  • capitalizeWords(value: string): string

    • Capitalizes the first letter of each word in a string.
  • headlineOnly(value: string): string

    • Capitalizes the first letter of each significant word in a headline.

General Utilities

  • delay(ms: number): Promise

    • Returns a promise that resolves after a specified delay in milliseconds.
  • createInitials(name: string, length = 2): string

    • Generates initials from a given name.
  • isThisAWord(value?: string): string | undefined

    • Checks if a given string is a word (more than one character).
  • convertDateToUnix(date: Date): number

    • Converts a Date object to a Unix timestamp.
  • unixTimeStampNow(): number

    • Returns the current Unix timestamp.
  • generateRandomAlphaNumeric(length: number): string

    • Generates a random alphanumeric string of a specified length.
  • removeTrailingSlash(url: string | undefined): string

    • Removes the trailing slash from a URL.
  • getRandomInt(max: number): number

    • Returns a random integer between 0 and the specified maximum.
  • formatCurrency(amount: number, currency = 'NGN'): string

    • Formats a number as a currency string.
  • formatCash(value: number): string

    • Formats a number in a compact cash notation.
  • formatNumber(amount: number): string

    • Formats a number with commas as thousands separators.
  • getRandomUnixTimestamp(startYear: number, endYear: number): number

    • Generates a random Unix timestamp between two years.
  • unixTimestampToMaxAge(expirationUnixTimestamp: number): number

    • Calculates the max-age in seconds from a Unix timestamp.
  • parseInterface(data: any): any

    • Parses and returns a deep copy of the given data.
  • expiresAt(duration: number, format: 'm' | 'h' | 's' = 'm'): number

    • Returns a Unix timestamp for a future expiration time.
  • isOdd(num: number): boolean

    • Checks if a number is odd.
  • isEven(num: number): boolean

    • Checks if a number is even.
  • getValueByQuery(obj: T, query: string): any | undefined

    • Retrieves a value from an object using a dot-separated query string.
  • isValidURL(url: string): boolean

    • Validates if a string is a properly formatted URL.
  • recordToArray(record: Record<string, string>): string[]

    • Converts a record to an array of its values.
  • formatDate(date: Date): string

    • Formats a Date object into a readable string.
  • obscureString(input: string): string

    • Obscures a string by replacing each character with a bullet point.
  • calculatePercentage(amount: number, percentage: number): number

    • Calculates a percentage of a given amount.
  • calculateDaysBetweenTimestamps(timestamp1: number, timestamp2: number): number

    • Calculates the number of days between two Unix timestamps.
  • getLastDayOfMonth(year: number, month: number): Date

    • Returns the last day of a given month and year.
  • getMonthName(month: number): string

    • Returns the name of a month given its number.
  • getRandomInteger(max: number): number

    • Returns a random integer between 0 and the specified maximum.
  • getDifferenceInHours(date1: Date, date2: Date): number

    • Calculates the difference in hours between two dates.
  • getDifferenceInMinutes(date1: Date, date2: Date): number

    • Calculates the difference in minutes between two dates.
  • getDifferenceInSeconds(date1: Date, date2: Date): number

    • Calculates the difference in seconds between two dates.
  • roundTo(n: number, place: number): number

    • Rounds a number to a specified number of decimal places.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.

License

This project is licensed under the MIT License.


This README provides a comprehensive overview of the functions available in your library, making it easier for you and your team to understand and utilize the library effectively. Adjust the descriptions and examples as needed to better fit your team's specific use cases.