1 | export type Index<T> = {[key: string]: T}
|
2 | export type Option<T> = T | undefined;
|
3 |
|
4 | export function map<A, B>(a: Option<A>, f: (a: A) => B): Option<B> {
|
5 | return a ? f(a) : undefined;
|
6 | }
|
7 |
|
8 | export function flatMap<A, B>(a: Option<A>, f: (a: A) => Option<B>): Option<B> {
|
9 | return a ? f(a) : undefined;
|
10 | }
|
11 |
|
12 | export function getOrElse<T>(t: Option<T>, _default: T): T {
|
13 | return t ? t : _default;
|
14 | }
|
15 |
|
16 | export function obfuscateString(rawString?: string): string | undefined {
|
17 | if (!rawString) return undefined;
|
18 | const stringLength = rawString.length;
|
19 | if (stringLength === 0) return '';
|
20 | else {
|
21 | const clearSize = Math.floor(0.3 * stringLength);
|
22 | const clear = rawString.substring(0, clearSize);
|
23 | const obfuscated = 'X'.repeat(stringLength - clearSize);
|
24 | return clear + obfuscated;
|
25 | }
|
26 | } |
\ | No newline at end of file |