Skip to content

Commit a7868e5

Browse files
committed
chore: add website and move docs
1 parent 88271ba commit a7868e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+10394
-538
lines changed

.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@
9999
}
100100
],
101101
"import/no-extraneous-dependencies": "error",
102+
"import/no-unresolved": [
103+
"error",
104+
{
105+
"commonjs": true
106+
}
107+
],
102108
"indent": [
103109
"error",
104110
"tab",

README.md

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,13 @@ JavaScript data processing pipelines and utilities. Use native Iterators/Generat
1515
- Lazy evaluation when possible
1616
- Tree shaking friendliness
1717

18-
## Quicklinks
19-
20-
- [Installation](#installation)
21-
- [Usage](#usage)
22-
- [Concepts](#concepts)
23-
- [Pull](packages/undercut-pull/README.md)
24-
- [Push](packages/undercut-push/README.md)
25-
- [Operations](operations.md)
26-
- [Utilities](packages/undercut-utils/README.md)
27-
- [License](#license)
28-
2918
## Installation
3019

3120
There are 3 main packages:
3221

33-
- [`@undercut/pull`](https://www.npmjs.com/package/@undercut/pull) -- exports Pull Lines (Iterables). [\[documentation\]](packages/undercut-pull/README.md)
34-
- [`@undercut/push`](https://www.npmjs.com/package/@undercut/push) -- exports Push Lines (Observers). [\[documentation\]](packages/undercut-push/README.md)
35-
- [`@undercut/utils`](https://www.npmjs.com/package/@undercut/utils) -- exports all the various JavaScript utilities. [\[documentation\]](packages/undercut-utils/README.md)
22+
- [`@undercut/pull`](https://www.npmjs.com/package/@undercut/pull) -- exports Pull Lines (Iterables).
23+
- [`@undercut/push`](https://www.npmjs.com/package/@undercut/push) -- exports Push Lines (Observers).
24+
- [`@undercut/utils`](https://www.npmjs.com/package/@undercut/utils) -- exports all the various JavaScript utilities.
3625

3726
These packages are the intended way to use `undercut`. They carry `stable ES Next` code. It is very convenient for apps using Webpack/Babel/etc, and will help 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 its codebase. The code is universal and may be used in Node/Browser/microwave.
3827

@@ -48,11 +37,11 @@ yarn add @undercut/pull
4837

4938
### Additional packages
5039

51-
Several precompiled packages are available for older projects or quick experiments. They do not require any sort of compilaton:
40+
Several precompiled packages are available:
5241

53-
- [`@undercut/cli`](https://www.npmjs.com/package/@undercut/cli) -- provides 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`. This package is compiled for Node.js 10 LTS and upwards. [\[documentation\]](packages/undercut-cli/README.md)
54-
- [`@undercut/node-10`](https://www.npmjs.com/package/@undercut/node-10) -- a precompiled CommonJS version for Node.js 10 LTS and upwards. Requires stable polyfills from `core-js@3`. [\[documentation\]](packages/undercut-node-10/README.md)
55-
- [`@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` property in the `window`, may also be used by CJS/AMD loaders. Requires stable polyfills from `core-js@3`. [\[documentation\]](packages/undercut-web-2019/README.md)
42+
- [`@undercut/cli`](https://www.npmjs.com/package/@undercut/cli) -- provides 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.
43+
- [`@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`.
44+
- [`@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`.
5645

5746
### Updating `undercut`
5847

@@ -76,6 +65,8 @@ console.log(result); // [8, 10, 14]
7665

7766
## Concepts
7867

68+
*\* Please visit the website for full documentation or look in the `docs` folder.*
69+
7970
`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*).
8071

8172
`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`).
@@ -105,14 +96,6 @@ Push line -- push items into an Observer
10596

10697
Of course, you can process synchronous items with `Push Lines` too, but `Pull Lines` are easier to operate and write operations for.
10798

108-
## [Pull](packages/undercut-pull/README.md)
109-
110-
## [Push](packages/undercut-push/README.md)
111-
112-
## [Operations](operations.md)
113-
114-
## [Utilities](packages/undercut-utils/README.md)
115-
11699
## License
117100

118101
Licensed under the MIT License, see [LICENSE](LICENSE) for more information.

docs/cli/examples.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: CLI Examples
3+
---
4+
5+
### Pipe data through like you usually do in a shell
6+
7+
```bash
8+
$ cat strings.txt | undercut 'map(s => s.trim())' 'filter(s => s.length > 10)'
9+
Hello world!
10+
A very long string...
11+
```
12+
13+
Use an Iterable as a `source` instead of `stdin`:
14+
15+
```bash
16+
$ undercut -s 'range(0, 5)' 'map(Math.sqrt)' 'sum()'
17+
6.146264369941973
18+
```
19+
20+
### Import an installed `npm` package and use it
21+
22+
```bash
23+
$ undercut -i 'pad::left-pad' -s 'range(0, 3)' 'map(x => pad(x, 3))'
24+
000
25+
001
26+
002
27+
```
28+
29+
### Enter text data from keyboard by skipping a source
30+
31+
Results will be printed to `stdout` after you signal the end of input with `Ctrl + D`:
32+
33+
```bash
34+
$ undercut 'map(s => s.toUpperCase(s))'
35+
Tom
36+
Sam
37+
# Ctrl + D to finish the input.
38+
TOM
39+
SAM
40+
```

docs/cli/overview.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: CLI Overview
3+
---
4+
5+
`@undercut/cli` is a command line utility for data processing using `undercut`'s Push Lines and any valid JavaScript expressions.
6+
7+
## Installation
8+
9+
```bash
10+
npm install --global @undercut/cli
11+
# or
12+
yarn global add @undercut/cli
13+
```
14+
15+
You may also install it locally, but don't forget to add `node_modules/.bin` to the `PATH`.
16+
17+
## Usage
18+
19+
The name of the installed command is `undercut`. You may also import the `run` function from the `@undercut/cli` to call it programmatically.
20+
21+
```bash
22+
undercut [...options] [...operations]
23+
```
24+
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`.
26+
27+
```bash
28+
undercut 'map(s => parseInt(s, 10))' 'filter(utils.isNumberValue)'
29+
```
30+
31+
If your expression starts with a call to a `push` exported function, you may omit `"push."` prefix there:
32+
33+
```bash
34+
undercut 'composeOperations([push.sortStrings(utils.desc)])'
35+
^ ^--- but not here
36+
|--- skip prefix here
37+
```
38+
39+
Any valid JavaScript expression resulting into a `PushOperation` works:
40+
41+
```bash
42+
undercut 'observer => observer' # Does nothing useful, but works.
43+
```

docs/concepts.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Concepts
3+
---
4+
5+
`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*).
6+
7+
`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 into a `target`.
8+
9+
```text
10+
source ----> [ op_0 | op_1 | ... | op_N ] ----> target
11+
pipeline
12+
```
13+
14+
Depending on the fact whether the `source` items are or aren't yet available you will have two different approaches: `pull` and `push`.
15+
16+
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.
17+
18+
```text
19+
Pull Line -- pull items from an Iterable
20+
21+
( source + pipeline = Iterable )
22+
```
23+
24+
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.
25+
26+
```text
27+
Push line -- push items into an Observer
28+
29+
( pipeline + target = Observer )
30+
```
31+
32+
Of course, you can process synchronous items with `Push Lines` too, but `Pull Lines` are easier to operate and write operations for.

docs/introduction.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: Introduction
3+
---
4+
5+
`Undercut` is a JavaScript library for building data processing pipelines. It also provides general purpose utilities.
6+
7+
- Based on existing JS protocols and language features
8+
- Balanced API: not too imperative, not too functional
9+
- Easy operation extensibility and composability
10+
- Pure ES Modules with Node 13 loader compliance
11+
- Raw code in the packages + precompiled versions
12+
- Lazy evaluation when possible
13+
- Tree shaking friendliness
14+
15+
## Installation
16+
17+
There are 3 main packages:
18+
19+
- [`@undercut/pull`](pull/overview) -- exports Pull Lines (Iterables).
20+
- [`@undercut/push`](push/overview) -- exports Push Lines (Observers).
21+
- [`@undercut/utils`](utils/overview) -- exports all the various JavaScript utilities.
22+
23+
These packages are the intended way to use `undercut` and carry `stable ES Next` code. It is very convenient for apps using Webpack/Babel/etc, and will help 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 its codebase. The code is universal and may be used in Node/Browser/microwave.
24+
25+
Don't forget to check that `/node_modules/@undercut/` isn't excluded from compilation and `core-js@3` polyfill or analogue is in place.
26+
27+
Package main entry points are stable, so any export removal/renaming is as a breaking change.
28+
29+
```bash
30+
npm install @undercut/pull
31+
# or
32+
yarn add @undercut/pull
33+
```
34+
35+
### Additional packages
36+
37+
Several [precompiled packages](precompiled) are available too:
38+
39+
- `@undercut/cli`
40+
- `@undercut/node-10`
41+
- `@undercut/web-2019`
42+
43+
### Updating `undercut`
44+
45+
If you're updating `undercut` to a newer version, please update `@babel/preset-env` and `core-js` packages to the latest versions too.
46+
47+
## Usage
48+
49+
```js
50+
import { pullArray, filter, map, skip } from "@undercut/pull";
51+
52+
const source = [1, 2, 3, 4, 5, 6, 7];
53+
54+
const result = pullArray([
55+
skip(2),
56+
filter(x => x % 3 === 0),
57+
map(x => x * 2) // Will be executed only 3 times.
58+
], source);
59+
60+
console.log(result); // [8, 10, 14]
61+
```

docs/operations/overview.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Operations
1+
---
2+
title: Operations List
3+
---
24

3-
## Common operations
4-
5-
These operations exist in both `pull` and `push` versions:
5+
Currently all operations exist in both `pull` and `push` versions:
66

77
- `append(...items)` -- adds its arguments to the end of the sequence.
88
- `average()` -- reduces the sequence into a number by calculating the average of it.
@@ -64,11 +64,3 @@ These operations exist in both `pull` and `push` versions:
6464
- `unzipWith(itemsExtractor)` -- reverse to the `zip` producing a sequence of sources by getting their items from the `extractor`.
6565
- `zip(...sources)` -- transforms the sequence into a new one by combining by one item from it and the sources into an array.
6666
- `zipWith(itemFactory, ...sources)` -- transforms the sequence into a new one by combining by one item from it and the source into a value returned by the `itemFactory`.
67-
68-
## Pull-only operations
69-
70-
- N/A
71-
72-
## Push-only operations
73-
74-
- N/A

docs/packages.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Precompiled Packages
3+
---
4+
5+
### `@undercut/cli`
6+
7+
Provides 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`. This package works on Node.js 10.13 and upwards.
8+
9+
[Full documentation.](cli/overview)
10+
11+
### `@undercut/node-10`
12+
13+
A precompiled CommonJS version of `pull/push/utils` packages for Node.js 10.13 and upwards. Requires stable polyfills from `core-js@3`.
14+
15+
Usage is similar to original packages:
16+
17+
```js
18+
const { pullArray, filter, map, skip } = require("@undercut/node-10/pull");
19+
20+
const source = [1, 2, 3, 4, 5, 6, 7];
21+
22+
const result = pullArray([
23+
skip(2),
24+
filter(x => x % 3 === 0),
25+
map(x => x * 2) // Will be executed only 3 times.
26+
], source);
27+
28+
console.log(result); // [8, 10, 14]
29+
```
30+
31+
### `@undercut/web-2019`
32+
33+
A precompiled version of `pull/push/utils` packages 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`.
34+
35+
Usage is similar to original packages, but supports different loading styles. Import desired entry first:
36+
37+
```js
38+
// When using as a script tag and its global variable:
39+
const { pullArray, filter, map, skip } = undercut.pull;
40+
// When using as a CommonJS module:
41+
const { pullArray, filter, map, skip } = require("@undercut/web-2019/pull");
42+
// When using local copy as an AMD module:
43+
require(["scripts/undercut/pull.js"], function ({ pullArray, filter, map, skip }) {
44+
/* Your code */
45+
});
46+
```
47+
48+
*\* There're [example HTML pages](https://github.com/the-spyke/undercut/tree/master/packages/undercut-web-2019/examples) in the repository.*
49+
50+
And then use it in your code:
51+
52+
```js
53+
const source = [1, 2, 3, 4, 5, 6, 7];
54+
55+
const result = pullArray([
56+
skip(2),
57+
filter(x => x % 3 === 0),
58+
map(x => x * 2) // Will be executed only 3 times.
59+
], source);
60+
61+
console.log(result); // [8, 10, 14]
62+
```

0 commit comments

Comments
 (0)