Skip to main content

Usage

Analyzing a Single Username

import { analyzeUsername } from '@fazelstudio/username-intelligence';

const result = analyzeUsername('h4ck3r_man');

Options

You can pass an options object as the second argument:

const result = analyzeUsername('username', {
strict: false, // Enable stricter validation
blockProfanity: false, // Reject usernames containing profanity
reservedWords: [], // Custom blocked words
checkVisual: true, // Check for visual spoofing
enableCache: true, // Enable LRU result caching
enableSecurity: true, // Enable security analysis
enableLinguistic: true, // Enable linguistic analysis
enableVisual: true, // Enable visual analysis
enablePatterns: true, // Enable pattern detection
enableStructure: true, // Enable structural analysis
});

Output Structure

The result object contains:

FieldDescription
inputOriginal input username
metaLength, normalized form, byte/grapheme length
statsEntropy, character counts
scriptUnicode script detection, mixed-script flags
patternsDetected patterns (leet, separator-style, etc.)
securityThreat detection (invisibles, homoglyphs, phishing)
structureStructural analysis (transitions, density)
linguisticWord-likeness, name-likeness, pronounceability
visualReadability, aesthetic, distinctiveness scores
complexityCharset size, efficiency
classificationStyle, scores (0–100), levels, and recommendation

Scores and Levels

All scores are 0–100. Levels provide human-readable categories:

  • overall: Combined quality score
  • quality: Username quality
  • security_risk: How risky the username appears (higher = riskier)
  • suspicion: Suspicion level (higher = more suspicious)
  • authenticity: How authentic the username seems
  • professionalism: Professionalism score
  • entropy: Shannon entropy value

Level examples: low, trusted, good, probably-authentic, semi-professional, recommended

Batch Analysis

Analyze multiple usernames at once:

import { batchAnalyze } from '@fazelstudio/username-intelligence';

const results = batchAnalyze(['h4ck3r_man', 'john_doe', 'user123'], {
stopOnError: false,
includeErrors: true,
});

Returns an array of { username, analysis, success } objects.

Comparing Usernames

import { compareUsernames } from '@fazelstudio/username-intelligence';

const comparison = compareUsernames('h4ck3r_man', 'hacker_man');
console.log(comparison.comparison.similarity_score);
// Output: e.g., 72 (out of 100)

Cache Management

import { clearCache, getCacheStats } from '@fazelstudio/username-intelligence';

console.log(getCacheStats());
// { size: 5, maxSize: 500 }

clearCache();

Utility Functions

import {
normalizeUsername,
calculateEntropy,
detectHomoglyphs,
detectConfusables,
isLikelyPhishing,
analyzeScriptConsistency,
} from '@fazelstudio/username-intelligence';

const normalized = normalizeUsername('MyUser_123');
const entropy = calculateEntropy('xcv892nm');
const hasHomoglyphs = detectHomoglyphs('раураl');
const isPhishing = isLikelyPhishing('раураl');

Error Handling

The library validates inputs before analysis:

analyzeUsername(''); // Throws: Username must be a non-empty string
analyzeUsername(123); // Throws: Username must be a non-empty string
analyzeUsername('a'.repeat(1001)); // Throws: Username exceeds max length of 1000
batchAnalyze('string'); // Throws: batchAnalyze requires an array