How to use the string-replace-async function in string-replace-async

To help you get started, we’ve selected a few string-replace-async examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github springload / metatemplate / src / template-formats / html / template.html.ts View on Github external
)
          ).join("");
        }
        throw Error(
          `Unknown templateUsages type ${typeof templateUsages} from aCode.variables[${key}]. aCode = ${JSON.stringify(
            aCode
          )}. templateUsages: ${JSON.stringify(templateUsages)}`
        );
      };

      // When there are attribute variable placeholders side-by-side
      // then add a space.
      // FIXME: Use a bloody HTML parser for all this code
      html = html.replace(/\}\}\{\{/g, "}} {{");

      html = await stringReplaceAsync(
        html,
        /{{(.*?)}}/gi,
        async (match, middle) => {
          const dynamicKey: DynamicKey = parseDynamicKey(middle);
          validateDynamicKey(dynamicKey);
          return draw(dynamicKey, true, dynamicKey.type as EnumOption[]);
        }
      );

      // Some attributes will be valueless eg disabled="" which is considered
      // false so we shouldn't render the attribute at all.
      html = html.replace(/[a-zA-Z][a-zA-Z0-9-]+?="\s*"/gi, "");
      // and certain boolean attributes should be converted to valueless
      html = html.replace(/([a-zA-Z][a-zA-Z0-9-]+?)="true"/gi, (match, p1) => {
        if (match.includes("value=")) {
          // TODO: compare against HTML5 boolean attributes
github springload / metatemplate / src / template-formats / html / template.html.ts View on Github external
if (!key) throw Error(`Couldn't find key in "${match}"`);

          const value = (aCode as TemplateUsageElement).variables[key];

          if (!!value) {
            const response = match
              .substring(match.indexOf(">") + 1)
              .replace("", "");
            return response;
          } else {
            return "";
          }
        }
      );

      html = await stringReplaceAsync(
        html,
        //gi,
        async match => {
          // self-closing 
          const key = getAttr(match, "key");
          if (!key) throw Error(`Couldn't find key in "${match}"`);
          return await renderByVariableElementKey(key);
        }
      );

      html = await stringReplaceAsync(
        html,
        /([\s\S]*?)<\/mt-variable>/gi,
        async (match, defaultValue) => {
          // expanded  placeholder 
          const key = getAttr(match, "key");
github springload / metatemplate / src / template-formats / html / template.html.ts View on Github external
}
      );

      // Some attributes will be valueless eg disabled="" which is considered
      // false so we shouldn't render the attribute at all.
      html = html.replace(/[a-zA-Z][a-zA-Z0-9-]+?="\s*"/gi, "");
      // and certain boolean attributes should be converted to valueless
      html = html.replace(/([a-zA-Z][a-zA-Z0-9-]+?)="true"/gi, (match, p1) => {
        if (match.includes("value=")) {
          // TODO: compare against HTML5 boolean attributes
          return match;
        }
        return p1;
      });

      html = await stringReplaceAsync(
        html,
        //gi,
        async match => {
          // FIXME: obviously regexes and HTML don't mix well
          // so if nested this will break. Replace with proper parser.
          const key = getAttr(match, "key");
          if (!key) throw Error(`Couldn't find key in "${match}"`);

          const value = (aCode as TemplateUsageElement).variables[key];

          if (!!value) {
            const response = match
              .substring(match.indexOf(">") + 1)
              .replace("", "");
            return response;
          } else {
github imachug / Kiwipedia / main / src / common / wiki-engine / wikitext.js View on Github external
export async function wikiTextToHTML(wikitext, slug) {
	let html = InstaView.convert(wikitext);

	html = await stringReplaceAsync(html, /ARTICLENAMEGOESHERE(.*?)(['"])/g, async (all, article, quote) => {
		let wiki;

		if(article.indexOf(":") == -1) {
			// Local link
			wiki = slug;
		} else {
			// Interwiki
			article = article.replace(/^:/, "");

			wiki = article.substr(0, article.indexOf(":"));
			article = article.substr(article.indexOf(":") + 1);

			wiki = toSlug(wiki.replace("/", "MYAWESOMECONSTANT")).replace(toSlug("MYAWESOMECONSTANT"), "/");
		}

		article = toSlug(article);
github springload / metatemplate / src / template-formats / html / template.html.ts View on Github external
}
        }
      );

      html = await stringReplaceAsync(
        html,
        //gi,
        async match => {
          // self-closing 
          const key = getAttr(match, "key");
          if (!key) throw Error(`Couldn't find key in "${match}"`);
          return await renderByVariableElementKey(key);
        }
      );

      html = await stringReplaceAsync(
        html,
        /([\s\S]*?)<\/mt-variable>/gi,
        async (match, defaultValue) => {
          // expanded  placeholder 
          const key = getAttr(match, "key");
          if (!key) throw Error(`Couldn't find key in "${match}"`);
          return await renderByVariableElementKey(key, defaultValue);
        }
      );

      return html;
    };
github lttb / module-i18n / src / loader / utils / Clause / index.js View on Github external
  return async source => stringReplaceAsync(await source, clauseRegexp, replacer)
}
github lttb / module-i18n / src / loader / utils / Plural / index.js View on Github external
return async (source) => {
    const result = await stringReplaceAsync(await source, pluralRegexp, replacer)

    return result.includes(moduleNamespace)
      ? `const ${moduleNamespace} = ${stringify((await dictionary()).methods)};\n`.concat(result)
      : result
  }
}

string-replace-async

Asynchronous String.prototype.replace()

MIT
Latest version published 3 years ago

Package Health Score

47 / 100
Full package analysis

Popular string-replace-async functions