@mimik/lib-filters
v2.0.7
Published
Libraries for filter process
Readme
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]) ⇒ Object
- ~isProd(env) ⇒ Boolean
- ~logs(origObject, config) ⇒ Object
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]) ⇒ Object
Replace lengthy strings by --(string length)-- in a given object.
Kind: inner method of lib-filters
Returns: Object - The transformed object.
Category: sync
| Param | Type | Default | Description | | --- | --- | --- | --- | | object | Object | | The object where strings will be replaced. | | [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 undefined/null, 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
Kind: inner method of lib-filters
Returns: Object - The filtered object.
Category: sync
| Param | Type | Description | | --- | --- | --- | | origObject | Object | The object to apply filtering. | | config | Array.<String> | An array of JSONPath strings defining the fields to mask. |
Example
const filtered = logs(
{ password: 'secret', user: 'john' },
['$.password'],
);
// filtered.password === '-------'
// filtered.user === 'john'