Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. // @flow
  2.  
  3. /* Reads HTML into a string */
  4. const readFromHtml = (templateName: string): string => {
  5. const pathToHtml = 'path/to/html';
  6. const file = fs.readFileSync(pathToHtml, 'utf8');
  7. return file;
  8. };
  9.  
  10. /* Creates function that defines parameters in string literal */
  11. const createTemplate = (stringLiteral: string, ...params: any): Function => {
  12. return new Function(params, 'return `' + stringLiteral + '`;');
  13. };
  14.  
  15. const htmlString = readFileHtml() // "Hello, my name is ${firstName} ${lastName}";
  16. const template = createTemplate(htmlString, 'firstName', 'lastName');
  17.  
  18. console.log(template('Brandon', 'Fujii')); // Hello, my name is Brandon Fujii
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement