-
-
Notifications
You must be signed in to change notification settings - Fork 11
cutbox.js specification
This page outlines the specification of $HOME/.cutbox.js
(i.e. ~/.cutbox.js
)
NOTE: using javascript + pseudo type hints, function interface syntax inspired by Swift
A JavaScript file which contains an array (cutboxFunctions
) of objects containing a function fn
and descriptive metadata name
.
Note: With subsequent versions of CutBox function description metadata may extend to allow for new features.
// Note: use of top level 'this' (aka 'globalThis') is
// required to persist state across evaluations.
this.cutboxFunctions = [
{ fn: CutBoxFunction, name: String }
...
];
A JavaScript Function
adhering to the interface:
[String] -> String
All functions must accept a single argument, an array of strings, and return a single string.
e.g. strings => strings.join(" ")
Any valid JS function, or function reference can be used, providing it adheres to the interface spec above:
let joinWithDashes = items => items.join(" - ")
this.cutboxFunctions = [
{
name: "Join with spaces",
fn: (i) => i.join(" ")
},
{
name: "Join with dashes",
fn: joinWithDashes
},
{
name: "Uppercase",
fn: i => i.map( s => s.toUpperCase() ).join("\n")
},
{
name: "Lowercase",
fn: i => i.map( (s) => {
return s.toLowerCase() ).join("\n")
}
},
{
name: "Join with commas",
fn: function(items){ return items.join(",") }
}
]
For further examples, see: JavaScript Examples
CutBox a nice little pasteboard time-machine