@catbee/utils
Version:
A modular, production-grade utility toolkit for Node.js and TypeScript, designed for robust, scalable applications (including Express-based services). All utilities are tree-shakable and can be imported independently.
62 lines (59 loc) • 2.44 kB
TypeScript
/*
* The MIT License
*
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* Generates a UUID v4 string (RFC 4122).
*
* @returns {string} UUID v4 (e.g., 'c0de1234-5678-9abc-def0-123456789abc')
*/
declare function uuid(): string;
/**
* Generates a nanoid-style random ID (URL-safe, customizable length).
*
* @param {number} length - Length of the ID (default: 21).
* @returns {string} Nanoid-style random string.
*/
declare function nanoId(length?: number): string;
/**
* Generates a cryptographically strong random hex string.
*
* @param {number} byteLength - Number of random bytes (default: 16 -> 32 hex chars).
* @returns {string} Random hex string.
*/
declare function randomHex(byteLength?: number): string;
/**
* Generates a random integer between min (inclusive) and max (inclusive).
*
* @param {number} min - Minimum value.
* @param {number} max - Maximum value.
* @returns {number} Random integer in range.
*/
declare function randomInt(min: number, max: number): number;
/**
* Generates a cryptographically strong random base64 string.
*
* @param {number} byteLength - Number of random bytes (default: 16).
* @returns {string} Random base64 string (URL-safe, no padding).
*/
declare function randomBase64(byteLength?: number): string;
export { nanoId, randomBase64, randomHex, randomInt, uuid };