Skip to content

JavaScript lazy data processing, pipelines, and language utilities built around native JS features and protocols.

License

Notifications You must be signed in to change notification settings

the-spyke/undercut

Repository files navigation

✂ undercut ✂

downloads circleci codecov rms netlify license

Undercut has started as a JavaScript library for lazy data processing and building pipelines. It also provides various language utilities, CLI, and more. The goal is to grow into a Standard Library one day. The code is universal and works in Node/browser/microwave.

  • Based on existing JS protocols and language features
  • Balanced API: not too imperative, not too functional
  • Various language utilities to use as a Standard Library
  • Composability and extensibility by design
  • Custom operations in a couple of lines
  • Pure ES Modules with Node 14 loader compliance
  • Lazy evaluation when possible
  • Tree shaking friendliness
  • No external dependencies
  • TypeScript in JSDoc
  • RMS 0.3.0

Please visit undercut.js.org for broader overview and documentation.

Usage

Undercut Demo

import { pullArray, filter, map, skip } from "@undercut/pull";

const source = [1, 2, 3, 4, 5, 6, 7];

const result = pullArray([
    skip(2),
    filter(x => x % 3),
    map(x => x * 2) // Will be executed only 3 times.
], source);

console.log(result); // [8, 10, 14]
import { isNumberValue } from "@undercut/utils";

console.log(isNumberValue(123)); // true
console.log(isNumberValue("hello")); // false
console.log(isNumberValue(NaN)); // false

Installation

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.

These packages are the intended way to use Undercut. They are compliant with the Raw Module Specification 0.3.0 and provide original modern JavaScript code in the ESM format.

Precompiled packages are available too.

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.

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 to your build step.

Checkout our CodeSandbox demo on how easy it is.

Package main entry points are stable, so any export removal/renaming is a breaking change.

npm install @undercut/pull
# or
yarn add @undercut/pull

CLI

@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 12.17 and upwards.

$ cat strings.txt | undercut 'map(s => s.trim())' 'filter(s => s.length > 10)'
Hello world!
A very long string...

$ undercut -p -s 'pull.range(0, 5)' 'map(Math.sqrt)' 'sum()'
6.146264369941973

Precompiled packages

  • @undercut/node -- A precompiled version for Node.js 12.17 and upwards. Requires stable polyfills from core-js@3.
  • @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.

License

Licensed under the MIT License, see LICENSE for more information.