tanstack-shadcn-table
Version:
A powerful, feature-rich React table component built on top of TanStack Table v8 with shadcn/ui styling. Optimized bundle size with 55% reduction through peer dependencies.
76 lines (75 loc) • 2.51 kB
TypeScript
/**
* Input sanitization functions
* Tree-shakeable - import only what you need
*/
/**
* Sanitizes HTML content to prevent XSS attacks.
* Removes dangerous HTML elements and attributes including:
* - Script tags
* - JavaScript: URLs
* - Event handlers (onclick, onerror, etc.)
* - Unsafe data: URLs
* - Style expressions
*
* @param input - The HTML string to sanitize
* @returns Sanitized HTML string with dangerous content removed
*
* @example
* ```tsx
* import { sanitizeHtml } from 'tanstack-shadcn-table/security/sanitize';
*
* const unsafe = '<script>alert("xss")</script>Hello';
* const safe = sanitizeHtml(unsafe); // "Hello"
* ```
*
* @public
*/
export declare function sanitizeHtml(input: string): string;
/**
* Sanitizes search input to prevent injection attacks (SQL injection, XSS, etc.).
* Removes dangerous characters and limits length to prevent DoS attacks.
*
* @param input - The search input string to sanitize
* @returns Sanitized string with dangerous characters removed (max 1000 characters)
*
* @example
* ```tsx
* import { sanitizeSearchInput } from 'tanstack-shadcn-table/security/sanitize';
*
* const unsafe = 'user"; DROP TABLE users; --';
* const safe = sanitizeSearchInput(unsafe); // "user DROP TABLE users "
* ```
*
* @public
*/
export declare function sanitizeSearchInput(input: string): string;
/**
* Validates and sanitizes column filter values based on filter type.
* Applies appropriate sanitization for each filter type:
* - Text/Custom: Sanitizes as search input
* - Select/Multi-select: Sanitizes array or string values
* - Range: Validates and bounds numeric values (-1,000,000 to 1,000,000)
* - Boolean: Converts to boolean type
* - Date/Date-range: Validates and formats as ISO date string
*
* @param value - The filter value to sanitize
* @param filterType - The type of filter ("text", "range", "select", "boolean", "date", etc.)
* @returns Sanitized filter value appropriate for the filter type
*
* @example
* ```tsx
* import { sanitizeFilterValue } from 'tanstack-shadcn-table/security/sanitize';
*
* // Text filter
* const safeText = sanitizeFilterValue('<script>alert("xss")</script>', 'text');
*
* // Range filter
* const safeRange = sanitizeFilterValue([-100, 9999999], 'range'); // [-100, 1000000]
*
* // Boolean filter
* const safeBool = sanitizeFilterValue('true', 'boolean'); // true
* ```
*
* @public
*/
export declare function sanitizeFilterValue(value: any, filterType: string): any;