Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const { obscureString } = require('obscure-string');

// Basic usage
obscureString('mysecretkey');
// → 'mys*****key'
// → 'mys******ey'

// Custom configuration
obscureString('john.doe@example.com', {
Expand Down Expand Up @@ -149,7 +149,7 @@ Main function to obscure a string.
```js
// Standard masking
obscureString('mysecretkey');
// → 'mys*****key'
// → 'mys******ey'

// Custom mask character
obscureString('secret', { maskChar: '█' });
Expand Down Expand Up @@ -564,7 +564,7 @@ npx obscure-string <string> [options]
```bash
# Basic masking
obscure-string "mysecretkey"
# → mys*****key
# → mys******ey

# Custom prefix/suffix and mask character
obscure-string "my-secret-token" --prefix 2 --suffix 4 --char "#"
Expand Down
10 changes: 5 additions & 5 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ describe('obscureString - Enhanced Input Validation', () => {
const result = obscureString(longString);
expect(result.length).toBe(10000);
expect(result.startsWith('aaa')).toBe(true);
expect(result.endsWith('aaa')).toBe(true);
expect(result.slice(3, -3)).toBe('*'.repeat(9994));
expect(result.endsWith('aa')).toBe(true);
expect(result.slice(3, -2)).toBe('*'.repeat(9995));
});

test('throws error for strings exceeding maxLength', () => {
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('obscureString - Unicode & Special Characters', () => {

test('handles mixed unicode and ASCII', () => {
const result = obscureString('user@例え.com');
expect(result).toBe('use*****com');
expect(result).toBe('use*******com');
});

test('handles special characters', () => {
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('obscureString - Security Edge Cases', () => {
test('handles SQL injection patterns', () => {
const sql = "'; DROP TABLE users; --";
const result = obscureString(sql);
expect(result).toBe("'; ***************** --");
expect(result).toBe("'; *****************; --");
});

test('handles path traversal attempts', () => {
Expand Down Expand Up @@ -325,7 +325,7 @@ describe('obscureStringBatch', () => {

test('handles array with mixed types', () => {
const result = obscureStringBatch(['string', 123, null, undefined]);
expect(result[0]).toBe('str*ng');
expect(result[0]).toBe('string'); // Too short with new default suffix=3
expect(result[1]).toBe('123'); // Too short
expect(result[2]).toBe('');
expect(result[3]).toBe('');
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ A tiny utility for masking the middle of strings. Perfect for redacting secrets,
```js
import { obscureString } from 'obscure-string';

obscureString('mysecretkey'); // → 'mys*****key'
obscureString('mysecretkey'); // → 'mys******ey'
```
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { obscureString } from 'obscure-string';

obscureString('mysecretkey');
// → 'mys*****key'
// → 'mys******ey'

obscureString('john.doe@example.com', {
prefixLength: 2,
Expand Down
Loading