Advertisement
Tokumei_No_Kage

Tema2

Nov 20th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function addTokens(input, tokens) {
  2.   if (typeof input !== "string") {
  3.     throw "Invalid input";
  4.   } else if (input.length < 6) {
  5.     throw "Input should have at least 6 characters";
  6.   }
  7.   if (Array.isArray(tokens)) {
  8.     tokens.forEach(token => {
  9.       if (
  10.         token.hasOwnProperty("tokenName") &&
  11.         typeof token.tokenName === "string"
  12.       ) {
  13.         input = input.replace("...", "${" + token.tokenName + "}");
  14.       } else {
  15.         throw "Invalid array format";
  16.       }
  17.     });
  18.   } else {
  19.     throw "Invalid array format";
  20.   }
  21.   return input;
  22. }
  23.  
  24. const app = {
  25.   addTokens: addTokens
  26. };
  27.  
  28. module.exports = app;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement