Shared utility package for intlify project providing performance tools, string formatting, event emitters, and type checking utilities.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
String formatting, HTML escaping, and sanitization functions for secure text processing and internationalization.
Format strings with placeholders using object or array arguments.
/**
* Format strings with placeholder replacement
* @param message - Template string with {key} placeholders
* @param args - Values to substitute (object or individual arguments)
* @returns Formatted string with placeholders replaced
*/
function format(message: string, ...args: any): string;Usage Examples:
import { format } from "@intlify/shared";
// Using individual arguments
const msg1 = format("Hello {0}, you have {1} messages", "Alice", 5);
// Result: "Hello Alice, you have 5 messages"
// Using object properties
const msg2 = format("Welcome {name}! Today is {day}.", {
name: "Bob",
day: "Monday"
});
// Result: "Welcome Bob! Today is Monday."
// Missing properties are replaced with empty string
const msg3 = format("Hello {name}, you have {count} items", { name: "Charlie" });
// Result: "Hello Charlie, you have items"Escape HTML special characters to prevent XSS attacks.
/**
* Escape HTML special characters to prevent XSS
* @param rawText - Raw text that may contain HTML characters
* @returns HTML-safe escaped string
*/
function escapeHtml(rawText: string): string;Usage Example:
import { escapeHtml } from "@intlify/shared";
const userInput = "<script>alert('XSS')</script>";
const safeHtml = escapeHtml(userInput);
// Result: "<script>alert('XSS')</script>"Sanitize translated HTML content by neutralizing dangerous elements while preserving safe markup.
/**
* Sanitize HTML content in translations by neutralizing dangerous elements
* @param html - HTML content to sanitize
* @returns Sanitized HTML with dangerous elements neutralized
*/
function sanitizeTranslatedHtml(html: string): string;Usage Example:
import { sanitizeTranslatedHtml } from "@intlify/shared";
// Neutralizes event handlers and javascript: URLs
const dangerousHtml = '<a href="javascript:alert(1)" onclick="harm()">Click</a>';
const safeHtml = sanitizeTranslatedHtml(dangerousHtml);
// Event handlers and javascript: URLs are neutralizedConvert values to display-friendly strings.
/**
* Convert values to display-friendly strings
* @param val - Value to convert to display string
* @returns String representation suitable for display
*/
function toDisplayString(val: unknown): string;Usage Example:
import { toDisplayString } from "@intlify/shared";
console.log(toDisplayString(null)); // ""
console.log(toDisplayString(undefined)); // ""
console.log(toDisplayString([1, 2, 3])); // "[\n 1,\n 2,\n 3\n]"
console.log(toDisplayString({ name: "Alice" })); // "{\n \"name\": \"Alice\"\n}"
console.log(toDisplayString("hello")); // "hello"Join array of strings with a separator.
/**
* Join array of strings with separator
* @param items - Array of strings to join
* @param separator - Separator to use between items (default: empty string)
* @returns Joined string
*/
function join(items: string[], separator?: string): string;Usage Example:
import { join } from "@intlify/shared";
const words = ["hello", "world", "test"];
console.log(join(words)); // "helloworldtest"
console.log(join(words, " ")); // "hello world test"
console.log(join(words, ", ")); // "hello, world, test"Safe JSON stringification with unicode character escaping.
/**
* JSON stringify with escaped unicode line/paragraph separators
* @param json - Value to stringify
* @returns JSON string with escaped unicode characters
*/
function friendlyJSONstringify(json: unknown): string;Create symbols with optional global registration.
/**
* Create symbols with optional global registration
* @param name - Symbol name/description
* @param shareable - Whether to use global symbol registry (default: false)
* @returns Symbol instance
*/
function makeSymbol(name: string, shareable?: boolean): symbol;Usage Example:
import { makeSymbol } from "@intlify/shared";
// Create unique symbol
const uniqueKey = makeSymbol("myKey");
// Create globally shareable symbol
const globalKey = makeSymbol("globalKey", true);
const sameGlobalKey = makeSymbol("globalKey", true);
console.log(globalKey === sameGlobalKey); // trueGenerate cache keys for format operations.
/**
* Generate cache keys for format operations
* @param locale - Locale identifier
* @param key - Message key
* @param source - Source string
* @returns Cache key string
*/
function generateFormatCacheKey(locale: string, key: string, source: string): string;Generate formatted code frames for error display and debugging.
/**
* Generate formatted code frames for error display
* @param source - Source code string
* @param start - Start position for highlighting (default: 0)
* @param end - End position for highlighting (default: source.length)
* @returns Formatted code frame with line numbers and highlighting
*/
function generateCodeFrame(source: string, start?: number, end?: number): string;Usage Example:
import { generateCodeFrame } from "@intlify/shared";
const code = `const message = "Hello {name}";
console.log(message);`;
const errorStart = code.indexOf("{name}");
const errorEnd = errorStart + "{name}".length;
const frame = generateCodeFrame(code, errorStart, errorEnd);
console.log(frame);
// Outputs formatted code frame with line numbers and highlighting