pii-paladin
Version:
A Node.js package to censor PII in a string using a hybrid NER and Regex approach.
56 lines (55 loc) • 2.16 kB
TypeScript
/**
* Censors detected Personally Identifiable Information (PII) in a string using a hybrid approach.
*
* This function combines Named Entity Recognition (NER) for contextual PII (names, orgs, locations)
* with Regular Expressions (Regex) for structured PII (SSN, credit cards, emails, phones, etc.).
*
* @param {string} input The string to censor.
* @returns {Promise<string>} A promise that resolves to the censored string.
*/
export function censorPII(input: string): Promise<string>;
/**
* @typedef {object} PIIEntity
* @property {string} entity_group - The type of PII detected (e.g., 'PER', 'ORG', 'LOC', 'SSN', 'EMAIL').
* @property {string} word - The actual text of the detected PII.
* @property {number} start - The starting character index of the PII in the original string.
* @property {number} end - The ending character index of the PII in the original string.
* @property {number} score - The confidence score of the detection (for NER, 1.0 for regex).
*/
/**
* Singleton class to manage the Named Entity Recognition (NER) pipeline from transformers.js.
* Ensures that the NER model is loaded only once.
*/
export class NerPipelineSingleton {
static task: string;
static model: string;
static instance: null;
/**
* Retrieves the singleton instance of the NER pipeline.
* @param {function} [progress_callback=null] - Optional callback function for progress updates during model loading.
* @returns {Promise<object>} A promise that resolves to the NER pipeline instance.
*/
static getInstance(progress_callback?: Function): Promise<object>;
}
export type PIIEntity = {
/**
* - The type of PII detected (e.g., 'PER', 'ORG', 'LOC', 'SSN', 'EMAIL').
*/
entity_group: string;
/**
* - The actual text of the detected PII.
*/
word: string;
/**
* - The starting character index of the PII in the original string.
*/
start: number;
/**
* - The ending character index of the PII in the original string.
*/
end: number;
/**
* - The confidence score of the detection (for NER, 1.0 for regex).
*/
score: number;
};