How to use the common-tags.replaceSubstitutionTransformer 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 thebespokepixel / trucolor / src / lib / colour.js View on Github external
mlight: 'rgb(255,255,255) darken 25',
	bright: 'rgb(255,255,255)',
	bob: 'black lighten 50 saturate 50 spin 180',
	ul: 'underline',
	invert: 'invert',
	exBackground: 'background dark red',
	exBold: 'bold yellow',
	exFaint: 'faint yellow',
	exItalic: 'italic #33FF33',
	exInvert: 'invert #7B00B1',
	exUnderline: 'underline #fff',
	exBlink: 'blink orange'
}))

export const colorReplacer = new TemplateTag(
	replaceSubstitutionTransformer(
		/([a-zA-Z]+?)[:/|](.+)/,
		(match, colorName, content) => `${clr[colorName]}${content}${clr[colorName].out}`
	)
)

export function spectrum(width, char) {
	if (terminalFeatures.color.has16m) {
		return _.map(new Array(width), (val, col) => {
			const scos = Math.cos((col / width) * (Math.PI / 2))
			const ssin = Math.sin((col / width) * (Math.PI))
			const red = (scos > 0) ? Math.floor(scos * 255) : 0
			const green = (ssin > 0) ? Math.floor(ssin * 255) : 0
			const blue = (scos > 0) ? Math.floor((1 - scos) * 255) : 0
			return `\u001B[38;2;${red};${green};${blue}m${char}`
		}).join('')
	}