@lidofinance/satanizer 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +35 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +35 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -4
package/dist/index.cjs
CHANGED
|
@@ -24,9 +24,14 @@ $parcel$export($6181fcac47f6fbd9$exports, "satanizer", () => $6181fcac47f6fbd9$e
|
|
|
24
24
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
|
|
25
25
|
const $6181fcac47f6fbd9$var$escapeRegExp = (string)=>string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
|
26
26
|
;
|
|
27
|
-
const $6181fcac47f6fbd9$var$patternToRegex = (pattern)
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const $6181fcac47f6fbd9$var$patternToRegex = (pattern)=>{
|
|
28
|
+
// Need to make regex global to work with matchAll
|
|
29
|
+
if (pattern == null) // regex which never matches anything
|
|
30
|
+
return /$a/g;
|
|
31
|
+
if (pattern instanceof RegExp) return new RegExp(pattern.source, "g");
|
|
32
|
+
return new RegExp($6181fcac47f6fbd9$var$escapeRegExp(pattern), "g");
|
|
33
|
+
};
|
|
34
|
+
const $6181fcac47f6fbd9$var$matchIndexes = (regex, input)=>Array.from(input.matchAll(regex)).filter((item)=>item != null)// Need to force types, because TS doesn't know it is the match
|
|
30
35
|
.map((match)=>[
|
|
31
36
|
match.index,
|
|
32
37
|
match.index + match[0].length
|
|
@@ -34,20 +39,33 @@ const $6181fcac47f6fbd9$var$matchIndexes = (regex, input)=>Array.from(input.matc
|
|
|
34
39
|
const $6181fcac47f6fbd9$var$getMask = (length)=>Array.from({
|
|
35
40
|
length: length
|
|
36
41
|
}).fill("*").join("");
|
|
37
|
-
const $6181fcac47f6fbd9$var$
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
const $6181fcac47f6fbd9$var$satanizerFactory = (patterns)=>(input)=>{
|
|
43
|
+
const visited = new Set();
|
|
44
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
45
|
+
const satanizeString = (target)=>patterns.map($6181fcac47f6fbd9$var$patternToRegex)// Need to find all indexes first, otherwise we may miss overlaps
|
|
46
|
+
.flatMap((regex)=>$6181fcac47f6fbd9$var$matchIndexes(regex, target))// Now it's safe to replace every match with the mask
|
|
47
|
+
.reduce((acc, [start, end])=>acc.slice(0, start) + $6181fcac47f6fbd9$var$getMask(end - start) + acc.slice(end), target);
|
|
48
|
+
const satanizeArray = (target)=>{
|
|
49
|
+
if (visited.has(target)) return "[Cycle]";
|
|
50
|
+
visited.add(target);
|
|
51
|
+
return target.map(satanize);
|
|
52
|
+
};
|
|
53
|
+
const satanizeObject = (target)=>{
|
|
54
|
+
if (visited.has(target)) return "[Cycle]";
|
|
55
|
+
visited.add(target);
|
|
56
|
+
return Object.getOwnPropertyNames(target).reduce((acc, key)=>({
|
|
57
|
+
...acc,
|
|
58
|
+
[satanize(key)]: satanize(target[key])
|
|
59
|
+
}), {});
|
|
60
|
+
};
|
|
61
|
+
const satanize = (target)=>{
|
|
62
|
+
if (typeof target === "string") return satanizeString(target);
|
|
63
|
+
if (typeof target === "number" || typeof target === "boolean" || target == null) return target;
|
|
64
|
+
if (Array.isArray(target)) return satanizeArray(target);
|
|
65
|
+
if (typeof target === "object") return satanizeObject(target);
|
|
66
|
+
return target;
|
|
67
|
+
};
|
|
68
|
+
return satanize(input);
|
|
51
69
|
};
|
|
52
70
|
function $6181fcac47f6fbd9$export$4aabe16cd431674e(patterns, ...args) {
|
|
53
71
|
if (args.length === 1) return $6181fcac47f6fbd9$var$satanizerFactory(patterns)(args[0]);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;ACAA,wDAAwD;AACxD,6FAA6F;AAC7F,MAAM,qCAAe,CAAC,SAA2B,OAAO,OAAO,CAAC,uBAAuB,QAAQ,oCAAoC;;AAInI,MAAM,uCAAiB,CAAC,UAA6B;IACnD,kDAAkD;IAClD,IAAI,WAAW,IAAI,EACjB,qCAAqC;IACrC,OAAO;IAET,IAAI,mBAAmB,QACrB,OAAO,IAAI,OAAO,QAAQ,MAAM,EAAE;IAEpC,OAAO,IAAI,OAAO,mCAAa,UAAU;AAC3C;AAEA,MAAM,qCAAe,CAAC,OAAe,QACnC,MAAM,IAAI,CAAC,MAAM,QAAQ,CAAC,QACvB,MAAM,CAAC,CAAC,OAAS,QAAQ,IAAI,CAC9B,+DAA+D;KAC9D,GAAG,CAAC,CAAC,QAAU;YAAC,MAAM,KAAK;YAAa,MAAM,KAAK,GAAc,KAAK,CAAC,EAAE,CAAC,MAAM;SAAC;AAEtF,MAAM,gCAAU,CAAC,SAAmB,MAAM,IAAI,CAAC;gBAAE;IAAO,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;AAE1E,MAAM,yCAAmB,CAAC,WAAwB,CAAC,QAAmB;QACpE,MAAM,UAAU,IAAI;QAEpB,+DAA+D;QAC/D,MAAM,iBAAiB,CAAC,SACtB,SACG,GAAG,CAAC,qCACL,iEAAiE;aAChE,OAAO,CAAC,CAAC,QAAU,mCAAa,OAAO,QACxC,qDAAqD;aACpD,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,GAAK,IAAI,KAAK,CAAC,GAAG,SAAS,8BAAQ,MAAM,SAAS,IAAI,KAAK,CAAC,MAAM;QAEhG,MAAM,gBAAgB,CAAI,SAA8B;YACtD,IAAI,QAAQ,GAAG,CAAC,SACd,OAAO;YAET,QAAQ,GAAG,CAAC;YACZ,OAAO,OAAO,GAAG,CAAC;QACpB;QAEA,MAAM,iBAAiB,CAAmB,SAA0B;YAClE,IAAI,QAAQ,GAAG,CAAC,SACd,OAAO;YAET,QAAQ,GAAG,CAAC;YACZ,OAAO,OAAO,mBAAmB,CAAC,QAAQ,MAAM,CAC9C,CAAC,KAAK,MAAS,CAAA;oBAAE,GAAG,GAAG;oBAAE,CAAC,SAAS,KAAK,EAAE,SAAS,MAAM,CAAC,IAAe;gBAAE,CAAA,GAC3E,CAAC;QAEL;QAEA,MAAM,WAAW,CAAI,SAAiB;YACpC,IAAI,OAAO,WAAW,UACpB,OAAO,eAAe;YAExB,IAAI,OAAO,WAAW,YAAY,OAAO,WAAW,aAAa,UAAU,IAAI,EAC7E,OAAO;YAET,IAAI,MAAM,OAAO,CAAC,SAChB,OAAO,cAAc;YAEvB,IAAI,OAAO,WAAW,UACpB,OAAO,eAAe;YAExB,OAAO;QACT;QAEA,OAAO,SAAS;IAClB;AAKO,SAAS,0CAAa,QAAmB,EAAE,GAAG,IAAc,EAAE;IACnE,IAAI,KAAK,MAAM,KAAK,GAClB,OAAO,uCAAiB,UAAU,IAAI,CAAC,EAAE;IAE3C,OAAO,uCAAiB;AAC1B;;ADpFA;;;;;;;;AEAA,sDAAsD;AAC/C,MAAM,2CAAoB;AAC1B,MAAM,4CAAa;AAEnB,MAAM,4CAAY;AAClB,MAAM,4CAAa;AAEnB,MAAM,4CAAiB;IAAC;IAAmB;IAAY;IAAW;CAAW;","sources":["packages/core/satanazier/src/index.ts","packages/core/satanazier/src/satanizer.ts","packages/core/satanazier/src/common-patterns.ts"],"sourcesContent":["export * from './satanizer'\nexport * from './common-patterns'\n","// Escape string to be safely used in RegExp constructor\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\nconst escapeRegExp = (string: string): string => string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&') // $& means the whole matched string\n\nexport type Pattern = RegExp | string | null | undefined\n\nconst patternToRegex = (pattern: Pattern): RegExp => {\n // Need to make regex global to work with matchAll\n if (pattern == null) {\n // regex which never matches anything\n return /$a/g\n }\n if (pattern instanceof RegExp) {\n return new RegExp(pattern.source, 'g')\n }\n return new RegExp(escapeRegExp(pattern), 'g')\n}\n\nconst matchIndexes = (regex: RegExp, input: string) =>\n Array.from(input.matchAll(regex))\n .filter((item) => item != null)\n // Need to force types, because TS doesn't know it is the match\n .map((match) => [match.index as number, (match.index as number) + match[0].length])\n\nconst getMask = (length: number) => Array.from({ length }).fill('*').join('')\n\nconst satanizerFactory = (patterns: Pattern[]) => (input: unknown) => {\n const visited = new Set<unknown>()\n\n // eslint-disable-next-line unicorn/consistent-function-scoping\n const satanizeString = (target: string) =>\n patterns\n .map(patternToRegex)\n // Need to find all indexes first, otherwise we may miss overlaps\n .flatMap((regex) => matchIndexes(regex, target))\n // Now it's safe to replace every match with the mask\n .reduce((acc, [start, end]) => acc.slice(0, start) + getMask(end - start) + acc.slice(end), target)\n\n const satanizeArray = <T>(target: T[]): T[] | string => {\n if (visited.has(target)) {\n return '[Cycle]'\n }\n visited.add(target)\n return target.map(satanize)\n }\n\n const satanizeObject = <T extends object>(target: T): T | string => {\n if (visited.has(target)) {\n return '[Cycle]'\n }\n visited.add(target)\n return Object.getOwnPropertyNames(target).reduce(\n (acc, key) => ({ ...acc, [satanize(key)]: satanize(target[key as keyof T]) }),\n {} as T,\n )\n }\n\n const satanize = <T>(target: T): T => {\n if (typeof target === 'string') {\n return satanizeString(target) as T\n }\n if (typeof target === 'number' || typeof target === 'boolean' || target == null) {\n return target\n }\n if (Array.isArray(target)) {\n return satanizeArray(target) as T\n }\n if (typeof target === 'object') {\n return satanizeObject(target) as T\n }\n return target\n }\n\n return satanize(input)\n}\n\n// Overload type definition to accept both types of call.\nexport function satanizer<T>(pattern: Pattern[]): (input: T) => T // this is a bit incorrect since we don't perserve methods\nexport function satanizer<T>(pattern: Pattern[], input: T): T\nexport function satanizer<T>(patterns: Pattern[], ...args: [] | [T]) {\n if (args.length === 1) {\n return satanizerFactory(patterns)(args[0])\n }\n return satanizerFactory(patterns)\n}\n","// May caught ids, maybe needs to test this a bit more\nexport const blockchainAddress = /(0x)?[a-zA-Z0-9]{40,}/\nexport const ensAddress = /[a-zA-Z0-9.]+\\.eth/\n// It's not really valid, but it's still ok for secrets\nexport const ipAddress = /\\d+\\.\\d+\\.\\d+\\.\\d+/\nexport const macAddress = /([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})/\n\nexport const commonPatterns = [blockchainAddress, ensAddress, ipAddress, macAddress]\n"],"names":[],"version":3,"file":"index.cjs.map","sourceRoot":"../../../../"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export function satanizer<T>(pattern: Pattern[]): (input: T) => OmitFunctions<T>;
|
|
5
|
-
export function satanizer<T>(pattern: Pattern[], input: T): OmitFunctions<T>;
|
|
1
|
+
export type Pattern = RegExp | string | null | undefined;
|
|
2
|
+
export function satanizer<T>(pattern: Pattern[]): (input: T) => T;
|
|
3
|
+
export function satanizer<T>(pattern: Pattern[], input: T): T;
|
|
6
4
|
export const blockchainAddress: RegExp;
|
|
7
5
|
export const ensAddress: RegExp;
|
|
8
6
|
export const ipAddress: RegExp;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AAIA,sBAAsB,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;AAyExD,0BAA0B,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAA;AACjE,0BAA0B,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAA;AC7E7D,OAAO,MAAM,yBAA2C,CAAA;AACxD,OAAO,MAAM,kBAAiC,CAAA;AAE9C,OAAO,MAAM,iBAAgC,CAAA;AAC7C,OAAO,MAAM,kBAAsD,CAAA;AAEnE,OAAO,MAAM,wBAAuE,CAAA","sources":["packages/core/satanazier/src/src/satanizer.ts","packages/core/satanazier/src/src/common-patterns.ts","packages/core/satanazier/src/src/index.ts","packages/core/satanazier/src/index.ts"],"sourcesContent":[null,null,null,"export * from './satanizer'\nexport * from './common-patterns'\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../../../"}
|
package/dist/index.mjs
CHANGED
|
@@ -8,9 +8,14 @@ $parcel$export($634bfa66b85378ba$exports, "satanizer", () => $634bfa66b85378ba$e
|
|
|
8
8
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
|
|
9
9
|
const $634bfa66b85378ba$var$escapeRegExp = (string)=>string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
|
10
10
|
;
|
|
11
|
-
const $634bfa66b85378ba$var$patternToRegex = (pattern)
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const $634bfa66b85378ba$var$patternToRegex = (pattern)=>{
|
|
12
|
+
// Need to make regex global to work with matchAll
|
|
13
|
+
if (pattern == null) // regex which never matches anything
|
|
14
|
+
return /$a/g;
|
|
15
|
+
if (pattern instanceof RegExp) return new RegExp(pattern.source, "g");
|
|
16
|
+
return new RegExp($634bfa66b85378ba$var$escapeRegExp(pattern), "g");
|
|
17
|
+
};
|
|
18
|
+
const $634bfa66b85378ba$var$matchIndexes = (regex, input)=>Array.from(input.matchAll(regex)).filter((item)=>item != null)// Need to force types, because TS doesn't know it is the match
|
|
14
19
|
.map((match)=>[
|
|
15
20
|
match.index,
|
|
16
21
|
match.index + match[0].length
|
|
@@ -18,20 +23,33 @@ const $634bfa66b85378ba$var$matchIndexes = (regex, input)=>Array.from(input.matc
|
|
|
18
23
|
const $634bfa66b85378ba$var$getMask = (length)=>Array.from({
|
|
19
24
|
length: length
|
|
20
25
|
}).fill("*").join("");
|
|
21
|
-
const $634bfa66b85378ba$var$
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
const $634bfa66b85378ba$var$satanizerFactory = (patterns)=>(input)=>{
|
|
27
|
+
const visited = new Set();
|
|
28
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
29
|
+
const satanizeString = (target)=>patterns.map($634bfa66b85378ba$var$patternToRegex)// Need to find all indexes first, otherwise we may miss overlaps
|
|
30
|
+
.flatMap((regex)=>$634bfa66b85378ba$var$matchIndexes(regex, target))// Now it's safe to replace every match with the mask
|
|
31
|
+
.reduce((acc, [start, end])=>acc.slice(0, start) + $634bfa66b85378ba$var$getMask(end - start) + acc.slice(end), target);
|
|
32
|
+
const satanizeArray = (target)=>{
|
|
33
|
+
if (visited.has(target)) return "[Cycle]";
|
|
34
|
+
visited.add(target);
|
|
35
|
+
return target.map(satanize);
|
|
36
|
+
};
|
|
37
|
+
const satanizeObject = (target)=>{
|
|
38
|
+
if (visited.has(target)) return "[Cycle]";
|
|
39
|
+
visited.add(target);
|
|
40
|
+
return Object.getOwnPropertyNames(target).reduce((acc, key)=>({
|
|
41
|
+
...acc,
|
|
42
|
+
[satanize(key)]: satanize(target[key])
|
|
43
|
+
}), {});
|
|
44
|
+
};
|
|
45
|
+
const satanize = (target)=>{
|
|
46
|
+
if (typeof target === "string") return satanizeString(target);
|
|
47
|
+
if (typeof target === "number" || typeof target === "boolean" || target == null) return target;
|
|
48
|
+
if (Array.isArray(target)) return satanizeArray(target);
|
|
49
|
+
if (typeof target === "object") return satanizeObject(target);
|
|
50
|
+
return target;
|
|
51
|
+
};
|
|
52
|
+
return satanize(input);
|
|
35
53
|
};
|
|
36
54
|
function $634bfa66b85378ba$export$4aabe16cd431674e(patterns, ...args) {
|
|
37
55
|
if (args.length === 1) return $634bfa66b85378ba$var$satanizerFactory(patterns)(args[0]);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;
|
|
1
|
+
{"mappings":";;;;;;ACAA,wDAAwD;AACxD,6FAA6F;AAC7F,MAAM,qCAAe,CAAC,SAA2B,OAAO,OAAO,CAAC,uBAAuB,QAAQ,oCAAoC;;AAInI,MAAM,uCAAiB,CAAC,UAA6B;IACnD,kDAAkD;IAClD,IAAI,WAAW,IAAI,EACjB,qCAAqC;IACrC,OAAO;IAET,IAAI,mBAAmB,QACrB,OAAO,IAAI,OAAO,QAAQ,MAAM,EAAE;IAEpC,OAAO,IAAI,OAAO,mCAAa,UAAU;AAC3C;AAEA,MAAM,qCAAe,CAAC,OAAe,QACnC,MAAM,IAAI,CAAC,MAAM,QAAQ,CAAC,QACvB,MAAM,CAAC,CAAC,OAAS,QAAQ,IAAI,CAC9B,+DAA+D;KAC9D,GAAG,CAAC,CAAC,QAAU;YAAC,MAAM,KAAK;YAAa,MAAM,KAAK,GAAc,KAAK,CAAC,EAAE,CAAC,MAAM;SAAC;AAEtF,MAAM,gCAAU,CAAC,SAAmB,MAAM,IAAI,CAAC;gBAAE;IAAO,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;AAE1E,MAAM,yCAAmB,CAAC,WAAwB,CAAC,QAAmB;QACpE,MAAM,UAAU,IAAI;QAEpB,+DAA+D;QAC/D,MAAM,iBAAiB,CAAC,SACtB,SACG,GAAG,CAAC,qCACL,iEAAiE;aAChE,OAAO,CAAC,CAAC,QAAU,mCAAa,OAAO,QACxC,qDAAqD;aACpD,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,GAAK,IAAI,KAAK,CAAC,GAAG,SAAS,8BAAQ,MAAM,SAAS,IAAI,KAAK,CAAC,MAAM;QAEhG,MAAM,gBAAgB,CAAI,SAA8B;YACtD,IAAI,QAAQ,GAAG,CAAC,SACd,OAAO;YAET,QAAQ,GAAG,CAAC;YACZ,OAAO,OAAO,GAAG,CAAC;QACpB;QAEA,MAAM,iBAAiB,CAAmB,SAA0B;YAClE,IAAI,QAAQ,GAAG,CAAC,SACd,OAAO;YAET,QAAQ,GAAG,CAAC;YACZ,OAAO,OAAO,mBAAmB,CAAC,QAAQ,MAAM,CAC9C,CAAC,KAAK,MAAS,CAAA;oBAAE,GAAG,GAAG;oBAAE,CAAC,SAAS,KAAK,EAAE,SAAS,MAAM,CAAC,IAAe;gBAAE,CAAA,GAC3E,CAAC;QAEL;QAEA,MAAM,WAAW,CAAI,SAAiB;YACpC,IAAI,OAAO,WAAW,UACpB,OAAO,eAAe;YAExB,IAAI,OAAO,WAAW,YAAY,OAAO,WAAW,aAAa,UAAU,IAAI,EAC7E,OAAO;YAET,IAAI,MAAM,OAAO,CAAC,SAChB,OAAO,cAAc;YAEvB,IAAI,OAAO,WAAW,UACpB,OAAO,eAAe;YAExB,OAAO;QACT;QAEA,OAAO,SAAS;IAClB;AAKO,SAAS,0CAAa,QAAmB,EAAE,GAAG,IAAc,EAAE;IACnE,IAAI,KAAK,MAAM,KAAK,GAClB,OAAO,uCAAiB,UAAU,IAAI,CAAC,EAAE;IAE3C,OAAO,uCAAiB;AAC1B;;ADpFA;;;;;;;;AEAA,sDAAsD;AAC/C,MAAM,2CAAoB;AAC1B,MAAM,4CAAa;AAEnB,MAAM,4CAAY;AAClB,MAAM,4CAAa;AAEnB,MAAM,4CAAiB;IAAC;IAAmB;IAAY;IAAW;CAAW;","sources":["packages/core/satanazier/src/index.ts","packages/core/satanazier/src/satanizer.ts","packages/core/satanazier/src/common-patterns.ts"],"sourcesContent":["export * from './satanizer'\nexport * from './common-patterns'\n","// Escape string to be safely used in RegExp constructor\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\nconst escapeRegExp = (string: string): string => string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&') // $& means the whole matched string\n\nexport type Pattern = RegExp | string | null | undefined\n\nconst patternToRegex = (pattern: Pattern): RegExp => {\n // Need to make regex global to work with matchAll\n if (pattern == null) {\n // regex which never matches anything\n return /$a/g\n }\n if (pattern instanceof RegExp) {\n return new RegExp(pattern.source, 'g')\n }\n return new RegExp(escapeRegExp(pattern), 'g')\n}\n\nconst matchIndexes = (regex: RegExp, input: string) =>\n Array.from(input.matchAll(regex))\n .filter((item) => item != null)\n // Need to force types, because TS doesn't know it is the match\n .map((match) => [match.index as number, (match.index as number) + match[0].length])\n\nconst getMask = (length: number) => Array.from({ length }).fill('*').join('')\n\nconst satanizerFactory = (patterns: Pattern[]) => (input: unknown) => {\n const visited = new Set<unknown>()\n\n // eslint-disable-next-line unicorn/consistent-function-scoping\n const satanizeString = (target: string) =>\n patterns\n .map(patternToRegex)\n // Need to find all indexes first, otherwise we may miss overlaps\n .flatMap((regex) => matchIndexes(regex, target))\n // Now it's safe to replace every match with the mask\n .reduce((acc, [start, end]) => acc.slice(0, start) + getMask(end - start) + acc.slice(end), target)\n\n const satanizeArray = <T>(target: T[]): T[] | string => {\n if (visited.has(target)) {\n return '[Cycle]'\n }\n visited.add(target)\n return target.map(satanize)\n }\n\n const satanizeObject = <T extends object>(target: T): T | string => {\n if (visited.has(target)) {\n return '[Cycle]'\n }\n visited.add(target)\n return Object.getOwnPropertyNames(target).reduce(\n (acc, key) => ({ ...acc, [satanize(key)]: satanize(target[key as keyof T]) }),\n {} as T,\n )\n }\n\n const satanize = <T>(target: T): T => {\n if (typeof target === 'string') {\n return satanizeString(target) as T\n }\n if (typeof target === 'number' || typeof target === 'boolean' || target == null) {\n return target\n }\n if (Array.isArray(target)) {\n return satanizeArray(target) as T\n }\n if (typeof target === 'object') {\n return satanizeObject(target) as T\n }\n return target\n }\n\n return satanize(input)\n}\n\n// Overload type definition to accept both types of call.\nexport function satanizer<T>(pattern: Pattern[]): (input: T) => T // this is a bit incorrect since we don't perserve methods\nexport function satanizer<T>(pattern: Pattern[], input: T): T\nexport function satanizer<T>(patterns: Pattern[], ...args: [] | [T]) {\n if (args.length === 1) {\n return satanizerFactory(patterns)(args[0])\n }\n return satanizerFactory(patterns)\n}\n","// May caught ids, maybe needs to test this a bit more\nexport const blockchainAddress = /(0x)?[a-zA-Z0-9]{40,}/\nexport const ensAddress = /[a-zA-Z0-9.]+\\.eth/\n// It's not really valid, but it's still ok for secrets\nexport const ipAddress = /\\d+\\.\\d+\\.\\d+\\.\\d+/\nexport const macAddress = /([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})/\n\nexport const commonPatterns = [blockchainAddress, ensAddress, ipAddress, macAddress]\n"],"names":[],"version":3,"file":"index.mjs.map","sourceRoot":"../../../../"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Tool, which mask secrets",
|
|
4
4
|
"repository": "git@github.com:lidofinance/warehouse.git",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.28.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -19,15 +19,14 @@
|
|
|
19
19
|
"lint": "eslint . && prettier --check src",
|
|
20
20
|
"lint:fix": "eslint --fix . && prettier --check src --write",
|
|
21
21
|
"types": "tsc --noEmit",
|
|
22
|
-
"test": "jest
|
|
22
|
+
"test": "jest"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@lidofinance/config-prettier": "~0.
|
|
25
|
+
"@lidofinance/config-prettier": "~0.28.0",
|
|
26
26
|
"@types/jest": "^29.2.4",
|
|
27
27
|
"@types/node": "^18.11.17",
|
|
28
28
|
"jest": "^29.3.1",
|
|
29
29
|
"ts-jest": "^29.0.3",
|
|
30
|
-
"tsd": "^0.25.0",
|
|
31
30
|
"typescript": "4.9"
|
|
32
31
|
}
|
|
33
32
|
}
|