Object
Provides masking operations for object
and array
data types with customizable rules.
Object
ts
import { maskObject } from 'maskio';
const source = {
firstCode: '123456',
otherCode: {
resultCode: '123',
name: 'Xiao Ming',
},
};
const config = { '^.*Code$': 'all', '^otherCode.name$': 'userName' };
console.log(maskObject(source, config));
// Apply full masking to fields ending with "Code", precise masking for otherCode.name
// Output: {"firstCode": "******","otherCode": {"resultCode": "***","name": "********g"}}
Array
ts
import { maskObject } from 'maskio';
const sourceArr = [
123,
{
firstCode: '123456',
otherCode: [
{
resultCode: '123',
other: '234',
},
123,
235,
],
},
];
const config = { '^.*Code$': 'all' };
console.log(maskObject(sourceArr, config));
// Array traversal with full masking for Code-ending fields
// Output: [ 123, { firstCode: '******', otherCode: [ { resultCode: '***', other: '234' }, 123, 235 ]}]
Special Data
Only masks number
and string
data types:
ts
import { maskObject } from 'maskio';
const sourceType = {
strCode: '123456',
numCode: 123,
funcCode: () => {},
arrCode: [1, 2],
boolCode: true,
};
const config = { '^.*Code$': 'all' };
console.log(maskObject(sourceType, config));
// Output: {strCode: '******', numCode: '***', funcCode: [Function: funcCode], arrCode: [ 1, 2 ], boolCode: true}