You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[@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";
52
45
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
57
49
```
58
50
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
72
52
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.
74
54
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.
76
58
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.
[Precompiled packages are available too.](#precompiled-packages)
83
62
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`.
85
64
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.
87
66
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.
89
68
90
-
Pull Line -- pull items from an Iterable:
69
+
Package main entry points are stable, so any export removal/renaming is a breaking change.
91
70
92
-
```js
93
-
constsource= [0, 1, 2, 3];
94
-
constpipeline= [
95
-
append(4, 5),
96
-
compact(),
97
-
skip(2)
98
-
];
99
-
100
-
// source + pipeline = Iterable
101
-
constiterable=pullLine(pipeline, source);
71
+
```sh
72
+
npm install @undercut/pull
73
+
# or
74
+
yarn add @undercut/pull
102
75
```
103
76
104
-
Read more about [pull](https://undercut.js.org/docs/pull/overview).
105
-
106
-
### Push
77
+
## CLI
107
78
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.
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
125
91
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`.
Copy file name to clipboardExpand all lines: docs/cli/overview.md
+65-9Lines changed: 65 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: CLI Overview
3
3
---
4
4
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.
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.
16
16
17
17
## Usage
18
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.
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
20
21
-
```bash
21
+
```sh
22
22
undercut [...options] [...operations]
23
23
```
24
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`.
25
+
[List of available operations.](../operations/overview)
26
26
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`.
Any valid JavaScript expression resulting into a `PushOperation` works:
40
42
41
-
```bash
43
+
```sh
42
44
undercut 'observer => observer'# Does nothing useful, but works.
43
45
```
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`.
A specifier is translated into something like this:
61
+
62
+
```js
63
+
constname=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
+
constchalk=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.
Copy file name to clipboardExpand all lines: docs/faq.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: FAQ
4
4
5
5
### Is it a replacement for Lodash and Underscore?
6
6
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.
8
8
9
9
### Why it isn't 1.0 yet?
10
10
@@ -16,7 +16,7 @@ We use Undercut on our personal projects, but don't know any sufficiently large
16
16
17
17
### What about performance?
18
18
19
-
Not measured yet, but we're planning to do automatic benchmarking later.
19
+
We're planning to do automatic benchmarking later.
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`.
0 commit comments