AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 01.09.2021, 02:32   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
crmtipoftheday: Tip #1410: 50 Shades of Regex
Источник: https://crmtipoftheday.com/1410/50-s...hades-of-regex
==============

I usually don’t drool over code but this one is just way too elegant for me not to. StackEdit – In-browser Markdown editor is an awesome app for markdown editing. One of the standout features is ability to comment and review – something sorely missing from the standard markdown. StackEdit very cleverly serializes reviews and notes as a base64 string and inserts it at the end of the document using HTML comment . As part of the exercise this comment is saved very tidily in a 50 char wide column. So how does one wrap a string at a fixed width? This is the genius line:

const serializedData = utils.encodeBase64(JSON.stringify(data)) .replace(/(.{50})/g, '$1\n');
What does it do?
  • utils.encodeBase64(JSON.stringify(data)) – take our data object, serialize it to string, then convert to base64 to make sure it’s printable
  • replace – that’s just replace one thing with another
  • (.{50}) – a group of 50 characters
  • /g – global, i.e. do not stop after the match
  • '$1\n' – replace those groups of 50 characters with themselves plus newlines
Is that a brilliant piece of code or what?
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
crmtipoftheday: Tip #1407: How to secure Power Apps portal from making the news Blog bot Dynamics CRM: Blogs 0 24.08.2021 18:13
crmtipoftheday: Tip #1402: Why you should not use Microsoft Lists/SharePoint Lists for business-critical Power Apps Blog bot Dynamics CRM: Blogs 0 17.02.2021 15:12
crmtipoftheday: Tip #1103: Chart styling cheat sheet Blog bot Dynamics CRM: Blogs 0 08.04.2018 03:03
crmtipoftheday: Tip #1095: Add percentage labels to pie charts Blog bot Dynamics CRM: Blogs 0 02.04.2018 04:16
crmtipoftheday: Tip #1060: Quickly create vector/SVG images for Dynamics 365 Blog bot Dynamics CRM: Blogs 0 24.01.2018 22:11
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 16:29.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.