test-stringx
v1.0.0
Published
A complete testing suite for the [stringx-js](https://www.stringx-js.com/) package, featuring **357 tests** across basic functionality, advanced scenarios, performance benchmarks, and security validations.
Downloads
3
Readme
StringX-JS Comprehensive Test Suite
A complete testing suite for the stringx-js package, featuring 357 tests across basic functionality, advanced scenarios, performance benchmarks, and security validations.
Quick Start
# Install dependencies
npm install
# Run all tests
npm test
# Run specific test categories
npm run test:basic # Basic functionality tests
npm run test:advanced # Advanced use cases and edge cases
npm run test:performance # Performance benchmarks
npm run test:security # Security validationsTest Results Summary
✅ 344/357 tests passing (96.4% success rate)
⏱️ Total duration: ~781ms
📦 Package tested: stringx-js v1.1.2Test Categories
1. Basic Tests (156 tests - ✅ 100% pass)
Tests core functionality of Str, Number, and Arr classes:
- String case conversions (camel, snake, kebab, studly, title)
- String extraction and manipulation
- Number formatting and parsing
- Array operations with dot notation
- Type-safe getters
- Fluent chaining
Run: npm run test:basic
2. Advanced Tests (144 tests - ✅ 94% pass)
Tests complex scenarios and real-world use cases:
- Complex fluent chaining
- Unicode and international text
- Advanced pattern matching
- Multi-language number spelling
- Deeply nested data structures
- E-commerce and API integration scenarios
Run: npm run test:advanced
3. Performance Tests (20+ tests - ✅ 95% pass)
Benchmarks performance with various workloads:
- Large string operations (100k+ characters)
- Bulk operations (1k-10k iterations)
- Cache performance validation
- Memory efficiency tests
- Stress tests
Run: npm run test:performance
4. Security Tests (37 tests - ✅ 93% pass)
Validates security against common attacks:
- XSS payload handling
- SQL injection prevention
- Command injection detection
- Path traversal attempts
- Prototype pollution (⚠️ vulnerability found)
- ReDoS pattern detection
- Secure random generation
Run: npm run test:security
Test Files
tests/
├── basic-str.test.js # Str class basic tests (79 tests)
├── basic-number.test.js # Number class basic tests (39 tests)
├── basic-arr.test.js # Arr class basic tests (38 tests)
├── advanced-str.test.js # Str advanced tests (74 tests)
├── advanced-number.test.js # Number advanced tests (39 tests)
├── advanced-arr.test.js # Arr advanced tests (31 tests)
├── performance.test.js # Performance benchmarks (20+ tests)
└── security.test.js # Security tests (37 tests)Key Features Tested
✅ String Operations (Str)
- 95+ methods including camel, snake, kebab case conversions
- Pattern matching with regex
- UUID/ULID/password generation
- Slug generation for URLs
- Base64 encoding/decoding
- Pluralization and singularization
- Fluent chaining with
of()
✅ Number Operations (Number)
- Number formatting with locales
- Currency formatting (USD, EUR, GBP, JPY, etc.)
- File size formatting (B, KB, MB, GB, TB)
- Human-readable numbers (1K, 2M, 3B)
- Number spelling in 16+ languages
- Ordinal numbers (1st, 2nd, 3rd)
- Percentage formatting
✅ Array Operations (Arr)
- Dot notation for nested data (
user.profile.email) - Plucking and mapping
- Filtering and sorting
- Type-safe getters (boolean, integer, float, string, array)
- Array flattening and collapsing
- CSS class/style generation
- Query string building
Performance Highlights
| Operation | Workload | Performance | |-----------|----------|-------------| | String operations | 100k chars | < 100ms | | UUID generation | 1000 UUIDs | < 200ms | | Number formatting | 10k numbers | < 200ms | | Dot notation access | 10k accesses | < 100ms | | Array filtering | 10k items | < 200ms | | Fluent chaining | 1000 chains | < 100ms |
Security Findings
✅ Secure Features
- Cryptographically secure UUID/ULID generation
- XSS payload sanitization
- SQL injection prevention
- Secure password generation
- Sensitive data masking
⚠️ Security Concerns
- Prototype Pollution:
Arr.set()allows setting__proto__which pollutes Object.prototype- Workaround: Never use
__proto__,constructor, orprototypeas keys
- Workaround: Never use
- ReDoS Risk: Some regex operations could be vulnerable to denial of service
- Mitigation: Validate and sanitize regex patterns from user input
Usage Examples
String Operations
import Str from 'stringx-js';
// Fluent chaining
const result = Str.of(' [email protected] ')
.trim()
.lower()
.before('@')
.replace('.', '_')
.camel()
.toString(); // 'johnDoe'
// UUID generation
const id = Str.uuid(); // 'e3c2d7a4-5c8e-4b2f-...'
// Slug generation
const slug = Str.slug('Hello World 2024'); // 'hello-world-2024'Number Operations
import { Number } from 'stringx-js';
// Format numbers
Number.format(1234567.89, 2); // '1,234,567.89'
// Currency
Number.currency(1234.56); // '$1,234.56'
// File sizes
Number.fileSize(1024 * 1024); // '1 MB'
// Human-readable
Number.abbreviate(1500000); // '2M'
// Spell in multiple languages
Number.spell(42, 'en'); // 'forty-two'
Number.spell(42, 'fr'); // 'quarante-deux'Array Operations
import { Arr } from 'stringx-js';
// Dot notation
const data = { user: { name: 'John', profile: { email: '[email protected]' } } };
Arr.get(data, 'user.profile.email'); // '[email protected]'
// Pluck values
const users = [
{ name: 'John', age: 30 },
{ name: 'Jane', age: 25 }
];
Arr.pluck(users, 'name'); // ['John', 'Jane']
// Flatten nested data
const nested = { 'user.name': 'John', 'user.age': 30 };
Arr.undot(nested); // { user: { name: 'John', age: 30 } }Requirements
- Node.js >= 14.0.0
- npm or yarn
Contributing
Feel free to add more tests or improve existing ones:
- Fork the repository
- Add your tests in the appropriate file
- Ensure tests follow the existing structure
- Run
npm testto verify - Submit a pull request
Test Structure
Each test file uses Node.js native test runner with this structure:
import { describe, it } from 'node:test';
import assert from 'node:assert';
describe('Feature Name', () => {
describe('Sub-feature', () => {
it('should do something', () => {
assert.strictEqual(actual, expected);
});
});
});Reporting Issues
If you find bugs or security vulnerabilities:
- Check TEST_SUMMARY.md for known issues
- Create an issue at stringx-js GitHub
- Include test case and expected behavior
Resources
- Official Website: https://www.stringx-js.com/
- NPM Package: https://www.npmjs.com/package/stringx-js
- GitHub: https://github.com/AymanAtmeh/stringx-js
- Documentation: See README in node_modules/stringx-js
License
MIT
Created for: stringx-js v1.1.2 Test Coverage: 96.4% (344/357 tests passing) Last Updated: October 31, 2025
