PIIDetector class
The core PII detection and sanitization engine.
Singleton class that detects and replaces Personally Identifiable Information in strings using regex patterns and optional validators.
final detector = PIIDetector();
final clean = detector.sanitize('Email: john@test.com');
print(clean); // 'Email: [EMAIL HIDDEN]'
Constructors
- PIIDetector()
-
Returns the singleton PIIDetector instance.
factory
Properties
- config → ShieldConfig
-
The current configuration.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- report → ShieldReport?
-
The detection report, or null if reporting is disabled.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
sensitiveNames
→ Set<
String> -
Returns the set of currently registered sensitive names.
no setter
Methods
-
addPattern(
PIIPattern pattern) → void - Adds a custom PIIPattern at runtime.
-
clearNames(
) → void - Clears all registered sensitive names.
-
configure(
ShieldConfig config) → void -
Configures the detector with the given
config. -
containsPII(
String input) → bool -
Returns true if
inputcontains any detectable PII. -
detect(
String input) → List< PIIMatch> -
Detects all PII in
inputand returns a list of PIIMatch objects. -
getPIIType(
String input) → PIIType? -
Returns the PIIType of the first PII found in
input, or null. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerName(
String name) → void -
Registers a single sensitive
namefor name detection. -
registerNames(
List< String> names) → void -
Registers multiple sensitive
namesat once. -
removePattern(
PIIType type) → void -
Removes all patterns of the given
type. -
reset(
) → void - Resets the detector to its default state.
-
sanitize(
String input) → String -
The main sanitization method. Replaces all detected PII in
inputwith configured replacement text. -
sanitizeJson(
Map< String, dynamic> json, {List<String> ? sensitiveKeys}) → Map<String, dynamic> -
Sanitizes a JSON map by replacing values of sensitive keys with
[REDACTED]and running PII detection on remaining string values. -
toString(
) → String -
A string representation of this object.
inherited
-
unregisterName(
String name) → void -
Removes a previously registered
name.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
-
defaultSensitiveKeys
→ const List<
String> - The default sensitive keys used for JSON sanitization.