restore
Reverse tokenization to recover original PII values.
Usage
import { createMasker } from '@pii-mask/core';
const masker = createMasker({ mode: 'tokenize' });
const { result, tokenMap } = masker.maskObject({
email: 'lucky@example.com',
phone: '+2348012345678',
});
// Send tokenized data to an LLM or external API...
// Then restore the originals:
const restored = masker.restore(result, tokenMap);
console.log(JSON.parse(restored));
// → { email: 'lucky@example.com', phone: '+2348012345678' }Convenience methods
For structured data, use restoreObject() or restoreArray() to restore and parse in one step:
const masker = createMasker({ mode: 'tokenize' });
const { result, tokenMap } = masker.maskObject({
email: 'lucky@example.com',
phone: '+2348012345678',
});
// Restore and parse as object
const obj = masker.restoreObject(result, tokenMap);
// → { email: 'lucky@example.com', phone: '+2348012345678' }
// For arrays
const { result: arrResult, tokenMap: arrMap } = masker.maskArray([{ email: 'lucky@example.com' }]);
const arr = masker.restoreArray(arrResult, arrMap);How it works
restore() replaces each token in the masked string with its original value from the token map. The token map is a Record<string, string> where keys are tokens and values are the original PII.
Only works with tokenize mode output.