Socket
Socket
Sign inDemoInstall

@handy-common-utils/misc-utils

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@handy-common-utils/misc-utils - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

28

dist/mask.d.ts

@@ -21,2 +21,24 @@ /**

/**
* Create a mask function with pre-set parameters.
* @example
* const maskApiKey = masker(2, 2, 10);
* const maskedString = maskApiKey(myApiKey);
*
* @param keepLeft Number of characters on the left to be kept in the output without masking.
* Default value is 1.
* @param keepRight Number of characters on the right to be kept in the output without masking.
* Default value is 0.
* @param minLength Minimal length of the string for keepLeft and keepRight to be effective.
* If the input string is shorter than this length, the whole string would be masked.
* Default value is 3.
* @param maskLengthOrMaskString The string to be used for replacing the part in the input that needs to be masked,
* or the length of the mask string if a fixed length is desired,
* or null/undefined if the mask string should have the same length as the part to be masked.
* Default value is null.
* @param maskPattern The pattern to be repeated as the mask.
* Default value is '*'.
* @returns A mask function that has specified parameters as pre-set
*/
export declare function masker<T extends string | undefined | null = string>(keepLeft?: number, keepRight?: number, minLength?: number, maskLengthOrMaskString?: number | string | undefined | null, maskPattern?: string): (input: T) => T;
/**
* Mask sensitive information in an email address while keeping some information for troubleshooting

@@ -39,2 +61,8 @@ * @param email the email address which could also be null or undefined

export declare function maskAll<T extends string | undefined | null>(input: T): T;
/**
* Mask credit card number string
* @param input credit card number string which could also be null or undefined
* @returns Something like ****-****-****-1234, or null/undefined if the input is null/undefined
*/
export declare function maskCreditCard<T extends string | undefined | null>(input: T): T;
//# sourceMappingURL=mask.d.ts.map

39

dist/mask.js

@@ -5,3 +5,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.maskAll = exports.maskFullName = exports.maskEmail = exports.mask = void 0;
exports.maskCreditCard = exports.maskAll = exports.maskFullName = exports.maskEmail = exports.masker = exports.mask = void 0;
/**

@@ -49,2 +49,27 @@ * Mask the content of a string

/**
* Create a mask function with pre-set parameters.
* @example
* const maskApiKey = masker(2, 2, 10);
* const maskedString = maskApiKey(myApiKey);
*
* @param keepLeft Number of characters on the left to be kept in the output without masking.
* Default value is 1.
* @param keepRight Number of characters on the right to be kept in the output without masking.
* Default value is 0.
* @param minLength Minimal length of the string for keepLeft and keepRight to be effective.
* If the input string is shorter than this length, the whole string would be masked.
* Default value is 3.
* @param maskLengthOrMaskString The string to be used for replacing the part in the input that needs to be masked,
* or the length of the mask string if a fixed length is desired,
* or null/undefined if the mask string should have the same length as the part to be masked.
* Default value is null.
* @param maskPattern The pattern to be repeated as the mask.
* Default value is '*'.
* @returns A mask function that has specified parameters as pre-set
*/
function masker(keepLeft = 1, keepRight = 0, minLength = 3, maskLengthOrMaskString = null, maskPattern = '*') {
return input => mask(input, keepLeft, keepRight, minLength, maskLengthOrMaskString, maskPattern);
}
exports.masker = masker;
/**
* Mask sensitive information in an email address while keeping some information for troubleshooting

@@ -92,1 +117,13 @@ * @param email the email address which could also be null or undefined

exports.maskAll = maskAll;
/**
* Mask credit card number string
* @param input credit card number string which could also be null or undefined
* @returns Something like ****-****-****-1234, or null/undefined if the input is null/undefined
*/
function maskCreditCard(input) {
if (input == null) {
return input;
}
return '****-****-****-' + input.padStart(4, '*').slice(-4);
}
exports.maskCreditCard = maskCreditCard;

3

package.json
{
"name": "@handy-common-utils/misc-utils",
"version": "1.5.0",
"version": "1.5.1",
"description": "Miscellaneous utilities",

@@ -21,2 +21,3 @@ "scripts": {

"@types/node": "^16.11.12",
"fast-safe-stringify": "^2.1.1",
"log": "^6.3.1",

@@ -23,0 +24,0 @@ "safe-stable-stringify": "^2.4.3",

@@ -40,8 +40,8 @@ # @handy-common-utils/misc-utils

const masked = JSON.stringify(obj, pathBasedReplacer([
[/.*\.x-api-key$/, maskAll],
[/.*customer\.name$/, maskFullName],
[/.*customer\..*[eE]mail$/, maskEmail],
[/.*\.zip$/, (value: string) => value.slice(0, 3) + 'XX'],
[/.*\.cc$/, () => undefined],
[/.*\.ssn$/, mask],
[/(^|\.)x-api-key$/i, maskAll],
[/(^|\.)customer\.name$/i, maskFullName],
[/(^|\.)customer\..*[eE]mail$/i, maskEmail],
[/(^|\.)zip$/i, (value: string) => value.slice(0, 3) + 'XX'],
[/(^|\.)cc$/i, () => undefined],
[/(^|\.)ssn$/i, mask],
]));

@@ -112,3 +112,3 @@ ```

const replacer = pathBasedReplacer([
[/.*billing\.cc$/, maskCreditCard]
[/(^|\.)billing\.cc$/i, maskCreditCard]
]);

@@ -920,2 +920,8 @@

##### maskCreditCard
Re-exports [maskCreditCard](#maskcreditcard)
___
##### maskEmail

@@ -933,2 +939,8 @@

##### masker
Re-exports [masker](#masker)
___
##### pathAwareReplacer

@@ -1133,2 +1145,28 @@

##### maskCreditCard
▸ **maskCreditCard**<`T`\>(`input`): `T`
Mask credit card number string
###### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends `undefined` \| ``null`` \| `string` |
###### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `input` | `T` | credit card number string which could also be null or undefined |
###### Returns
`T`
Something like ****-****-****-1234, or null/undefined if the input is null/undefined
___
##### maskEmail

@@ -1184,3 +1222,52 @@

___
##### masker
▸ **masker**<`T`\>(`keepLeft?`, `keepRight?`, `minLength?`, `maskLengthOrMaskString?`, `maskPattern?`): (`input`: `T`) => `T`
Create a mask function with pre-set parameters.
**`Example`**
```ts
const maskApiKey = masker(2, 2, 10);
const maskedString = maskApiKey(myApiKey);
```
###### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends `undefined` \| ``null`` \| `string` = `string` |
###### Parameters
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `keepLeft` | `number` | `1` | Number of characters on the left to be kept in the output without masking. Default value is 1. |
| `keepRight` | `number` | `0` | Number of characters on the right to be kept in the output without masking. Default value is 0. |
| `minLength` | `number` | `3` | Minimal length of the string for keepLeft and keepRight to be effective. If the input string is shorter than this length, the whole string would be masked. Default value is 3. |
| `maskLengthOrMaskString` | `undefined` \| ``null`` \| `string` \| `number` | `null` | The string to be used for replacing the part in the input that needs to be masked, or the length of the mask string if a fixed length is desired, or null/undefined if the mask string should have the same length as the part to be masked. Default value is null. |
| `maskPattern` | `string` | `'*'` | The pattern to be repeated as the mask. Default value is '*'. |
###### Returns
`fn`
A mask function that has specified parameters as pre-set
▸ (`input`): `T`
####### Parameters
| Name | Type |
| :------ | :------ |
| `input` | `T` |
####### Returns
`T`
<a name="modulesstringify_replacermd"></a>

@@ -1187,0 +1274,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc