UNPKG

vvlad1973-telegram-framework

Version:
65 lines (45 loc) 1.4 kB
# Filler object There is an object called Filler which is used to generate text strings from templates by substituting values from a pool of string resources and parameters. Example of use template string without parameters: ```javascript import Filler from 'vvlad1973-telegram-framework'; let params = {}, strings = { SOME_STRING: 'Some result text' }; const filler = Filler(params, strings) let result = filler.completeText('@SOME_STRING') // result = "Some result text" ``` Example of template string with parameters: ```javascript import Filler from 'vvlad1973-telegram-framework'; let params = { name: 'Jack' }, strings = { HELLO: 'Hi, %s!' }; const filler = Filler(params, strings) let result = filler.completeText('@HELLO:[@name]') // result = 'Hi, Jack!' ``` Example of template string with regular expression and parameters: ```javascript import Filler from 'vvlad1973-telegram-framework'; let params = { name: 'Jack' }, strings = { HELLO_1: 'Hi, %s!', HELLO_2: 'Hola, %s!', HELLO_3: 'Guten tag, %s!', HELLO_4: 'Привет, %s!', }; const filler = Filler(params, strings) let result = filler.completeText('@/^HELLO_\\d+/:[@name]') // result is random of 'Hi, Jack!', 'Hola, Jack!' etc. ```