Created
September 23, 2021 15:48
-
-
Save alexalannunes/e6a01cd60dc1509ce04993b02d97ace0 to your computer and use it in GitHub Desktop.
replace vars to value in some text
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 characters
| const vars = [{ | |
| name: '{CLIENTE_NOME}', | |
| value: 'Alex Alan Nunes' | |
| }, { | |
| name: '{DATA}', | |
| value: new Date().toLocaleString() | |
| }, { | |
| name: '{PERIODO}', | |
| value: 'manha' | |
| }]; | |
| let texto = "O cliente {CLIENTE_NOME} solicitou visitia na data {DATA} no período da {PERIODO}"; | |
| vars.forEach(({name, value}) => { | |
| const keyRegex = new RegExp(name, 'g') | |
| console.log(keyRegex) | |
| texto = texto.replace(keyRegex, value) | |
| }) | |
| texto; | |
| //'O cliente Alex Alan Nunes solicitou visitia na data 23/09/2021 12:46:07 no período da manha' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment