Skip to content

Commit c38ff1a

Browse files
committed
docs: Rewrite all package descriptions and readmes
1 parent 584401b commit c38ff1a

35 files changed

+546
-346
lines changed

README.md

Lines changed: 40 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
[![downloads](https://img.shields.io/npm/dm/@undercut/pull)](https://www.npmjs.com/package/@undercut/pull)
44
[![circleci](https://circleci.com/gh/the-spyke/undercut.svg?style=shield)](https://circleci.com/gh/the-spyke/undercut)
55
[![codecov](https://codecov.io/gh/the-spyke/undercut/branch/master/graph/badge.svg)](https://codecov.io/gh/the-spyke/undercut)
6-
[![rms](https://img.shields.io/badge/RMS-Compliant-blue)](https://github.com/the-spyke/rms)
6+
[![rms](https://img.shields.io/badge/RMS-0.3.0-blue)](https://github.com/the-spyke/rms)
77
[![netlify](https://api.netlify.com/api/v1/badges/61838e27-0d07-49d4-a295-2d1ab2d91c4d/deploy-status)](https://app.netlify.com/sites/undercut/deploys)
88
[![license](https://img.shields.io/npm/l/undercut.svg)](https://github.com/the-spyke/undercut/blob/master/LICENSE)
99

10-
JavaScript data processing pipelines and utilities. Use native JS features without framework overhead.
10+
JavaScript lazy data processing, pipelines, and language utilities built around native JS features and protocols.
1111

1212
- Based on existing JS protocols and language features
1313
- Balanced API: not too imperative, not too functional
14-
- Various language utilities to use instead of Lodash
15-
- Easy operation extensibility and composability
14+
- Various language utilities to use as a Standard Library
15+
- Composability and extensibility by design
16+
- Custom operations in a couple of lines
1617
- Pure ES Modules with Node 14 loader compliance
17-
- Raw code in the packages + precompiled versions
1818
- Lazy evaluation when possible
1919
- Tree shaking friendliness
20+
- No external dependencies
21+
- TypeScript in JSDoc
22+
23+
Please visit [undercut.js.org](https://undercut.js.org) for broader overview and documentation.
2024

2125
## Usage
2226

@@ -36,94 +40,57 @@ const result = pullArray([
3640
console.log(result); // [8, 10, 14]
3741
```
3842

39-
## Installation
40-
41-
There are 3 main packages:
42-
43-
- [@undercut/pull](https://www.npmjs.com/package/@undercut/pull) -- Pull Lines (Iterables).
44-
- [@undercut/push](https://www.npmjs.com/package/@undercut/push) -- Push Lines (Observers).
45-
- [@undercut/utils](https://www.npmjs.com/package/@undercut/utils) -- Various JavaScript language utilities.
46-
47-
These packages are the intended way to use `Undercut` and comply with the [Raw Module Specification](https://github.com/the-spyke/rms). It means providing original modern JavaScript code in the `ESM` format. It is very convenient for apps using Webpack/Babel/etc, and helps to avoid double compilation and deoptimization. Only [finished proposals (Stage 4)](https://github.com/tc39/proposals/blob/master/finished-proposals.md) may be used in the codebase. The code itself is universal and may be used in Node/Browser/Microwave. Your environment may require `core-js@3` or similar polyfill.
48-
49-
Checkout our [CodeSandbox demo](https://codesandbox.io/s/undercut-demo-1up46?fontsize=14&hidenavigation=1&moduleview=1&theme=dark&previewwindow=console) on how easy it is to use.
50-
51-
Package main entry points are stable, so any export removal/renaming is a breaking change.
43+
```js
44+
import { isNumberValue } from "@undercut/utils";
5245

53-
```sh
54-
npm install @undercut/pull
55-
# or
56-
yarn add @undercut/pull
46+
console.log(isNumberValue(123)); // true
47+
console.log(isNumberValue("hello")); // false
48+
console.log(isNumberValue(NaN)); // false
5749
```
5850

59-
### Additional packages
60-
61-
Several precompiled packages are available:
62-
63-
- [@undercut/cli](https://www.npmjs.com/package/@undercut/cli) -- A command line interface for processing data with JavaScript and `Undercut` in a shell. Accepts string items from `stdin` and puts results as strings into `stdout`. Works on Node.js 10.13 and upwards.
64-
- [@undercut/node-10](https://www.npmjs.com/package/@undercut/node-10) -- A precompiled CommonJS version for Node.js 10.13 and upwards. Requires stable polyfills from `core-js@3`.
65-
- [@undercut/web-2019](https://www.npmjs.com/package/@undercut/web-2019) -- A precompiled version for web browsers not older than `2019-01-01`. Creates `undercut` variable in the global scope, may also be used by CJS/AMD loaders. Requires stable polyfills from `core-js@3`.
66-
67-
### Updating
68-
69-
The process is as descibed in `RMS`: before upgrading the `Undercut` to a newer version, please upgrade `@babel/preset-env` and `core-js` packages to their latest versions too.
70-
71-
## Concepts
51+
## Installation
7252

73-
> Please visit [undercut.js.org](https://undercut.js.org) for full documentation or look in the [docs](docs/) folder.
53+
Undercut is split into packages by functionality. `pull` and `push` provide pipelines for data processing, language utilities are in `utils`. `cli` allows to use Undercut in a shell.
7454

75-
`Undercut` helps constructing pipelines for data processing. Instead of creating new concepts it leverages existing JavaScript protocols and features like [Iteration protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) and [Generators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*).
55+
- [@undercut/pull](https://www.npmjs.com/package/@undercut/pull) -- Pipelines on Iterables.
56+
- [@undercut/push](https://www.npmjs.com/package/@undercut/push) -- Pipelines on Observers.
57+
- [@undercut/utils](https://www.npmjs.com/package/@undercut/utils) -- Generic utilities for type checking, common functions, iterables, objects, promises, randomization, etc.
7658

77-
`Pipelines` is just a term for ordered sequences of operations (just like a conveyor on a factory). Imagine you want to process a bunch of `source` items and put the result items somewhere (`target`).
59+
These packages are the intended way to use `Undercut`. They are compliant with the [Raw Module Specification 0.3.0](https://github.com/the-spyke/rms) and provide original modern JavaScript code in the `ESM` format.
7860

79-
```text
80-
source ----> [ op_0 | op_1 | ... | op_N ] ----> target
81-
pipeline
82-
```
61+
[Precompiled packages are available too.](#precompiled-packages)
8362

84-
Depending on the fact whether the `source` items are or aren't yet available you will have two different approaches: [pull](#pull) and [push](#push).
63+
You may need to compile the code and/or load polyfills depending on your environment. Look for exact minimum versions of `@babel/preset-env` and `core-js` in the `package.json`.
8564

86-
### Pull
65+
Most modern apps already have such infrastructure or use similar tools. So most likely you don't have to do anything. If not, just add [Babel](https://babeljs.io/setup) to your build step.
8766

88-
If `source` items are available at the moment of execution, we can *pull* items from it one by one and process them synchronously. `Undercut` call this a `Pull Line`. It is created by combining a `source` and a `pipeline` into an `Iterable`. This `Iterable` may be passed around and used by any native ES construct like `for-of` loop to read the result. `Undercut` also provides a bunch of `target` helpers for one-line extracting results out of Iterables into common structures like arrays/objects/maps/etc.
67+
Checkout our [CodeSandbox demo](https://codesandbox.io/s/undercut-demo-1up46?fontsize=14&hidenavigation=1&moduleview=1&theme=dark&previewwindow=console) on how easy it is.
8968

90-
Pull Line -- pull items from an Iterable:
69+
Package main entry points are stable, so any export removal/renaming is a breaking change.
9170

92-
```js
93-
const source = [0, 1, 2, 3];
94-
const pipeline = [
95-
append(4, 5),
96-
compact(),
97-
skip(2)
98-
];
99-
100-
// source + pipeline = Iterable
101-
const iterable = pullLine(pipeline, source);
71+
```sh
72+
npm install @undercut/pull
73+
# or
74+
yarn add @undercut/pull
10275
```
10376

104-
Read more about [pull](https://undercut.js.org/docs/pull/overview).
105-
106-
### Push
77+
## CLI
10778

108-
If `source` items are **not** available at the moment of execution, we have to process items as they appear. We can do this by *pushing* items into a `Push Line`. It is created by combining a `pipeline` and a `target` into an `Observer`. `Observers` are convenient in use cases like reacting on a button click and may be passed around or used by several producers.
79+
[@undercut/cli](https://www.npmjs.com/package/@undercut/cli) package provides a command line interface for processing data with JavaScript and operations from Undercut in a shell. It allows you to pass strings from `stdin`, get results in `stdout`, and much more. Works on Node.js 10.13 and upwards.
10980

110-
Push line -- push items into an Observer:
81+
```sh
82+
$ cat strings.txt | undercut 'map(s => s.trim())' 'filter(s => s.length > 10)'
83+
Hello world!
84+
A very long string...
11185

112-
```js
113-
const target = toArray();
114-
const pipeline = [
115-
append(4, 5),
116-
compact(),
117-
skip(2)
118-
];
119-
120-
// pipeline + target = Observer
121-
const observer = pushLine(pipeline, target);
86+
$ undercut -s 'range(0, 5)' 'map(Math.sqrt)' 'sum()'
87+
6.146264369941973
12288
```
12389

124-
Of course, you can process synchronous items with `Push Lines` too, but `Pull Lines` are easier to operate and write operations for.
90+
## Precompiled packages
12591

126-
Read more about [push](https://undercut.js.org/docs/push/overview).
92+
- [@undercut/node-10](https://www.npmjs.com/package/@undercut/node-10) -- A precompiled CommonJS version for Node.js 10.13 and upwards. Requires stable polyfills from `core-js@3`.
93+
- [@undercut/web-2019](https://www.npmjs.com/package/@undercut/web-2019) -- A precompiled version for web browsers not older than `2019-01-01`. Creates `undercut` variable in the global scope, may also be used by CJS/AMD loaders. Requires stable polyfills from `core-js@3`.
12794

12895
## License
12996

docs/cli/overview.md

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: CLI Overview
33
---
44

5-
`@undercut/cli` is a command line utility for data processing using `Undercut`'s Push Lines and any valid JavaScript expressions.
5+
A command line utility for lazy data processing in a shell using operations from Undercut and any valid JavaScript expression including loading your custom libraries.
66

77
## Installation
88

@@ -12,32 +12,88 @@ npm install --global @undercut/cli
1212
yarn global add @undercut/cli
1313
```
1414

15-
You may also install it locally, but don't forget to add `node_modules/.bin` to the `PATH`.
15+
You may also install it locally.
1616

1717
## Usage
1818

19-
The name of the installed command is `Undercut`. You may also import the `run` function from the `@undercut/cli` to call it programmatically.
19+
The name of the installed command is `undercut`. You may also import the `run` function from the `@undercut/cli` to call it programmatically.
2020

21-
```bash
21+
```sh
2222
undercut [...options] [...operations]
2323
```
2424

25-
You're building a `Push Line` where the source is `stdin` and the target is `stdout`. Operations should be quoted (prevents parsing by the shell) and separated by spaces. You can use everything that is available in the global context of Node.js. `Undercut`'s packages are available too under their names: `pull`, `push`, and `utils`.
25+
[List of available operations.](../operations/overview)
2626

27-
```bash
27+
You're building a `Push Line` where the source is `stdin` and the target is `stdout`. Operations should be single quoted (prevents parsing by the shell) and separated by spaces. You can use everything that is available in the global context of Node.js. There're predefined variables with imports from Undercut packages: `pull`, `push`, and `utils`.
28+
29+
```sh
2830
undercut 'map(s => parseInt(s, 10))' 'filter(utils.isNumberValue)'
2931
```
3032

31-
If your expression starts with a call to a `push` exported function, you may omit `"push."` prefix there:
33+
If your expression starts with a call to a `push` function, you may omit the `"push."` prefix there:
3234

33-
```bash
35+
```sh
3436
undercut 'composeOperations([push.sortStrings(utils.desc)])'
3537
^ ^--- but not here
3638
|--- skip prefix here
3739
```
3840

3941
Any valid JavaScript expression resulting into a `PushOperation` works:
4042

41-
```bash
43+
```sh
4244
undercut 'observer => observer' # Does nothing useful, but works.
4345
```
46+
47+
## Options
48+
49+
### `-i`, `--import=SPECIFIER`
50+
51+
Import a Node.js module to use it in expressions. The specifier has the format `name::id`. Module will be loaded by this `id` and accessible under this `name`.
52+
53+
```sh
54+
$ undercut -i 'pad::left-pad' -s 'range(0, 3)' 'map(x => pad(x, 3, 0))'
55+
000
56+
001
57+
002
58+
```
59+
60+
A specifier is translated into something like this:
61+
62+
```js
63+
const name = require("id");
64+
```
65+
66+
So, the `name` should be a valid JS identifier, and the `id` should allow Node to load the module (like a path to a `.js` file or a name of npm package).
67+
68+
You may omit the name if your `id` is a valid identifier:
69+
70+
```js
71+
// -i 'chalk'
72+
const chalk = require("chalk");
73+
```
74+
75+
Or use a destructuring expression:
76+
77+
```js
78+
// -i '{green,blue}::chalk'
79+
const {green,blue} = require("chalk");
80+
```
81+
82+
### `-s`, `--source=EXPRESSION`
83+
84+
Specify a JavaScript expression of an Iterable to read input values from. In this case `stdin` will be ignored.
85+
86+
You can skip the `"pull."` prefix for a function from the `pull` package.
87+
88+
```sh
89+
$ undercut -s 'range(0, 5)' 'sum()'
90+
10
91+
```
92+
93+
### `--help`
94+
95+
Shows help information.
96+
97+
### `--version`
98+
99+
Prints package's version.

docs/faq.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: FAQ
44

55
### Is it a replacement for Lodash and Underscore?
66

7-
Kind of. Undercut provides Pull Lines, which are a good replacement for `Lodash.chain` (without loading entire library), and various utilities for objects/functions/etc. Right now Lodash has more functionality, but Undercut should gain parity with time. The difference is that Undercut is ESM focused and provides only what is missing in the modern language like `Array.isArray` vs. `isArray` utility. Undercut also has more advanced features like Push Lines and supports tree shaking natively.
7+
Kind of. Undercut provides Pull Lines, which are a good replacement for `Lodash.chain` (without loading the entire library), and various utilities for objects/functions/etc. Right now Lodash has more functionality, but Undercut should gain parity with time. The difference is that Undercut is ESM focused and provides only what is missing in the modern language like `Array.isArray` vs. `isArray` utility. Undercut also has more advanced features like Push Lines and supports tree shaking natively. The broader goal is to become a Standard Library.
88

99
### Why it isn't 1.0 yet?
1010

@@ -16,7 +16,7 @@ We use Undercut on our personal projects, but don't know any sufficiently large
1616

1717
### What about performance?
1818

19-
Not measured yet, but we're planning to do automatic benchmarking later.
19+
We're planning to do automatic benchmarking later.
2020

2121
### Why ESNext instead of a precompiled version?
2222

@@ -30,7 +30,7 @@ Most likely not. Checkout our [CodeSandbox demo](https://codesandbox.io/s/underc
3030

3131
### Do I really need "core-js"?
3232

33-
It depends... Node.js and Chrome were quite good lately in catching up with ES releases, so it may run for you without issues. If your environment has something missing, you'll get an error during runtime. Test your code and if everything is fine, I may omit the `core-js`.
33+
It depends... Node.js and Chrome were quite good lately in catching up with ES releases, so it may run for you without issues. If your environment has something missing, you'll get an error during runtime. Test your code and if everything is fine, you may omit the `core-js`.
3434

3535
### Can I contibute?
3636

0 commit comments

Comments
 (0)