cuHacking logocuHacking DevDocs

utils

Utility functions and constants.

📦 Overview

What it does

This library provides utility functions and constants for libraries. These functions & constants usually have a global context, and could be used in any applications & libraries.

Note on niche functions & constants

Utility functions & constants specific to an app or library should be specified in the respective app or library's lib directory. This library is only used for globally usable functions.

Key Features

  • Allows for global usage of utility functions & constants
  • Write unit tests just once

How to use

Basic Usage Example

Simply import the functions you need and use them:

import { getBaseUrl } from '@cuhacking/utils'
 
const baseUrl = getBaseUrl()  // Example value: https://localhost:3000/

📖 API Reference

getBaseUrl

  • Description: Gets the base URL of the window.
  • Return Type: string

Error Handling

Errors should be handled within the functions themself. The library does not perform any additional error handling or manipulation on top of the provided functions.


🛠️ Commands

View all commands

To view all commands from the library's project.json, package.json and inheritted:

Terminal
pnpm nx show project utils

Focus library usage

To view/focus on all the apps & libraries which use this library:

Terminal
pnpm nx graph --focus utils

📝 Contributing

Best Practices

Code Formatting

Implement your functions in identifiable files.

The library should be linted without any errors:

Terminal
pnpm nx run utils:lint

Testing

To run tests for this library:

Terminal
pnpm nx run utils:test

❓ FAQs

How can I add a new function/constant?

Write it in an existing library file or create a file of your own. Make sure to export the function/constant, and follow function definition guidelines.

Last updated on

On this page

Edit on GitHubMade with 🩶 for Hackers by Hackers