How to use the common-tags.replaceResultTransformer function in common-tags

To help you get started, we’ve selected a few common-tags 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 DefinitelyTyped / DefinitelyTyped / common-tags / common-tags-tests.ts View on Github external
new commonTags.TemplateTag({
    onSubstitution: substitution => `${substitution}!`,
    onEndResult: endResult => `${endResult}!`
});

/* Tests Built-in Transformers */

new commonTags.TemplateTag(commonTags.trimResultTransformer());
new commonTags.TemplateTag(commonTags.trimResultTransformer('left'));
new commonTags.TemplateTag(commonTags.trimResultTransformer('right'));

new commonTags.TemplateTag(commonTags.stripIndentTransformer());
new commonTags.TemplateTag(commonTags.stripIndentTransformer('initial'));
new commonTags.TemplateTag(commonTags.stripIndentTransformer('all'));

new commonTags.TemplateTag(commonTags.replaceResultTransformer('foo', 'bar'));

new commonTags.TemplateTag(commonTags.inlineArrayTransformer());
new commonTags.TemplateTag(commonTags.inlineArrayTransformer({}));
new commonTags.TemplateTag(commonTags.inlineArrayTransformer({separator: 'foo'}));
new commonTags.TemplateTag(commonTags.inlineArrayTransformer({conjunction: 'bar'}));

new commonTags.TemplateTag(commonTags.splitStringTransformer('foo'));
github doczjs / docz / core / docz-core / src / utils / parse-html.ts View on Github external
if (typeof items === 'string' || items instanceof String) return items
  return items.map(item => item).join('')
}

const getHtmlFilepath = (indexHtml: string | undefined) =>
  indexHtml
    ? path.resolve(paths.root, indexHtml)
    : fromTemplates('index.tpl.html')

const getPublicUrl = (config: Config, dev: boolean): string => {
  const prefix = config.base === '/' ? '' : config.base
  return dev ? prefix : `${prefix}/public`
}

const emptyLineTrim = new ctags.TemplateTag(
  ctags.replaceResultTransformer(/^\s*[\r\n]/gm, ''),
  ctags.trimResultTransformer
)

export const htmlTemplate = async (indexHtml: string | undefined) =>
  compiled(getHtmlFilepath(indexHtml), {
    minimize: false,
    escape: false,
  })

interface ParseHtmlParams {
  config: Config
  ctx: Record
  dev: boolean
  template: (props: Record) => string
}