Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/duart38/carpenter
- Owner: duart38
- License: mit
- Created: 2021-03-15T10:25:38.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-17T13:32:02.000Z (almost 4 years ago)
- Last Synced: 2024-10-17T18:46:35.874Z (4 months ago)
- Topics: builder-pattern, carpenter, chainable-methods, chaining, chaining-callables, deno, methodchain, string-carpenter
- Language: TypeScript
- Homepage:
- Size: 99.6 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
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(() => {});
```