{"id":300573,"date":"2020-03-23T09:00:26","date_gmt":"2020-03-23T09:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=300573"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=300573","title":{"rendered":"\u0421\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0447\u0430\u0441\u0442\u044c \u043d\u043e\u043c\u0435\u0440\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/493598\/\">\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u0440\u044b\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u043d\u043e\u043c\u0435\u0440 \u043f\u043e\u0434 \u0437\u0432\u0435\u0437\u0434\u043e\u0447\u043a\u0430\u043c\u0438. \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c +79999999999 \u043d\u0430 +799****9999 \u043d\u0435 \u0442\u0440\u0443\u0434\u043d\u043e, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043c\u0430\u0441\u043e\u043a \u043d\u043e\u043c\u0435\u0440\u043e\u0432 \u043d\u0435 \u043e\u0434\u043d\u0430, \u0430 \u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u043d\u043e\u043c\u0435\u0440\u0430 \u044d\u0442\u0438 \u043a\u0430\u043a \u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u0435, \u0442\u0430\u043a \u0438 \u043a\u0430\u043d\u0430\u0434\u0441\u043a\u0438\u0435 \u0438\u043b\u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435. \u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u043e\u043c\u0435\u0440\u043e\u0432.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430:<\/p>\n<blockquote><p>\/^(\\(?\\+?\\d{1,2}\\)? ?\\(?\\d{1,3}\\)? ?\\d+\\-? ?\\d+\\-? ?\\d+)$\/<\/p><\/blockquote>\n<p>  \u041a\u0443\u0448\u0430\u0435\u0442:<\/p>\n<pre><code class=\"plaintext\">'+7 999 999-99-99', '+79999999999', '79999999999', '+7 (495) 150 41-32', '+55 11 99999-5555', '(+44) 0848 9123 456', '+1 284 852 5500', '+1 345 9490088', '+32 2 702-9200', '+65 6511 9266', '+86 21 2230 1000', '(123) 456 7899', '123-456-7899', '123 456 7899', '1234567899', '1 800 5551212', '800 555 1212', '8005551212', '18005551212', '234-911-5678', '+54 9 2982 123456', '02982 15 123456', '(719) 309-3829' <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043c\u0435\u043d\u044b:<\/p>\n<pre><code class=\"javascript\">function hideNumber(string, replaceTo = '*', elemsHide = 4, sliceFromback = 4) {     result = string.match(\/^(\\(?\\+?\\d{1,2}\\)? ?\\(?\\d{1,3}\\)? ?\\d+\\-? ?\\d+\\-? ?\\d+)$\/);     if (result !== null) {           \/\/ \u0442\u0443\u0442 \u043c\u044b \u0432\u044b\u0434\u0435\u0440\u0433\u0438\u0432\u0430\u0435\u043c n \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0441\u0440\u0435\u0437\u0430 x         const regex = new RegExp(`((\\\\(?\\\\ ?\\\\-?\\\\d\\\\ ?\\\\-?\\\\)?){${elemsHide}})((\\\\ ?\\\\-?\\\\d\\\\ ?\\\\-?){${sliceFromback}}$)`, 'gm');          let m;         while ((m = regex.exec(string)) !== null) {             if (m.index === regex.lastIndex) {                 regex.lastIndex++;             }              const forRex = m[1];             const str = m[1].replace(\/(\\d)\/gm, replaceTo);             const lasts = m[3];             const full = string;             const noBack = full.slice(0, -lasts.length).slice(0, -forRex.length);             const out = noBack+''+str+''+lasts;             return out;         }         return string;     } else {         return string;     } } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u043c\u043e<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">const str = [     '+7 999 999-99-99',     '+79999999999',     '79999999999',     '+7 (495) 150 41-32',     '+55 11 99999-5555',     '(+44) 0848 9123 456',     '+1 284 852 5500',     '+1 345 9490088',     '+32 2 702-9200',     '+65 6511 9266',     '+86 21 2230 1000',     '(123) 456 7899',     '123-456-7899',     '123 456 7899',     '1234567899',     '1 800 5551212',     '800 555 1212',     '8005551212',     '18005551212',     '234-911-5678',     '+54 9 2982 123456',     '02982 15 123456',     '(719) 309-3829',     'Judi' ];   str.forEach(i =&gt; {     console.log(i +' =&gt; '+hideNumber(i)); }) <\/code><\/pre>\n<p>  console:<\/p>\n<pre><code class=\"plaintext\">+7 999 999-99-99 =&gt; +7 99* ***-99-99 +79999999999 =&gt; +799****9999 79999999999 =&gt; 799****9999 +7 (495) 150 41-32 =&gt; +7 (49*) *** 41-32 +55 11 99999-5555 =&gt; +55 11 9****-5555 (+44) 0848 9123 456 =&gt; (+44) 084* ***3 456 +1 284 852 5500 =&gt; +1 28* *** 5500 +1 345 9490088 =&gt; +1 34* ***0088 +32 2 702-9200 =&gt; +32 * ***-9200 +65 6511 9266 =&gt; +65 **** 9266 +86 21 2230 1000 =&gt; +86 21 **** 1000 (123) 456 7899 =&gt; (12*) *** 7899 123-456-7899 =&gt; 12*-***-7899 123 456 7899 =&gt; 12* *** 7899 1234567899 =&gt; 12****7899 1 800 5551212 =&gt; 1 80* ***1212 800 555 1212 =&gt; 80* *** 1212 8005551212 =&gt; 80****1212 18005551212 =&gt; 180****1212 234-911-5678 =&gt; 23*-***-5678 +54 9 2982 123456 =&gt; +54 9 29** **3456 02982 15 123456 =&gt; 02982 ** **3456 (719) 309-3829 =&gt; (71*) ***-3829 Judi =&gt; Judi  <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0415\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0448\u0438\u0445 \u043d\u043e\u043c\u0435\u0440\u043e\u0432 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0433 \u0431\u044b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0434\u0435\u043b\u0435) \u043d\u0435 \u043f\u043e\u0434\u043e\u0448\u0435\u043b, \u043f\u0438\u0448\u0438\u0442\u0435, \u0434\u043e\u043f\u043e\u043b\u043d\u044e.<\/p>\n<h4>P.S.<\/h4>\n<p>  \u0412 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 <a href=\"https:\/\/habr.com\/ru\/users\/mwizard\/\" class=\"user_link\">mwizard<\/a> \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0431\u0435\u0437 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043a\u0438:<\/p>\n<pre><code class=\"javascript\">type Context = {     readonly offset: number;     readonly filtered: string; }  function hidePhone(phone: string): string {     return Array.from(phone).reduceRight((ctx: Context, char: string): Context =&gt; {         const isDigit = char &gt;= '0' &amp;&amp; char &lt;= '9';         const offset = ctx.offset + (isDigit ? 1 : 0);         const filteredChar = isDigit ? (offset &gt;= 4 &amp;&amp; offset &lt; 8) ? '*' : char : char;         const filtered = filteredChar + ctx.filtered;         return { offset, filtered };     }, { offset: -1, filtered: '' }).filtered; } <\/code><\/pre>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/493598\/\"> https:\/\/habr.com\/ru\/post\/493598\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/493598\/\">\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u0440\u044b\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u043d\u043e\u043c\u0435\u0440 \u043f\u043e\u0434 \u0437\u0432\u0435\u0437\u0434\u043e\u0447\u043a\u0430\u043c\u0438. \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c +79999999999 \u043d\u0430 +799****9999 \u043d\u0435 \u0442\u0440\u0443\u0434\u043d\u043e, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043c\u0430\u0441\u043e\u043a \u043d\u043e\u043c\u0435\u0440\u043e\u0432 \u043d\u0435 \u043e\u0434\u043d\u0430, \u0430 \u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u043d\u043e\u043c\u0435\u0440\u0430 \u044d\u0442\u0438 \u043a\u0430\u043a \u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u0435, \u0442\u0430\u043a \u0438 \u043a\u0430\u043d\u0430\u0434\u0441\u043a\u0438\u0435 \u0438\u043b\u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435. \u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u043e\u043c\u0435\u0440\u043e\u0432.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-300573","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=300573"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300573\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}