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.
npm install test-stringxA complete testing suite for the stringx-js package, featuring 357 tests across basic functionality, advanced scenarios, performance benchmarks, and security validations.
``bashInstall dependencies
npm install
Test Results Summary
`
ā
344/357 tests passing (96.4% success rate)
ā±ļø Total duration: ~781ms
š¦ Package tested: stringx-js v1.1.2
`Test Categories
$3
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 chainingRun:
npm run test:basic$3
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 scenariosRun:
npm run test:advanced$3
Benchmarks performance with various workloads:
- Large string operations (100k+ characters)
- Bulk operations (1k-10k iterations)
- Cache performance validation
- Memory efficiency tests
- Stress testsRun:
npm run test:performance$3
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 generationRun:
npm run test:securityTest 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
$3
- 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()$3
- 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$3
- 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 buildingPerformance 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
$3
- Cryptographically secure UUID/ULID generation
- XSS payload sanitization
- SQL injection prevention
- Secure password generation
- Sensitive data masking$3
1. Prototype Pollution: Arr.set() allows setting __proto__ which pollutes Object.prototype
- Workaround: Never use __proto__, constructor, or prototype as keys
2. ReDoS Risk: Some regex operations could be vulnerable to denial of service
- Mitigation: Validate and sanitize regex patterns from user inputUsage Examples
$3
`javascript
import Str from 'stringx-js';// Fluent chaining
const result = Str.of(' john.doe@example.com ')
.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'
`$3
`javascript
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'
`$3
`javascript
import { Arr } from 'stringx-js';// Dot notation
const data = { user: { name: 'John', profile: { email: 'john@example.com' } } };
Arr.get(data, 'user.profile.email'); // 'john@example.com'
// 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:
1. Fork the repository
2. Add your tests in the appropriate file
3. Ensure tests follow the existing structure
4. Run
npm test to verify
5. Submit a pull requestTest Structure
Each test file uses Node.js native test runner with this structure:
`javascript
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);
});
});
});
``If you find bugs or security vulnerabilities:
1. Check TEST_SUMMARY.md for known issues
2. Create an issue at stringx-js GitHub
3. Include test case and expected behavior
- 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
MIT
---
Created for: stringx-js v1.1.2
Test Coverage: 96.4% (344/357 tests passing)
Last Updated: October 31, 2025