All Projects β†’ bogas04 β†’ marinate

bogas04 / marinate

Licence: MIT license
πŸ₯˜ A JavaScript library making use of Tagged Template Literals to chunk, transform and pipe a template to a given stream.

Programming Languages

CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to marinate

morestachio
Lightweight, powerful, flavorful, template engine.
Stars: ✭ 45 (+125%)
Mutual labels:  stream, templating
mobius-gui
🎨 Reactive & Stream & Driver based UI framework build on Mobius Utils, equipped with neumorphism-derived & utility-first styles.
Stars: ✭ 43 (+115%)
Mutual labels:  stream
Prinder
Free Pull Request reminder for Github. Has configurations to post reminders to Slack and email along with jinja templating
Stars: ✭ 21 (+5%)
Mutual labels:  templating
node-twitch-get-stream
Gets the m3u8 direct stream URLs of a live stream on twitch.tv.
Stars: ✭ 45 (+125%)
Mutual labels:  stream
textics
πŸ“‰ JavaScript Text Statistics that counts lines, words, chars, and spaces.
Stars: ✭ 36 (+80%)
Mutual labels:  stream
enmasse
πŸ“« enmasse – Templated emails for GMail.
Stars: ✭ 23 (+15%)
Mutual labels:  templating
jsCast
πŸ“» An Audio Streaming Application written in JavaScript
Stars: ✭ 23 (+15%)
Mutual labels:  stream
rxact
Rxact is an observable application management for Javascript app
Stars: ✭ 21 (+5%)
Mutual labels:  stream
escpos-coffee-samples
anastaciocintra.github.io/escpos-coffee
Stars: ✭ 29 (+45%)
Mutual labels:  stream
ionic-chat-tutorial-react
Build a Real-Time Chat App with Ionic, React, and Stream
Stars: ✭ 19 (-5%)
Mutual labels:  stream
rtmp-social-multicast
Want to stream to Twitch, YouTube, Facebook, and/or Periscope at the same time? That's what this project allows you to do!
Stars: ✭ 42 (+110%)
Mutual labels:  stream
psh
PSH - PHP shell helper
Stars: ✭ 60 (+200%)
Mutual labels:  templating
stream-throttle
Rust Stream combinator, to limit the rate at which items are produced
Stars: ✭ 19 (-5%)
Mutual labels:  stream
docker-bakery
Dockerfile hierarchy management tool with automatic rebuilding of dependent images when parent changes
Stars: ✭ 30 (+50%)
Mutual labels:  templating
Bililive dm VR
[ε’•ε’•ε’•δΈ­] Bη«™VR弹幕姬
Stars: ✭ 18 (-10%)
Mutual labels:  stream
panel
ReCast is a multi platform restreaming tool, you can stream with one servers to multiple services
Stars: ✭ 40 (+100%)
Mutual labels:  stream
rec-core
Data pipelining service
Stars: ✭ 19 (-5%)
Mutual labels:  stream
fastify-axios
Add axios http client to your fastify instance
Stars: ✭ 28 (+40%)
Mutual labels:  nodejs-library
bb8
Starter kit for automating tasks in everyday front-end development. πŸ‘¨πŸ»β€πŸ’» ⚑️ πŸ›  ✨ πŸ€–
Stars: ✭ 13 (-35%)
Mutual labels:  templating
orkid-node
Reliable and modern Redis Streams based task queue for Node.js πŸ€–
Stars: ✭ 61 (+205%)
Mutual labels:  nodejs-library

Marinate

WORK IN PROGRESS

Marinate logo

A JavaScript library making use of Tagged Template Literals to chunk, transform and pipe a template to a given stream.

Installation

The library works on Node 8 and above. However, it's possible to transpile the used features (async await in for..of, template literal strings, tagged template literal) to support older versions of Node.

# use npm
npm install marinate
# or yarn
yarn add marinate
# or new-hip-package-manager-for-js
new-hip-package-manager-for-js marinate

Usage

For a working server, check out this example that uses react & express.

import marinate from 'marinate';

import express from 'express';
import fetch from 'node-fetch';

import { renderToString, renderToNodeStream }  from 'hip-new-framework-of-the-month';

import { Nav, App } from './spa';
import footerHTML from './templates/footer';

const app = express();

const template = marinate`
<!doctype html>
<html>
  <body>
    ${renderToString(Nav)}
    ${() => renderToNodeStream(App)}
    ${() => fetch('api-route').then(r => r.text())}
    ${() => footerHTML}
  </body>
</html>`

app
  .get('/', (req, res) => template(res))
  .listen(4000, () => 'Server listening on port 4000')

Motivation

marinate was created to solve a problem where a node based web server is designed to stream the output, yet use a templating library to split static and non-static parts.

Assume following template

const template = `<html>
  <head>
    ${fs.readFileSync(cssPath)}
  </head>
  <body>
    ${renderToString(App)}
  </body>
</html>`

If you want to stream fs.readFileSync or renderToString part of your application, you will have to split your template into chunks, i.e. template parts before and the said part, then write your first chunk to HTTP Response stream, pipe your App renderStream to it, and finally write latter chunk once your App stream ends. This gets complicated as more and more dynamic portions become part of your template.

Tagged Template Literals

Thankfully, ES2015's tagged template literals are sort of designed to do exactly this. They can create these chunks automatically, and act differently upon the dynamic parts. This allows you to now pass functions, promises, streams and what not !

Currently we support following parts:

  • strings
  • functions
    • returning strings
    • returning promises
    • returning streams

Note that a function can return a function, or a promsie can resovle to a function/promise. Basically the definition of dynami parts is recursive, ultimately evaluating to a string or stream. Be careful!

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].