@mimik/lib-filters
lib-filters
Example (Default import)
import libFilters from '@mimik/lib-filters';
Example (Named imports)
import { lengthyString, isProd, logs, MASK } from '@mimik/lib-filters';
- lib-filters
- ~MASK :
String - sync
- ~lengthyString(object, [length]) ⇒
* - ~isProd(env) ⇒
Boolean - ~logs(origObject, [config]) ⇒
Object
- ~lengthyString(object, [length]) ⇒
- ~MASK :
lib-filters~MASK : String
The default masking string used by logs to replace sensitive values.
Kind: inner constant of lib-filters
Default: '-------'
lib-filters~lengthyString(object, [length]) ⇒ *
Replace lengthy strings by --concat(<string length>)-- in a given value.
Kind: inner method of lib-filters
Returns: * - The input value with long strings replaced.
Category: sync
| Param | Type | Default | Description |
|---|---|---|---|
| object | * |
The value where long strings will be replaced. Strings, numbers, arrays and objects are all supported. | |
| [length] | Number |
1000 |
The length at which the replacement happens. If no length or a length of 0 is given the default length is 1000 characters. Optional. |
lib-filters~isProd(env) ⇒ Boolean
Check if the environment is production.
Kind: inner method of lib-filters
Returns: Boolean - Returns true if env is any falsy value (e.g. undefined, null, '', 0, false), or is 'prod'/'production' (case-insensitive).
Category: sync
| Param | Type | Description |
|---|---|---|
| env | String |
The environment property. |
lib-filters~logs(origObject, [config]) ⇒ Object
Mask the variables defined in the config on the object. Follows the jsonpath pattern for masking: https://www.npmjs.com/package/jsonpath
Security note: config is evaluated as JSONPath (including [?(...)] filter
expressions) and must always be developer-controlled, trusted input. An
attacker-influenced config string is an expression-evaluation vector.
Kind: inner method of lib-filters
Returns: Object - The filtered object.
Category: sync
Throws:
Error'Input must be a valid JSON object.' when origObject is not an object.Error'Config must be an array of JSONPath strings.' when config is provided but not an array.
| Param | Type | Description |
|---|---|---|
| origObject | Object |
The object to apply filtering. |
| [config] | Array.<String> |
An array of JSONPath strings defining the fields to mask. When omitted or empty, the object is returned unchanged. |
Example
const filtered = logs(
{ password: 'secret', user: 'john' },
['$.password'],
);
// filtered.password === '-------'
// filtered.user === 'john'