@robinpath/sanitize
0.1.0PublicInput sanitization utilities for security: HTML escaping, XSS prevention, SQL escaping, filename and path sanitization, URL cleaning, and more
@robinpath/sanitize
Input sanitization utilities for security: HTML escaping, XSS prevention, SQL escaping, filename and path sanitization, URL cleaning, and more
Why use this module?
The sanitize module lets you:
- Strip or escape HTML tags from input
- Remove XSS attack vectors from input
- Escape SQL special characters to prevent injection
- Escape special regex characters in a string
- Sanitize a string for safe use as a filename
All functions are callable directly from RobinPath scripts with a simple, consistent API.
Installation
npm install @robinpath/sanitize
Quick Start
No credentials needed — start using it right away:
sanitize.xss
Available Functions
| Function | Description |
|---|---|
sanitize.html | Strip or escape HTML tags from input |
sanitize.xss | Remove XSS attack vectors from input |
sanitize.sql | Escape SQL special characters to prevent injection |
sanitize.regex | Escape special regex characters in a string |
sanitize.filename | Sanitize a string for safe use as a filename |
sanitize.path | Prevent path traversal attacks by sanitizing a file path |
sanitize.url | Sanitize a URL, stripping dangerous protocols like javascript: |
sanitize.email | Normalize an email address (lowercase, remove dots/plus aliases for Gmail) |
sanitize.stripTags | Remove all HTML tags from a string, optionally allowing specific tags |
sanitize.escapeHtml | Escape HTML special characters: & < > " ' |
sanitize.unescapeHtml | Unescape HTML entities back to their original characters |
sanitize.trim | Deep trim all string values within an object, array, or string |
sanitize.truncate | Truncate a string to a maximum length with a suffix |
sanitize.alphanumeric | Strip all non-alphanumeric characters from a string |
sanitize.slug | Sanitize a string into a URL-safe slug |
Examples
Remove XSS attack vectors from input
sanitize.xss
Escape SQL special characters to prevent injection
sanitize.sql
Escape special regex characters in a string
sanitize.regex
Integration with RobinPath
import { RobinPath } from "@wiredwp/robinpath";
import Module from "@robinpath/sanitize";
const rp = new RobinPath();
rp.registerModule(Module.name, Module.functions);
rp.registerModuleMeta(Module.name, Module.functionMetadata);
const result = await rp.executeScript(`
sanitize.xss
`);
Full API Reference
See MODULE.md for complete documentation including all parameters, return types, error handling, and advanced examples.
Related Modules
@robinpath/json— JSON module for complementary functionality
License
MIT
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.0 | latest | yesterday |
Related Modules
@dev-tester/hello-world
Updated description
@robinpath/apollo
Apollo module for RobinPath.
@robinpath/archive
Create and extract .zip and .tar.gz file archives
@robinpath/assert
Testing assertions: equal, deepEqual, truthy, falsy, type checks, includes, matches, throws, and more
$ robinpath install @robinpath/sanitize
