CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rc-util

Common utility functions and components specifically designed for React development.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

core-utilities.mddocs/

Core Utilities

Essential utility functions for common React development patterns including function chaining, unique ID generation, and developer warnings.

Capabilities

createChainedFunction

Creates a function that calls all provided functions with the same arguments from left to right. Useful for combining multiple event handlers or callbacks.

/**
 * Safe chained function - only creates new function if needed
 * @param {...Function} functions - Functions to chain together
 * @returns {Function|null} Combined function or null if no valid functions
 */
function createChainedFunction(...functions): Function;

Usage Example:

import createChainedFunction from 'rc-util/lib/createChainedFunction';

const handleClick = createChainedFunction(
  () => console.log('Analytics tracked'),
  () => setModalOpen(true),
  onCustomClick
);

// All three functions will be called when handleClick is invoked
<button onClick={handleClick}>Open Modal</button>

guid

Generates a globally unique identifier using timestamp and an incrementing seed value.

/**
 * Generate a global unique id across current application
 * @returns {string} Unique identifier in format: timestamp_seed
 */
function guid(): string;

Usage Example:

import guid from 'rc-util/lib/guid';

const uniqueId = guid(); // "1641234567890_0"
const anotherId = guid(); // "1641234567891_1"

// Useful for generating unique keys or IDs
const items = data.map(item => ({ ...item, id: guid() }));

warn

Development-only console warning wrapper that only outputs in non-production environments.

/**
 * Log warning message in development mode only
 * @param {string} msg - Warning message to display
 */
function warn(msg: string): void;

Usage Example:

import warn from 'rc-util/lib/warn';

// Only warns in development
warn('This component will be deprecated in v2.0');

warning

Advanced warning system with once-only functionality to prevent duplicate warnings. Provides multiple warning functions with different levels and caching.

/**
 * Log warning if condition is false
 * @param {boolean} valid - Condition to check
 * @param {string} message - Warning message
 */
function warning(valid: boolean, message: string): void;

/**
 * Log note if condition is false
 * @param {boolean} valid - Condition to check  
 * @param {string} message - Note message
 */
function note(valid: boolean, message: string): void;

/**
 * Log warning once only for same message
 * @param {boolean} valid - Condition to check
 * @param {string} message - Warning message
 */
function warningOnce(valid: boolean, message: string): void;

/**
 * Log note once only for same message
 * @param {boolean} valid - Condition to check
 * @param {string} message - Note message
 */
function noteOnce(valid: boolean, message: string): void;

/**
 * Reset the warned messages cache
 */
function resetWarned(): void;

/**
 * Internal helper function for once-only warnings
 * @param {Function} method - Warning method to call
 * @param {boolean} valid - Condition to check
 * @param {string} message - Warning message
 */
function call(
  method: (valid: boolean, message: string) => void,
  valid: boolean,
  message: string
): void;

Usage Example:

import warningOnce, { warning, note, noteOnce, resetWarned, call } from 'rc-util/lib/warning';

// Basic warning
warning(props.name, 'Name prop is required');

// Warning that only shows once per message
warningOnce(false, 'This API is deprecated');
warningOnce(false, 'This API is deprecated'); // Won't show again

// Development note
noteOnce(props.experimental, 'Using experimental feature');

deprecated

Logs deprecation warnings for props or features that will be removed in future versions.

/**
 * Log deprecation warning for props
 * @param {string} props - Deprecated prop name
 * @param {string} instead - Replacement to use instead
 * @param {string} component - Component name where deprecation occurs
 */
function deprecated(props: string, instead: string, component: string): void;

Usage Example:

import deprecated from 'rc-util/lib/deprecated';

// In component implementation
if (this.props.oldProp) {
  deprecated('oldProp', 'newProp', 'MyComponent');
}

Install with Tessl CLI

npx tessl i tessl/npm-rc-util

docs

core-utilities.md

development-styling.md

dom-utilities.md

index.md

react-components.md

react-hooks.md

tile.json