1.1.0 • Published 2 years ago

dummy-templater v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

dummy-templater

Uso

	const {templater} = require('templater');

	// Context object properties are referenced as _.<name> into template.
	const str1 = "<div>{{_.name}}</div>";
	const tte1 = templater(str1);

	// Returned function needs context object for replacement
	console.log(tte1({
		name: "Rodrigo"
	}))


	const str2 = "La lista de la compra{{map()}}"

	// Template constructor can received environment object which members are referenced by its name
	const tte2 = templater(str2, {
		map: function (this: any) {
			return this.values.map((it: string, ix: number) => `   ${ix}-${it}\n`)
		}
	});


	console.log(tte2({
		values: ['Cero', 'Uno', 'Dos']
	}));