Skip to content

TwoFold (2✂︎f) written for Bun & TypeScript

License

Notifications You must be signed in to change notification settings

ShinyTrinkets/twofold.ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TwoFold (2✂︎f)

Project name

Glorified curly bubbly templates,
Templates with a twist,
Duplex templates,
Mirroring blueprints,
Context aware frames,
Self-replicating, self-terminating forms.

What is this ?

TwoFold is a small command line app that allows plain text files to behave like dynamic files. It is a hybrid between a text expander and a template engine.
It is also inspired by Emacs Org-mode, Python Jupyter Notebooks and React JS.

Check the Similar and comparison page for more details.

TwoFold operates by processing a text file and identifying all XML-like tags, transforming them into useful outputs. It is compatible with XML and HTML documents, but you can customize the tag markers, so you can make them look like jinja2, nunjucks, etc.

TwoFold can watch your files for changes and allow real-time collaboration within the same file and location, for example: to validate some information, or calculate some statistics (similar to a Spreadsheet application), or check for spelling errors (similar to a Document editor), and more.

It will work with any plain-text file like: .txt, Markdown, Emacs Org, reStructured Text, HTML, XML, and source-code files.

Probably WON'T work with binary files like: .doc, .pages, .xls, .numbers, .pdf, images, audio, or video. Running TwoFold on binary files MIGHT break them (with the default config), because media files contain XML-like Exif or IPTC tags.

The single tags are one use only, they are consumed after they render the response. The double tags are refreshed every time the file is rendered. They have different use-cases, different pros and cons.
Read more in the Tags documentation.

This repository provides the framework to parse and evaluate the tags and a few core tags. You can see the list with the command: tfold --tags.

It is easy to write your own tags, and load them with the cmd line switch: tfold --funcs myFolder, where "myFolder" will be a local folder with TypeScript/ JavaScript files.
Read more in the Tags development documentation.

Running for the first time

TwoFold is not published on NPM, because it's not working with Node.js. Therefore, you have to download it and launch it with Bun.

Git clone and run example:

git clone https://github.com/ShinyTrinkets/twofold.ts.git --depth=1
cd twofold.ts

bun tfold --help

The advantage of cloning is that you can later pull the latest version.

Alternatively, you can download the code as ZIP snapshot and extract:

wget https://github.com/ShinyTrinkets/twofold.ts/archive/refs/heads/main.zip
unzip main.zip
cd twofold.ts-main

bun tfold --help

You can also build a standalone executable and use it instead of the code, it takes less than a second:

bun build ./src/cli.ts --compile --outfile tfold

tfold --help

You can move the executable anywhere you need, eg: /usr/local/bin/

Usage

TwoFold uses XML-like tags to call JavaScript functions. If the tags are badly formed, or unknown, or they don't return anything, you won't see anything in the output.

If you have a Markdown file called example.md like this:

## Hello world!

It's a nice <emojiSunMoon /> outside and the time is <emojiClock />. Should I
play with TwoFold some more ? <yesOrNo></yesOrNo> ugh... <line '42' />

You can scan the file without rendering, to see what tags are available:

tfold --scan example.md

The output will look something like this:

(2✂︎f) Scan: example.md
Text length :: 152
[3.77ms] scan-example.md
✓ emojiSunMoon
✓ emojiClock
✓ yesOrNo
✓ line

Then you call TwoFold to render it like this:

tfold example.md

The file should be something like:

## Hello world!
It's a nice ☀️ outside and the time is 🕛.
Should I play with TwoFold some more ? <yesOrNo>Yes</yesOrNo> ugh...
------------------------------------------

To see a list with all the available tags, you can call:

tfold --tags

Read more in the Tags documentation.

Development

Check the Changelog (the past) and the Roadmap (the future).

This TwoFold in TypeScript, running in Bun.

The old version of TwoFold, written for Node.js is at: ShinyTrinkets/twofold.js.

For creating your own tags, read the Tags development documentation.


License

MIT © Shiny Trinkets.

About

TwoFold (2✂︎f) written for Bun & TypeScript

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published