Last active
July 6, 2025 15:34
-
-
Save iki/18b2577d6a41b790cf9a92e23f397a43 to your computer and use it in GitHub Desktop.
Revisions
-
iki revised this gist
Jul 30, 2022 . 1 changed file with 9 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,19 @@ const hide = (s: string) => '*'.repeat(s.length); const hideEachSecondMatch = (_match: string, ...matches: string[]) => matches .slice(0, -2) .map((m, i) => (i % 2 ? hide(m) : m)) .join(''); // Hide all characters in email name, except first and last character // FIXME: Better hide at least one character for 1-2 character names const hideEmail = (email: string, options?: { domain?: boolean }) => email.replace( options?.domain ? /^(.?)(.*)(.@.)(.*)(\.[^.]+)$/ : /^(.)(.*)(.@.+)/, hideEachSecondMatch ); hideEmail('[email protected]', { domain: true }); // 'e@o******.com' hideEmail('[email protected]', { domain: true }); // 'em@o******.com' hideEmail('[email protected]', { domain: true }); // 'e*a@o******.com' hideEmail('[email protected]', { domain: true }); // 'e***l@o******.com' hideEmail('[email protected]'); // 'e***[email protected]' -
iki created this gist
Jul 29, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ const hide = (s: string) => '*'.repeat(s.length); const hideOddMatches = (_: string, ...matches: string[]) => matches .slice(0, -2) .map((m, i) => (i % 2 ? hide(m) : m)) .join(''); const hideEmail = (email: string, options?: { domain?: boolean }) => email.replace( options?.domain ? /^(.?)(.*)(.@.)(.*)(\.[^.]+)$/ : /^(.)(.*)(.@.+)/, hideOddMatches ); hideEmail('[email protected]'); // 'e***[email protected]' hideEmail('[email protected]', { domain: true }); // 'u***l@o******.com' hideEmail('[email protected]', { domain: true }); // 'e@o******.com'