Origami comics

Coding in your terminal

The ori command line tool evaluates JavaScript expressions, calling functions by file name.

popStats.js
// Return population statistics for the given array of areas
export default function popStats(areas) {
  const populations = areas.map((area) => area.population);
  const total = populations.reduce((sum, pop) => sum + pop, 0);
  return {
    min: Math.min(...populations),
    max: Math.max(...populations),
    total,
  };
}
$ ori popStats.js [{ population: 1000 }, { population: 2000 }]
min: 1000
max: 2000
total: 3000
$

Parens in calls can often be omitted.

You can easily pass data to JavaScript functions from files, standard input, or directly from a server.

https://example.com/data.csv
country,population
Japan,123160000
South Korea,51143421
Taiwan,23299132
$ ori popStats.js https://example.com/data.csv/
min: 23299132
max: 123160000
total: 197602553
$

Origami knows file extensions like CSV.

You can traverse to the specific part of a function’s result that you’re interested in.

https://example.com/data.csv
country,population
Japan,123160000
South Korea,51143421
Taiwan,23299132
$ ori "popStats.js(https://example.com/data.csv/).max"
123160000
$

This expression needs parens.

This lets you develop code without having to constantly restart a larger application.

popStats.js
// Return population statistics for the given array of areas
export default function popStats(areas) {
  const populations = areas.map((area) => area.population);
  const total = populations.reduce((sum, pop) => sum + pop, 0);
  return {
    // Add average to stats
    average: Math.round(total / populations.length),

    min: Math.min(...populations),
    max: Math.max(...populations),
    total,
  };
}
$ ori popStats.js https://example.com/data.csv/
average: 65867518
min: 23299132
max: 123160000
total: 197602553
$

Read more: The ori command-line interface

  Comic index