Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@transformation/ejs

sunesimonsen10.8kMIT7.0.2

Writing pipeline to files with EJS

transformation,automation,pipeline,ejs

readme

@transformation/ejs

A package for rendering EJS templates.

renderTemplate

Renders an EJS template for each item in the pipeline.

const { renderTemplate } = require("@transformation/ejs");

Let say we want to render stock items with a custom template. Let's start out by defining the template in a file called stocks.ejs.

<%-key%>
<% for(let { price } of items) { -%>
  <%-price%>
<% } -%>

Now we can render items with the template by using the renderTemplate transform.

await expect(
  pipeline(
    emitItems(
      { symbol: "GOOG", price: 1349 },
      { symbol: "AAPL", price: 274 },
      { symbol: "AAPL", price: 275 },
      { symbol: "GOOG", price: 1351 },
      { symbol: "AAPL", price: 279 }
    ),
    groupBy("symbol"),
    renderTemplate("stocks.ejs")
  ),
  "to yield items",
  ["GOOG\n  1349\n  1351\n", "AAPL\n  274\n  275\n  279\n"]
);

writeTemplate

Renders an EJS template for each item in the pipeline to a file.

const { writeTemplate } = require("@transformation/ejs");

Let say we want to render stock items with a custom template. Let's start out by defining the template in a file called stocks.ejs.

<%-key%>
<% for(let { price } of items) { -%>
  <%-price%>
<% } -%>

No we can render items with the template by using the writeTemplate transform.

await program(
  emitItems(
    { symbol: "GOOG", price: 1349 },
    { symbol: "AAPL", price: 274 },
    { symbol: "AAPL", price: 275 },
    { symbol: "GOOG", price: 1351 },
    { symbol: "AAPL", price: 279 }
  ),
  groupBy("symbol"),
  writeTemplate("stocks.ejs", ({ key }) => `stocks-${key}.txt`)
);

This will create two files with the following content.

stocks-APPL.txt:

AAPL: 274
AAPL: 275
AAPL: 279

stocks-GOOG.txt:

GOOG: 1349
GOOG: 1351

You can of cause also just write items to one file, you just needs to make sure to aggregate the pipeline into one item first.

Here we define a template that will render a an array of stocks in a file called stocksArray.ejs.

<% for(let { symbol, price } of items) { -%>
<%-symbol%>: <%-price%>
<% } -%>
await program(
  emitItems(
    { symbol: "GOOG", price: 1349 },
    { symbol: "AAPL", price: 274 },
    { symbol: "AAPL", price: 275 },
    { symbol: "GOOG", price: 1351 },
    { symbol: "AAPL", price: 279 }
  ),
  sortBy("symbol"),
  toArray(),
  writeTemplate("stocksArray.ejs", "stocks.txt")
);

This produce the following result.

stocks.txt:

AAPL: 274
AAPL: 275
AAPL: 279
GOOG: 1349
GOOG: 1351

changelog

v7.0.1 (2022-12-06)

Pull requests

Commits to master

v7.0.0 (2022-12-06)

Pull requests

Commits to master

v6.1.0 (2022-12-06)

Pull requests

Commits to master

v6.0.1 (2022-11-23)

Pull requests

Commits to master

v6.0.0 (2022-05-31)

Pull requests

Commits to master

v5.1.1 (2022-05-31)

Pull requests

Commits to master

v5.1.0 (2022-05-31)

Pull requests

Commits to master

v5.0.0 (2022-05-30)

Pull requests

Commits to master

v4.3.0 (2022-02-08)

Pull requests

Commits to master

v4.2.0 (2022-01-17)

Pull requests

Commits to master

v4.1.2 (2021-10-07)

Pull requests

Commits to master

v4.1.1 (2021-09-17)

v4.1.0 (2021-09-17)

Pull requests

Commits to master

v4.0.1 (2021-08-18)

Pull requests

Commits to master

v4.0.0 (2021-03-16)

Pull requests

Commits to master

v3.8.0 (2020-11-12)

Pull requests

Commits to master

v3.7.0 (2020-11-10)

Pull requests

Commits to master

v3.6.0 (2020-11-08)

Pull requests

Commits to master

v3.5.3 (2020-11-08)

v3.5.2 (2020-11-07)

Pull requests

Commits to master

v3.5.1 (2020-11-06)

Pull requests

Commits to master

v3.5.0 (2020-11-06)

Pull requests

Commits to master

v3.4.0 (2020-11-05)

Pull requests

Commits to master

v3.3.0 (2020-11-04)

Pull requests

Commits to master

v3.2.0 (2020-11-03)

Pull requests

Commits to master

v3.1.0 (2020-11-01)

Pull requests

Commits to master

v3.0.0 (2020-11-01)

Pull requests

  • #47 Default to map instead of flatMap for plain functions in a pipeline (Major) (Sune Simonsen)

Commits to master

v2.3.0 (2020-11-01)

Pull requests

Commits to master

v2.2.0 (2020-10-31)

Pull requests

Commits to master

v2.1.0 (2020-10-31)

Pull requests

Commits to master

v2.0.0 (2020-10-31)

Pull requests

Commits to master

v1.34.0 (2020-10-28)

Pull requests

Commits to master

v1.33.0 (2020-09-11)

v1.32.0 (2020-08-11)

Pull requests

Commits to master

v1.31.0 (2020-07-12)

Pull requests

Commits to master

v1.30.2 (2020-07-10)

Pull requests

Commits to master

v1.30.1 (2020-07-08)

Pull requests

Commits to master

v1.30.0 (2020-07-03)

Pull requests

Commits to master

v1.29.1 (2020-07-02)

v1.29.0 (2020-07-02)

Pull requests

Commits to master

v1.28.0 (2020-07-02)

Pull requests

Commits to master

v1.27.1 (2020-06-21)

v1.27.0 (2020-06-21)

Pull requests

Commits to master

v1.26.0 (2020-06-14)

Pull requests

Commits to master

v1.25.0 (2020-06-13)

Pull requests

Commits to master

v1.24.0 (2020-06-12)

Pull requests

Commits to master

v1.23.0 (2020-06-10)

Pull requests

Commits to master

v1.22.0 (2020-06-09)

v1.21.0 (2020-06-08)

Pull requests

Commits to master

v1.20.2 (2020-06-07)

v1.20.1 (2020-06-07)

v1.20.0 (2020-06-07)

Pull requests

Commits to master

v1.19.0 (2020-06-05)

Pull requests

Commits to master

v1.18.2 (2020-06-01)

v1.18.1 (2020-06-01)

v1.18.0 (2020-06-01)

Pull requests

Commits to master

v1.17.0 (2020-05-30)

Pull requests

Commits to master

v1.16.0 (2020-05-29)

Pull requests

Commits to master

v1.15.0 (2020-05-09)

Pull requests

Commits to master

v1.14.1 (2020-04-10)

v1.14.0 (2020-02-10)

v1.13.0 (2020-02-10)

v1.12.3 (2020-02-03)

v1.12.2 (2020-01-18)

v1.12.1 (2020-01-17)

v1.12.0 (2020-01-17)

v1.11.0 (2020-01-17)

v1.10.0 (2020-01-15)

v1.9.1 (2020-01-04)

v1.9.0 (2020-01-04)

v1.8.0 (2020-01-03)

v1.7.1 (2019-12-29)

v1.7.0 (2019-12-29)

v1.6.0 (2019-12-25)

v1.5.0 (2019-12-23)

v1.4.1 (2019-12-23)

v1.4.0 (2019-12-23)

v1.3.1 (2019-12-21)

v1.3.0 (2019-12-21)

v1.2.0 (2019-12-21)

v1.1.1 (2019-12-18)

v1.1.0 (2019-12-18)