slash-updated
v1.0.0
Published
Enhanced path slash converter with advanced features - Convert Windows backslash paths to slash paths with additional utilities
Maintainers
Readme
slash-updated
Enhanced path slash converter with advanced features - Convert Windows backslash paths to slash paths with additional utilities
slash-updated is a powerful, zero-dependency TypeScript library that converts Windows backslash paths to forward slash paths with enhanced features and utilities. It's designed to be a drop-in replacement for the popular slash package while providing additional functionality.
🚀 Features
- Zero dependencies - Truly minimal with only TypeScript as dev dependency
- Ultra lightweight - Less than 3KB minified
- Full TypeScript support - Built with TypeScript, includes complete type definitions
- Enhanced functionality - More features than similar packages
- Path validation - Validate paths with customizable rules
- Path sanitization - Clean and sanitize paths automatically
- Bulk operations - Process multiple paths efficiently
- Detailed metadata - Get comprehensive information about path transformations
- Cross-platform - Works on Windows, macOS, and Linux
- CommonJS - Works with both old and modern Node.js projects
- Extensive testing - Comprehensive test suite using Node.js built-in test runner
- Modern codebase - Clean, readable, and maintainable code
📦 Installation
npm install slash-updatedyarn add slash-updatedpnpm add slash-updated🔧 Usage
Basic Usage
import slash from "slash-updated";
// Basic conversion
slash("C:\\Users\\John\\Documents");
// → 'C:/Users/John/Documents'
slash("foo\\bar\\baz");
// → 'foo/bar/baz'
// Already forward slashes (no change)
slash("foo/bar/baz");
// → 'foo/bar/baz'
// Extended-length paths are preserved
slash("\\\\?\\C:\\very long path");
// → '\\\\?\\C:\\very long path'Advanced Options
import slash from "slash-updated";
// Normalize with options
slash(" foo\\\\bar\\..\\baz\\ ", {
trim: true, // Remove leading/trailing whitespace
removeDuplicateSlashes: true, // Remove duplicate slashes
resolveRelative: true, // Resolve ../ and ./
removeTrailingSlash: true, // Remove trailing slash
});
// → 'foo/baz'
// Ensure trailing slash
slash("foo\\bar", { ensureTrailingSlash: true });
// → 'foo/bar/'Path Metadata
import { slashWithMetadata } from "slash-updated";
const result = slashWithMetadata("C:\\Users\\John\\Documents");
console.log(result);
// {
// path: 'C:/Users/John/Documents',
// original: 'C:\\Users\\John\\Documents',
// changed: true,
// type: 'windows',
// isAbsolute: true,
// segments: ['C:', 'Users', 'John', 'Documents']
// }Bulk Operations
import { slashBulk } from "slash-updated";
const paths = ["C:\\Users\\John", "D:\\Projects\\MyApp", "relative\\path"];
const results = slashBulk(paths, {
includeMetadata: true,
continueOnError: true,
trim: true,
});
console.log(results);
// Array of PathResult objectsPath Validation
import { slashValidate } from "slash-updated";
const result = slashValidate(
"C:\\Users\\John",
{
trim: true,
},
{
allowEmpty: false,
allowRelative: true,
maxLength: 260,
}
);
console.log(result);
// {
// path: 'C:/Users/John',
// isValid: true,
// errors: []
// }Path Sanitization
import { slashSanitize } from "slash-updated";
// Remove invalid characters and convert
slashSanitize('C:\\Users\\John<>:|"?*\\Documents');
// → 'C:/Users/John/Documents'URL Paths
import { slashUrl, toUrlPath } from "slash-updated";
// Convert path-like URLs (preserves actual URLs)
slashUrl("path\\to\\resource");
// → 'path/to/resource'
slashUrl("https://example.com/already\\valid");
// → 'https://example.com/already\\valid' (unchanged)
// Convert to URL-suitable path
toUrlPath("path\\to\\resource");
// → '/path/to/resource'Utility Functions
import {
validatePath,
isRelativePath,
isExtendedLengthPath,
detectPathType,
sanitizePath,
} from "slash-updated";
// Validate path
const validation = validatePath("C:\\Users\\John", {
allowEmpty: false,
maxLength: 260,
});
// Check if path is relative
isRelativePath("./relative/path"); // → true
isRelativePath("C:\\absolute\\path"); // → false
// Check for extended-length path
isExtendedLengthPath("\\\\?\\C:\\long\\path"); // → true
// Detect path type
detectPathType("C:\\Windows\\path"); // → 'windows'
detectPathType("/unix/path"); // → 'posix'
detectPathType("mixed\\path/style"); // → 'mixed'
detectPathType("https://example.com"); // → 'url'
// Sanitize path
sanitizePath('file<>:"|?*name'); // → 'filename'📚 API
slash(path, options?)
Convert Windows backslash paths to slash paths.
Parameters
path(string): The path to convertoptions(NormalizeOptions): Optional normalization options
Returns
string: The converted path
Options
interface NormalizeOptions {
trim?: boolean; // Remove leading/trailing whitespace
removeDuplicateSlashes?: boolean; // Remove duplicate slashes
resolveRelative?: boolean; // Resolve ../ and ./
removeTrailingSlash?: boolean; // Remove trailing slash
ensureTrailingSlash?: boolean; // Ensure trailing slash
}slashWithMetadata(path, options?)
Convert path and return detailed metadata.
Returns
interface PathResult {
path: string; // Converted path
original: string; // Original path
changed: boolean; // Whether path was changed
type: "windows" | "posix" | "mixed" | "url";
isAbsolute: boolean; // Whether path is absolute
segments: string[]; // Path segments
}slashBulk(paths, options?)
Process multiple paths at once.
Options
interface BulkOptions extends NormalizeOptions {
continueOnError?: boolean; // Continue processing on error
includeMetadata?: boolean; // Return metadata for each path
}slashValidate(path, options?, validationOptions?)
Convert and validate path.
Validation Options
interface ValidationOptions {
allowEmpty?: boolean; // Allow empty paths
allowRelative?: boolean; // Allow relative paths
maxLength?: number; // Maximum path length
customValidator?: (path: string) => boolean; // Custom validation
}Other Functions
slashSanitize(path, options?)- Convert and sanitize pathslashUrl(url, options?)- Convert URL-like pathstoUrlPath(path, options?)- Convert to URL-suitable pathvalidatePath(path, options?)- Validate pathisRelativePath(path)- Check if path is relativeisExtendedLengthPath(path)- Check for extended-length pathdetectPathType(path)- Detect path typesanitizePath(path)- Sanitize path
🆚 Comparison with Other Packages
| Feature | slash-updated | slash | upath | normalize-path | | ---------------------------- | ---------------- | ----------- | ----------- | -------------- | | Size | ~3KB | ~3KB | ~20KB | ~4KB | | Dependencies | 0 | 0 | 1 | 0 | | Dev Dependencies | 1 (TypeScript) | 7+ | 10+ | 5+ | | TypeScript | ✅ Built-in | ✅ Built-in | ✅ Built-in | ❌ External | | Basic conversion | ✅ | ✅ | ✅ | ✅ | | Path validation | ✅ | ❌ | ❌ | ❌ | | Path sanitization | ✅ | ❌ | ❌ | ❌ | | Bulk operations | ✅ | ❌ | ❌ | ❌ | | Detailed metadata | ✅ | ❌ | ❌ | ❌ | | URL path support | ✅ | ❌ | ❌ | ❌ | | Custom validation | ✅ | ❌ | ❌ | ❌ | | Path type detection | ✅ | ❌ | ❌ | ❌ | | Relative path resolution | ✅ | ❌ | ✅ | ✅ | | Trailing slash control | ✅ | ❌ | ❌ | ❌ | | Test Framework | Node.js built-in | Jest/Ava | Mocha | Jest | | Build Complexity | Minimal | Minimal | Complex | Minimal |
Why Choose slash-updated?
- Truly Zero Dependencies: Only TypeScript as dev dependency, no runtime dependencies
- More Features: Extensive functionality beyond basic conversion
- Better DX: Rich TypeScript support with detailed types
- Validation: Built-in path validation with customizable rules
- Flexibility: Multiple utility functions for different use cases
- Simplicity: Uses Node.js built-in test runner, no complex tooling
- Performance: Optimized for both single and bulk operations
- Modern: Built with modern JavaScript and TypeScript practices
- Lightweight: Minimal footprint with maximum functionality
🧪 Testing
npm test # Run tests using Node.js built-in test runnerThe package uses Node.js built-in test runner (available in Node.js 18+), eliminating the need for external testing frameworks like Jest or Mocha.
🛠️ Development
# Clone repository
git clone https://github.com/noorjsdivs/slash-updated.git
cd slash-updated
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Lint
npm run lint
# Format code
npm run format📋 Requirements
- Node.js >= 18.0.0 (for Node.js built-in test runner)
- TypeScript >= 5.0.0 (for TypeScript projects, dev only)
📝 License
MIT © ReactJS BD
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
🙏 Support
If you found this project helpful, please consider:
- ⭐ Starring the repository
- 🐛 Reporting issues
- 💡 Suggesting new features
- ☕ Buy me a coffee
📺 Learn More
Check out my YouTube channel for more programming content: ReactJS BD
Made with ❤️ by ReactJS BD
