react-code-dataset / spectrum /api /migrations /20171005075445-remove-markdown-links-from-messages.js
Download spectrum/api/migrations/20171005075445-remove-markdown-links-from-messages.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 836 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/migrations/20171005075445-remove-markdown-links-from-messages.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/migrations/20171005075445-remove-markdown-links-from-messages.js
-
curl -L -o 20171005075445-remove-markdown-links-from-messages.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/migrations/20171005075445-remove-markdown-links-from-messages.js
836 Bytes
| const replace = require('string-replace-to-array'); | |
| const MARKDOWN_LINK = /(?:\[(.*?)\]\((.*?)\))/g; | |
| const removeMarkdownLinks = text => { | |
| if (!text || typeof text !== 'string') return text; | |
| return replace(text, MARKDOWN_LINK, (fullLink, text, url) => url).join(''); | |
| }; | |
| exports.up = function(r, conn) { | |
| return r | |
| .table('messages') | |
| .withFields('id', 'content') | |
| .run(conn) | |
| .then(cursor => cursor.toArray()) | |
| .then(messages => | |
| Promise.all( | |
| messages.map(message => | |
| r | |
| .table('messages') | |
| .get(message.id) | |
| .update({ | |
| content: { | |
| body: removeMarkdownLinks(message.content.body), | |
| }, | |
| }) | |
| .run(conn) | |
| ) | |
| ) | |
| ); | |
| }; | |
| exports.down = function(r, conn) { | |
| return Promise.resolve(); | |
| }; | |