grotto
v0.0.2-alpha1
Published
WASM lib for functional pure data manipulation
Downloads
5
Maintainers
Readme
WASM lib for functional pure data manipulation.
About
Grotto is a WASM library for manipulating pure data functionally. That means core JavaScript/TypeScript types like string, number, object, array, and boolean. Grotto abstracts away common types of data manipulation to increase application peformance. Leaving you to focus on the unique aspects of your application.
🚴 Usage
npm i grotto
A real world example of Grotto in the Candy Apple Express template engine
import fs from 'fs'
import { replace } from 'grotto';
export function engine(filePath: string, options: object, callback: (err: any, render?: string | Buffer) => void): void {
fs.readFile(filePath, (err, content) => {
if (err) return callback(err);
let render = content.toString();
let guide = {};
for (const [key, val] of Object.entries(options)) {
if (key !== "settings" && key !== "_locals" && key !== "cache") {
(guide as any)[key] = (options as any)[key]
}
}
const result = replace(render, guide)
// Object.entries(options).filter(([key, val]) => { key !== "settings" && key !== "_locals" && key !== "cache" }).map(([key, val]) => {
// const doubleBraceSelect: RegExp = new RegExp(`\{{2}${key}}}`, "g") // select all: `(?<=\{\{).*?(?=\}\})`
// render = render.replace(doubleBraceSelect, val)
// })
callback(null, result)
})
}