Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/duart38/carpenter

Method chaining pattern for all things Deno
https://github.com/duart38/carpenter

builder-pattern carpenter chainable-methods chaining chaining-callables deno methodchain string-carpenter

Last synced: 3 months ago
JSON representation

Method chaining pattern for all things Deno

Awesome Lists containing this project

README

        

Carpenter 🛠




Documentation

## Road 🗺

- [x] Add ARGS (deno.args) carpenter
- [x] Add OS (deno.build) carpenter
- [x] Add STRING carpenter
- [x] Add ARRAY carpenter
- [x] Add SWITCH carpenter
- [x] Add OBJECT carpenter
- [x] Add VALUE carpenter (unknown values)
- [ ] Add more options to STRING carpenter
- [ ] Add more interconnections between various carpenters

## By example

### OS specific code

```JavaScript
import { OS } from "./mod.ts";

// basic
OS.on("darwin").do(() => console.log("Hey Darwin"));
OS.on("darwin").do(() => console.log("Hey Darwin")).else(() =>
console.log("something else")
);
// multiple clauses
let str = "";
OS.on("windows")
.do(() => str += "Hello ")
.do(() => str += "world");
```

---

### Command line argument specific code

```JavaScript
import {ARGS} from "./mod.ts";

// basic usage
ARGS.on("-h")
.do(() => some help code here)
.else(() => -h was not found);

// multiple flags (evaluates when all flags are set)
ARGS.on("-x", "-a")
.do(()=> console.log("flag -x and -a was found together"))
```

### Other carpenters

For more carpenters see documentation.

```JavaScript
import { STRING } from "./mod.ts";

STRING("hello")
.contains("hello").and().contains("x") // false
.or().isOfSize(5) // true
.do(() => console.log("OH WOW!!!!")) // true because of OR operator
;

STRING("hello")
.adapt((prev: string) => prev += " world") // adapts the string.. you may continue with chaining after this
.getValue(); // gets the current object value.
```

```JavaScript
import { SWITCH } from "./mod.ts";

SWITCH(someValue)
.case("one").do(() => {})
.case("chain")
.do(() => {})
.do(() => {})
.default(() => {});
```