Janet 1.27.0-01aab66 Documentation
(Other Versions: 1.26.0 1.25.1 1.24.0 1.23.0 1.22.0 1.21.0 1.20.0 1.19.0 1.18.1 1.17.1 1.16.1 1.15.0 1.13.1 1.12.2 1.11.1 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

Spork

While not part of Janet's core library, Spork is an official "contributor" library as well as a collection of various useful utilties for Janet.

Spork can be installed with

jpm install spork

Index

spork/argparse/argparse spork/base64/decode spork/base64/encode spork/crc/make-variant spork/crc/named-variant spork/cron/check spork/cron/next-timestamp spork/cron/parse-cron spork/ev-utils/go-nursery spork/ev-utils/join-nursery spork/ev-utils/multithread-service spork/ev-utils/nursery spork/ev-utils/pcall spork/ev-utils/pdag spork/ev-utils/pmap spork/ev-utils/pmap-full spork/ev-utils/pmap-limited spork/ev-utils/spawn-nursery spork/ev-utils/wait-cancel spork/fmt/format spork/fmt/format-file spork/fmt/format-print spork/generators/concat spork/generators/cycle spork/generators/drop spork/generators/drop-until spork/generators/drop-while spork/generators/filter spork/generators/from-iterable spork/generators/map spork/generators/mapcat spork/generators/range spork/generators/run spork/generators/take spork/generators/take-until spork/generators/take-while spork/generators/to-array spork/getline/default-autocomplete-context spork/getline/default-autocomplete-options spork/getline/default-doc-fetch spork/getline/make-getline spork/getline/max-history spork/htmlgen/doctype-html spork/htmlgen/escape spork/htmlgen/html spork/htmlgen/raw spork/http/cookie-grammar spork/http/cookies spork/http/logger spork/http/middleware spork/http/query-string-grammar spork/http/read-body spork/http/read-request spork/http/read-response spork/http/request spork/http/request-peg spork/http/response-peg spork/http/router spork/http/send-response spork/http/server spork/http/server-handler spork/http/status-messages spork/http/url-grammar spork/httpf/add-bindings-as-routes spork/httpf/add-route spork/httpf/default-payload-wrapper spork/httpf/listen spork/httpf/server spork/json/decode spork/json/encode spork/mdz/*front-matter* spork/mdz/*markup-dom* spork/mdz/add-loader spork/mdz/anchor spork/mdz/bigger spork/mdz/blockquote spork/mdz/center spork/mdz/code spork/mdz/codeblock spork/mdz/div spork/mdz/em spork/mdz/hr spork/mdz/html spork/mdz/image spork/mdz/li spork/mdz/link spork/mdz/markup spork/mdz/mdz-loader spork/mdz/ol spork/mdz/p spork/mdz/pre spork/mdz/section spork/mdz/smaller spork/mdz/strong spork/mdz/sub spork/mdz/sup spork/mdz/tag spork/mdz/td spork/mdz/th spork/mdz/tr spork/mdz/u spork/mdz/ul spork/misc/always spork/misc/antepenultimate spork/misc/caperr spork/misc/capout spork/misc/cond-> spork/misc/cond->> spork/misc/dedent spork/misc/defs spork/misc/dfs spork/misc/do-def spork/misc/do-var spork/misc/format-table spork/misc/gett spork/misc/insert-sorted spork/misc/insert-sorted-by spork/misc/int->string spork/misc/int/ spork/misc/log spork/misc/make spork/misc/make-id spork/misc/map-keys spork/misc/map-vals spork/misc/penultimate spork/misc/print-table spork/misc/randomize-array spork/misc/second spork/misc/select-keys spork/misc/set* spork/misc/string->int spork/misc/table-filter spork/misc/third spork/misc/trim-prefix spork/misc/trim-suffix spork/misc/until spork/misc/vars spork/msg/make-proto spork/msg/make-recv spork/msg/make-send spork/netrepl/client spork/netrepl/default-host spork/netrepl/default-port spork/netrepl/server spork/netrepl/server-single spork/path/abspath spork/path/abspath? spork/path/basename spork/path/delim spork/path/dirname spork/path/ext spork/path/join spork/path/normalize spork/path/parts spork/path/posix/abspath spork/path/posix/abspath? spork/path/posix/basename spork/path/posix/delim spork/path/posix/dirname spork/path/posix/ext spork/path/posix/join spork/path/posix/normalize spork/path/posix/parts spork/path/posix/relpath spork/path/posix/sep spork/path/relpath spork/path/sep spork/path/win32/abspath spork/path/win32/abspath? spork/path/win32/basename spork/path/win32/delim spork/path/win32/dirname spork/path/win32/ext spork/path/win32/join spork/path/win32/normalize spork/path/win32/parts spork/path/win32/relpath spork/path/win32/sep spork/rawterm/begin spork/rawterm/buffer-traverse spork/rawterm/ctrl-z spork/rawterm/end spork/rawterm/getch spork/rawterm/isatty spork/rawterm/monowidth spork/rawterm/rune-monowidth spork/rawterm/size spork/rawterm/slice-monowidth spork/regex/compile spork/regex/find spork/regex/find-all spork/regex/match spork/regex/peg spork/regex/replace spork/regex/replace-all spork/regex/source spork/rpc/client spork/rpc/default-host spork/rpc/default-port spork/rpc/server spork/schema/make-predicate spork/schema/make-validator spork/schema/predicate spork/schema/validator spork/services/*current-manager* spork/services/*current-service* spork/services/add-service spork/services/all-services spork/services/get-manager spork/services/get-service spork/services/make-manager spork/services/print-all spork/services/remove-service spork/services/set-title spork/services/start-service spork/services/stop-service spork/services/wait spork/sh/copy spork/sh/copy-file spork/sh/create-dirs spork/sh/devnull spork/sh/exec spork/sh/exec-fail spork/sh/exec-slurp spork/sh/exec-slurp-all spork/sh/exists? spork/sh/list-all-files spork/sh/make-new-file spork/sh/rm spork/sh/scan-directory spork/tarray/buffer spork/tarray/copy-bytes spork/tarray/length spork/tarray/new spork/tarray/properties spork/tarray/slice spork/tarray/swap-bytes spork/tasker/all-tasks spork/tasker/cancel-task spork/tasker/close-queues spork/tasker/default-expiration spork/tasker/default-priority spork/tasker/default-task-directory spork/tasker/err-file-name spork/tasker/max-priority spork/tasker/min-priority spork/tasker/new-tasker spork/tasker/out-file-name spork/tasker/queue-task spork/tasker/run-cleanup spork/tasker/run-executors spork/tasker/spawn-executors spork/tasker/statuses spork/tasker/task-file spork/tasker/task-meta-name spork/tasker/task-status spork/temple/add-loader spork/temple/base-env spork/temple/compile spork/temple/create spork/test/assert spork/test/assert-docs spork/test/assert-error spork/test/assert-no-error spork/test/assert-not spork/test/capture-stderr spork/test/capture-stdout spork/test/end-suite spork/test/start-suite spork/test/suppress-stderr spork/test/suppress-stdout spork/test/timeit spork/utf8/decode-rune spork/utf8/encode-rune spork/utf8/prefix->width spork/zip/add-bytes spork/zip/add-file spork/zip/compress spork/zip/decompress spork/zip/extract spork/zip/file-directory? spork/zip/file-encrypted? spork/zip/file-supported? spork/zip/get-filename spork/zip/locate-file spork/zip/read-bytes spork/zip/read-file spork/zip/reader-close spork/zip/reader-count spork/zip/stat spork/zip/version spork/zip/write-buffer spork/zip/write-file spork/zip/writer-close spork/zip/writer-finalize

function (spork/argparse/argparse description &keys options)
Parse `(dyn :args)` according to options. If the arguments are incorrect,
will return nil and print usage information.

Each option is a table or struct that specifies a flag or option
for the script. The name of the option should be a string, specified
via `(argparse/argparse "..." op1-name {...} op2-name {...} ...)`. A help option
and usage text is automatically generated for you.

The keys in each option table are as follows:

* `:kind` - What kind of option is this? One of `:flag`, `:multi`, `:option`, or
 `:accumulate`. A flag can either be on or off, a multi is a flag that can be provided
 multiple times, each time adding 1 to a returned integer, an option is a key that
 will be set in the returned table, and accumulate means an option can be specified
 0 or more times, each time appending a value to an array.
* `:short` - Single letter for shorthand access.
* `:help` - Help text for the option, explaining what it is.
* `:default` - Default value for the option.
* `:required` - Whether or not an option is required.
* `:short-circuit` - Whether or not to stop parsing and fail if this option is hit.
* `:action` - A function that will be invoked when the option is parsed.

There is also a special option name `:default` that will be invoked on arguments
that do not start with a -- or -. Use this option to collect unnamed
arguments to your script. This is separate from the `:default` key in option specifiers.

After "--", every argument is treated as an unnamed argument.

Once parsed, values are accessible in the returned table by the name
of the option. For example `(result "verbose")` will check if the verbose
flag is enabled.
Community Examples / source
function (spork/base64/decode s)
Converts a base64 encoded string to its binary representation of any format
(UTF-8, binary, ..).
Community Examples / source
function (spork/base64/encode s)
Converts a string of any format (UTF-8, binary, ..) to base64 encoding.
Community Examples / source
cfunction (spork/crc/make-variant size polynomial &opt init byte-flip xorout)
Create a CRC function based on the given polynomial, initial value, xourout, and whether to invert input bytes.
Community Examples / source
cfunction (spork/crc/named-variant name)
Get a named CRC variant.
Community Examples / source
function (spork/cron/check cron &opt time local)
Check if a given time matches a cron specifier.
Community Examples / source
function (spork/cron/next-timestamp cron &opt time local)
Given a cron schedule, get the next instance on the cron tab after time
Community Examples / source
function (spork/cron/parse-cron str)
Parse a cron string into a valid cron schedule object
Community Examples / source
function (spork/ev-utils/go-nursery nurse f &opt value)
Spawn a fiber into a nursery, similar to ev/go.
Community Examples / source
function (spork/ev-utils/join-nursery nurse)
Suspend the current fiber until the nursery is emptied.
Community Examples / source
function (spork/ev-utils/multithread-service thread-main n-threads)
Run instances of a function over multiple threads. On failures, restart the failed thread. Normal function returns will not trigger a restart.
Community Examples / source
function (spork/ev-utils/nursery )
Group a number of fibers into a single object for structured concurrency
Community Examples / source
function (spork/ev-utils/pcall f n)
Call a function n times (in parallel) for side effects. Each function is called with an integer argument indicating a fiber index. Returns nil.
Community Examples / source
function (spork/ev-utils/pdag f dag &opt n-workers)
Executes a dag by calling f on every node in the graph. Can set the number of workers for parallel execution. The graph is represented as a table mapping nodes to arrays of child nodes. Each node will only be evaluated after all children have been evaluated. Modifying `dag` inside `f` will not affect the scheduling of workers. Returns a table mapping each node to the result of `(f node)`.
Community Examples / source
function (spork/ev-utils/pmap f data &opt n-workers)
Map `f` over data in parallel, optionally limiting parallelism to `n` workers.
Community Examples / source
function (spork/ev-utils/pmap-full f data)
Function form of `ev/gather`. If any of the sibling fibers error, all other siblings will be canceled. Returns the gathered results in an array. `data` can be any indexed data structure.
Community Examples / source
function (spork/ev-utils/pmap-limited f data n-workers)
Similar to pmap-full, but only runs work n-ways parallel.
Community Examples / source
macro (spork/ev-utils/spawn-nursery nurse & body)
Similar to ev/spawn but associate spawned fibers with a nursery
Community Examples / source
macro (spork/ev-utils/wait-cancel & body)
Wait forever until the current fiber is canceled, and then run some cleanup code.
Community Examples / source
function (spork/fmt/format source)
Format a string of source code to a buffer.
Community Examples / source
function (spork/fmt/format-file file)
Format a file
Community Examples / source
function (spork/fmt/format-print source)
Format a string of source code and print the result.
Community Examples / source
function (spork/generators/concat & xs)
Concatenate one or more generators or iterables into a single generator.
Community Examples / source
function (spork/generators/cycle ds)
Repeatedly yield the elements of `ds`, looping back to the beginning when finished.
Community Examples / source
function (spork/generators/drop n ds)
Drop `n` elements from `ds`.
Community Examples / source
function (spork/generators/drop-until p ds)
Drop elements from `ds` until `p` is true.
Community Examples / source
function (spork/generators/drop-while p ds)
Drop elements from `ds` while `p` is true.
Community Examples / source
function (spork/generators/filter p ds)
Create a generator that filters `ds` with `p`.
Community Examples / source
function (spork/generators/from-iterable ds)
Create a new generator around any iterable data structure.
Community Examples / source
function (spork/generators/map f ds)
Create a generator that maps `f` over `ds`.
Community Examples / source
function (spork/generators/mapcat f ds)
Map `f` over `ds`, concatenating the results into a new generator.
Community Examples / source
function (spork/generators/range from to)
Create a lazy range.
Community Examples / source
function (spork/generators/run s)
Evaluate `s` for side effects.
Community Examples / source
function (spork/generators/take n ds)
Take `n` elements from iterable `ds`.
Community Examples / source
function (spork/generators/take-until p ds)
Return elements from `ds` until `p` is true.
Community Examples / source
function (spork/generators/take-while p ds)
Return elements from `ds` while `p` is true.
Community Examples / source
function (spork/generators/to-array s)
Consume `s` into a new array.
Community Examples / source
function (spork/getline/default-autocomplete-context buf pos)
Given a buffer and a cursor position, extract a string that will be used as context for autocompletion. Return a position and substring from the buffer to use for autocompletion.
Community Examples / source
function (spork/getline/default-autocomplete-options prefix &)
Default handler to get available autocomplete options for a given substring.
Community Examples / source
function (spork/getline/default-doc-fetch sym w &)
Default handler for Ctrl-G to lookup docstrings in the current environment.
Community Examples / source
function (spork/getline/make-getline &opt autocomplete-context autocomplete-options doc-fetch)
Reads a line of input into a buffer, like `getline`. However, allow looking up entries with a general lookup function rather than a environment table.
Community Examples / source
number spork/getline/max-history
Maximal amount of items in the history
Community Examples / source
function (spork/htmlgen/doctype-html html5 doctype header)
Community Examples / source
function (spork/htmlgen/escape x)
Escape characters in a string for HTML
Community Examples / source
function (spork/htmlgen/html data &opt buf)
Render HTML from standard data structures. Fills the provided optional buffer, or new one if it is not provided, with the html bytes.
Community Examples / source
function (spork/htmlgen/raw text)
Get an object that can be used to splice in HTML literals. `text` is not escaped in the output string.
Community Examples / source
core/peg spork/http/cookie-grammar
Grammar to parse a cookie header to a series of keys and values.
Community Examples / source
function (spork/http/cookies nextmw)
Parses cookies into the table under :cookies key
Community Examples / source
function (spork/http/logger nextmw)
Creates a logging middleware. The logger middleware prints URL route, return status, and elapsed request time.
Community Examples / source
function (spork/http/middleware x)
Coerce any type to http middleware
Community Examples / source
core/peg spork/http/query-string-grammar
Grammar that parses a query string (sans url path and ? character) and returns a table.
Community Examples / source
function (spork/http/read-body req)
Given a request, read the HTTP body from the connection. Returns the body as a buffer. If the request has no body, returns nil.
Community Examples / source
function (spork/http/read-request conn buf &opt no-query)
Read an HTTP request header from a connection. Returns a table with the following keys: * `:headers` - table mapping header names to header values. Header names are lowercase. * `:connection` - the connection stream for the header. * `:buffer` - the buffer instance that may contain extra bytes. * `:head-size` - the number of bytes used by the header. * `:method` - the HTTP method used. * `:path` - the path of the resource requested. The following keys are also present, but omitted if the user passes a truthy parameter to `no-query`. * `:route` - path of the resource requested without query string. * `:query-string` - segment of HTTP path after first ? character. * `:query` - the query string parsed into a table. Supports a single string value     for every string key, and any query parameters that aren't given a value are mapped to true.  Note that data is read in chunks and any data after the header terminator is  stored in `:buffer.`
Community Examples / source
function (spork/http/read-response conn buf)
Read an HTTP response header from a connection. Returns a table with the following keys: * `:headers` - table mapping header names to header values. Header names are lowercase. * `:connection` - the connection stream for the header. * `:buffer` - the buffer instance that may contain extra bytes. * `:head-size` - the number of bytes used by the header. * `:status` - the HTTP status code. * `:message` - the HTTP status message. Note that data is read in chunks and any data after the header terminator is stored in `:buffer.`
Community Examples / source
function (spork/http/request method url &keys {:headers headers :body body})
Make an HTTP request to a server. Returns a table contain response information. * `:head-size` - number of bytes in the http header * `:headers` - table mapping header names to header values. Header names are lowercase. * `:connection` - the connection stream for the header. * `:buffer` - the buffer instance that may contain extra bytes. * `:status` - HTTP status code as an integer. * `:message` - HTTP status message. * `:body` - Bytes of the response body.
Community Examples / source
core/peg spork/http/request-peg
PEG for parsing HTTP requests
Community Examples / source
core/peg spork/http/response-peg
PEG for parsing HTTP responses
Community Examples / source
function (spork/http/router routes)
Creates a router middleware. A router will dispatch to different routes based on the URL path.
Community Examples / source
function (spork/http/send-response conn response &opt buf)
Send an HTTP response over a connection. Will automatically use chunked encoding if body is not a byte sequence. `response` should be a table with the following keys: * `:headers` - optional headers to write * `:status` - integer status code to write * `:body` - optional byte sequence or iterable (for chunked body) for returning contents. The iterable can be lazy, i.e. for streaming    data.
Community Examples / source
function (spork/http/server handler &opt host port)
Makes a simple http server. By default it binds to 0.0.0.0:8000, returns a new server stream. Simply wraps http/server-handler with a net/server.
Community Examples / source
function (spork/http/server-handler conn handler)
A simple connection handler for an HTTP server. When a connection is accepted. Call this with a handler function to handle the connect. The handler will be called with one argument, the request table, which will contain the following keys: * `:head-size` - number of bytes in the http header. * `:headers` - table mapping header names to header values. * `:connection` - the connection stream for the header. * `:buffer` - the buffer instance that may contain extra bytes. * `:path` - HTTP path. * `:method` - HTTP method, as a string.
Community Examples / source
struct spork/http/status-messages
Mapping of HTTP status codes to their status message.
Community Examples / source
core/peg spork/http/url-grammar
Grammar to parse a URL into domain, port, and path triplet. Only supports the http:// protocol.
Community Examples / source
function (spork/httpf/add-bindings-as-routes server &opt env)
Add all local functions defined with :path metadata to a server. Will read from the :schema, :doc, :path, and :route-doc metadata to determine how the route behaves.
Community Examples / source
function (spork/httpf/add-route server path docstring schema handler &opt read-mime render-mime)
Add a single manually route to a server. Prefer using `httpf/add-bindings-as-routes` for the usual case.
Community Examples / source
function (spork/httpf/default-payload-wrapper payload)
Add some metadata to all responses
Community Examples / source
function (spork/httpf/listen server &opt host port n-workers)
Start server
Community Examples / source
function (spork/httpf/server &opt parent)
Create a new server.
Community Examples / source
cfunction (spork/json/decode json-source &opt keywords nils)
Returns a janet object after parsing JSON. If keywords is truthy, string keys will be converted to keywords. If nils is truthy, null will become nil instead of the keyword :null.
Community Examples /
cfunction (spork/json/encode x &opt tab newline buf)
Encodes a janet value in JSON (utf-8). tab and newline are optional byte sequence which are used to format the output JSON. if buf is provided, the formated JSON is append to buf instead of a new buffer. Returns the modifed buffer.
Community Examples /
keyword spork/mdz/*front-matter*
Dynamic binding to front matter after parsing, compilation, and evaluation, of markup completes.
Community Examples / source
keyword spork/mdz/*markup-dom*
The htmlgen source that can be used to generate a document with htmlgen/html.
Community Examples / source
function (spork/mdz/add-loader )
Allow importing and requiring markup as a module
Community Examples / source
function (spork/mdz/anchor name & content)
Create an in-page anchor for a local link.
Community Examples / source
function (spork/mdz/bigger content)
Make span element with bigger font
Community Examples / source
function (spork/mdz/blockquote content)
Make a block quote element
Community Examples / source
function (spork/mdz/center content)
Center some content
Community Examples / source
function (spork/mdz/code content)
Make code element with class mendoza-code
Community Examples / source
function (spork/mdz/codeblock lang &opt source)
Inline code or codeblock
Community Examples / source
function (spork/mdz/div a div element)
Community Examples / 
function (spork/mdz/em a em element)
Community Examples / 
function (spork/mdz/hr )
Add a horizontal rule
Community Examples / source
function (spork/mdz/html source)
Embed some raw html
Community Examples / source
function (spork/mdz/image src alt)
Make an image element
Community Examples / source
function (spork/mdz/li a li element)
Community Examples / 
function (spork/mdz/link url &opt content)
Create an anchor link
Community Examples / source
function (spork/mdz/markup source &opt env where)
Parse mendoza markup and evaluate it returning an htmlgen document tree.
Community Examples / source
function (spork/mdz/mdz-loader path &)
Loader for the mdz format
Community Examples / source
function (spork/mdz/ol a ol element)
Community Examples / 
function (spork/mdz/p a p element)
Community Examples / 
function (spork/mdz/pre a pre element)
Community Examples / 
function (spork/mdz/section name content)
Create a section. Usually used to embed different parts of the content document into different parts of the main page.
Community Examples / source
function (spork/mdz/smaller content)
Make span element with smaller font
Community Examples / source
function (spork/mdz/strong a strong element)
Community Examples / 
function (spork/mdz/sub a sub element)
Community Examples / 
function (spork/mdz/sup a sup element)
Community Examples / 
function (spork/mdz/tag name content)
Wrap some content in an html tag. If you need attributes or other properties, you may want to use raw HTML via the html function.
Community Examples / source
function (spork/mdz/td a td element)
Community Examples / 
function (spork/mdz/th a th element)
Community Examples / 
function (spork/mdz/tr a tr element)
Community Examples / 
function (spork/mdz/u a u element)
Community Examples / 
function (spork/mdz/ul a ul element)
Community Examples / 
function (spork/misc/always x)
Return a function that discards any arguments and always returns `x`.
Community Examples / source
function (spork/misc/antepenultimate xs)
Get the third-to-last element from an indexed data structure.
Community Examples / source
macro (spork/misc/caperr & body)
Captures the standart error output of the variadic `body` and returns it
as a buffer.
Community Examples / source
macro (spork/misc/capout & body)
Captures the standart output of the variadic `body` and returns it as
a buffer.
Community Examples / source
macro (spork/misc/cond-> val & clauses)
Threading conditional macro. It takes `val` to mutate,
and `clauses` pairs with condition and operation to which the `val`,
is put as first argument. All conditions are tried and
for truthy conditions the operation is executed.
Returns the value mutated if any condition is truthy.
Community Examples / source
macro (spork/misc/cond->> val & clauses)
Threading conditional macro. It takes `val` to mutate,
and `clauses` pairs of condition and operation to which the `val`,
is put as last argument. All conditions are tried and
for truthy the operation is ran.
Returns mutated value if any condition is truthy.
Community Examples / source
function (spork/misc/dedent & xs)
Remove indentation after concatenating the arguments. Works by removing
leading whitespace, and then removing that same pattern of whitepsace after
new lines.
Community Examples / source
macro (spork/misc/defs & bindings)
Defines many constants as in let `bindings`, but without creating new scope.
Community Examples / source
function (spork/misc/dfs data visit-leaf &opt node-before node-after get-children seen)
Do a depth first, pre-order traversal over a data structure.
Also allow for callbacks before and after visiting the children
of a node. Also allow for a custom `get-children` function to
change traversal as needed. Will detect cycles if an empty table
is passed as the `seen` parameter, which is used to cached values
that have been visited.
Community Examples / source
macro (spork/misc/do-def c d & body)
Convenience macro for defining constant named `c` with value `d` before `body`
and returning it after evaluating `body`, that presumably modifies 
the `c` refered content. For example buffer, table or array.
Community Examples / source
macro (spork/misc/do-var v d & body)
Convenience macro for defining varible named `v` with value `d` before `body`
and returning it after evaluating `body`, that presumably modifies `v`.
Community Examples / source
function (spork/misc/format-table buf-into data &opt columns header-mapping column-mapping)
Same as print-table but pushes table into a buffer.
Community Examples / source
macro (spork/misc/gett ds & keys)
Recursive macro (get). Similar to get-in, but keys are variadic argument.
Community Examples / source
function (spork/misc/insert-sorted arr <? & xs)
Insert elements in `arr` such that it remains sorted by the comparator. If
`arr` is not sorted beforehand, the results are undefined. Returns `arr`.
Community Examples / source
function (spork/misc/insert-sorted-by arr f & xs)
Insert elements in `arr` such that it remains sorted by the value returned
when `f` is called with the element, comparing the values with <. If `arr` is
not sorted beforehand, the results are undefined. Returns `arr`.
Community Examples / source
function (spork/misc/int->string int &opt base)
Stringify an integer in a particular base. Defaults to decimal (base 10).
Community Examples / source
function ( )
(int/ & xs)

Perform integer division.
Community Examples / source
macro (spork/misc/log level & args)
Print to a dynamic binding stream if that stream is set, otherwise do
nothing. Evaluate to nil. 
For example, `(log :err "value error: %V" my-value)` will print 
to `(dyn :err)` only if `(dyn :err)` has been set.
Community Examples / source
macro (spork/misc/make prototype & pairs)
Convenience macro for creating new table from even number of kvs pairs in a variadic `table-or-pairs`
arguments and setting its prototype to `prototype`.
Factory function for creating new objects from prototypes.
Community Examples / source
function (spork/misc/make-id &opt prefix)
Create a random, printable keyword id with 10 bytes of entropy
with an optional prefix.
Community Examples / source
function (spork/misc/map-keys f data)
Returns new table with function `f` applied to `data`'s
keys recursively.
Community Examples / source
function (spork/misc/map-vals f data)
Returns new table with function `f` applied to `data`'s values.
Community Examples / source
function (spork/misc/penultimate xs)
Get the second-to-last element from an indexed data structure.
Community Examples / source
function (spork/misc/print-table data &opt columns header-mapping column-mapping)
Iterate through the rows of a data structure and print a table in a human
readable way, with padding and heading information. Can optionally provide
a function use to print a row, as well as optionally select column keys
for each row. Lastly, a `header-mapping` dictionary can be provided that
changes the printed header names by mapping column keys to the desired
header name. If no mapping is found, then the column key will be used as
the header name. Returns nil.
Community Examples / source
function (spork/misc/randomize-array arr &opt rng)
Randomizes array using the fisher-yates shuffle, takes an optional random
number generator.
Community Examples / source
function (spork/misc/second xs)
Get the second element from an indexed data structure.
Community Examples / source
function (spork/misc/select-keys data keyz)
Returns new table with selected `keyz` from dictionary `data`.
Community Examples / source
macro (spork/misc/set* tgts exprs)
Parallel `set` function. Takes a list of targets and
expressions, evaluates all the expressions, and then
assigns them to the targets. Each target can be a variable
or a 2-tuple, just like in the normal `set` special form.
Community Examples / source
function (spork/misc/string->int str &opt base)
Parse an integer in the given base. Defaults to decimal (base 10). Differs
from scan-number in that this does not recognize floating point notation.
Community Examples / source
function (spork/misc/table-filter pred dict)
Filter a key-value structure info a table. Semantics are the same as for
built-in `filter`, except that `pred` takes two arguments (key and value.)
Does not consider prototypes.
Community Examples / source
function (spork/misc/third xs)
Get the third element from an indexed data structure.
Community Examples / source
function (spork/misc/trim-prefix prefix str)
Trim the specified prefix of a string if it has one
Community Examples / source
function (spork/misc/trim-suffix suffix str)
Trim the specified suffix of a string if it has one
Community Examples / source
macro (spork/misc/until cnd & body)
Repeat `body` while the `cnd` is false.
Equivalent to (while (not cnd) ;body).
Community Examples / source
macro (spork/misc/vars & bindings)
Defines many variables as in let `bindings`, but without creating new scope.
Community Examples / source
function (spork/msg/make-proto stream &opt pack unpack)
Create both a send an recv function from a stream, as with `make-send` and `make-recv`.
Community Examples / source
function (spork/msg/make-recv stream &opt unpack)
Get a function that, when invoked, gets the next message from a readable stream. Provide an optional unpack function that will parse the received buffer.
Community Examples / source
function (spork/msg/make-send stream &opt pack)
Create a function that when called with a msgs sends that msg. Provide an optional pack function that will convert a message to a string.
Community Examples / source
function (spork/netrepl/client &opt host port name)
Connect to a repl server. The default host is "127.0.0.1" and the default port is "9365".
Community Examples / source
string spork/netrepl/default-host
Default host to run server on and connect to.
Community Examples / source
string spork/netrepl/default-port
Default port to run the net repl.
Community Examples / source
function (spork/netrepl/server &opt host port env cleanup welcome-msg)
Start a repl server. The default host is "127.0.0.1" and the default port is "9365". Calling this will start a TCP server that exposes a repl into the given env. If no env is provided, a new env will be created per connection. If env is a function, that function will be invoked with the name and stream on each connection to generate an environment. `cleanup` is an optional function that will be called for each stream after closing if provided. `welcome-msg` is an optional string or function (welcome-msg client-name) to generate a message to print for the client on connection.
Community Examples / source
function (spork/netrepl/server-single &opt host port env cleanup welcome-msg)
Short-hand for serving up a a repl that has a single environment table in it. `env` must be a proper env table, not a function as is possible in netrepl/server.
Community Examples / source
function (spork/path/abspath path)
Coerce a path to be absolute.
Community Examples / source
function (spork/path/abspath? path)
Check if a path is absolute.
Community Examples / source
function (spork/path/basename path)
Gets the base file name of a path.
Community Examples / source
string spork/path/delim
Platform delimiter
Community Examples / source
function (spork/path/dirname path)
Gets the directory name of a path.
Community Examples / source
function (spork/path/ext path)
Get the file extension for a path.
Community Examples / source
function (spork/path/join & els)
Join path elements together.
Community Examples / source
function (spork/path/normalize path)
Normalize a path. This removes . and .. in the path, as well as empty path elements.
Community Examples / source
function (spork/path/parts path)
Split a path into its parts.
Community Examples / source
function (spork/path/posix/abspath path)
Coerce a path to be absolute.
Community Examples / source
function (spork/path/posix/abspath? path)
Check if a path is absolute.
Community Examples / source
function (spork/path/posix/basename path)
Gets the base file name of a path.
Community Examples / source
string spork/path/posix/delim
Platform delimiter
Community Examples / source
function (spork/path/posix/dirname path)
Gets the directory name of a path.
Community Examples / source
function (spork/path/posix/ext path)
Get the file extension for a path.
Community Examples / source
function (spork/path/posix/join & els)
Join path elements together.
Community Examples / source
function (spork/path/posix/normalize path)
Normalize a path. This removes . and .. in the path, as well as empty path elements.
Community Examples / source
function (spork/path/posix/parts path)
Split a path into its parts.
Community Examples / source
function (spork/path/posix/relpath source target)
Get the relative path between two subpaths.
Community Examples / source
string spork/path/posix/sep
Platform separator
Community Examples / source
function (spork/path/relpath source target)
Get the relative path between two subpaths.
Community Examples / source
string spork/path/sep
Platform separator
Community Examples / source
function (spork/path/win32/abspath path)
Coerce a path to be absolute.
Community Examples / source
function (spork/path/win32/abspath? path)
Check if a path is absolute.
Community Examples / source
function (spork/path/win32/basename path)
Gets the base file name of a path.
Community Examples / source
string spork/path/win32/delim
Platform delimiter
Community Examples / source
function (spork/path/win32/dirname path)
Gets the directory name of a path.
Community Examples / source
function (spork/path/win32/ext path)
Get the file extension for a path.
Community Examples / source
function (spork/path/win32/join & els)
Join path elements together.
Community Examples / source
function (spork/path/win32/normalize path)
Normalize a path. This removes . and .. in the path, as well as empty path elements.
Community Examples / source
function (spork/path/win32/parts path)
Split a path into its parts.
Community Examples / source
function (spork/path/win32/relpath source target)
Get the relative path between two subpaths.
Community Examples / source
string spork/path/win32/sep
Platform separator
Community Examples / source
cfunction (spork/rawterm/begin &opt on-winch)
Begin raw terminal functionality. Return a stream that can be read from to get input.
Community Examples / source
cfunction (spork/rawterm/buffer-traverse bytes index delta &opt skip-zerowidth)
Move to a new position in a buffer from index by incrementing by `delta` codepoints. Can also skip zero-width codepoints if desired.
Community Examples / source
cfunction (spork/rawterm/ctrl-z )
A handler that a user can use to handle ctrl-z from input to suspend the current process.
Community Examples / source
cfunction (spork/rawterm/end )
End raw terminal functionality.
Community Examples / source
cfunction (spork/rawterm/getch &opt into)
Get a byte of input from stdin, without blocking if possible. Returns a buffer.
Community Examples / source
cfunction (spork/rawterm/isatty )
Check if the current stdin is a tty.
Community Examples / source
cfunction (spork/rawterm/monowidth bytes &opt start-index end-index)
Measure the monospace width of a string.
Community Examples / source
cfunction (spork/rawterm/rune-monowidth rune)
Get the monospace width of a rune. Returns either 0, 1, or 2.
Community Examples / source
cfunction (spork/rawterm/size )
Get the number of rows and columns visible in the terminal as tuple [rows cols]
Community Examples / source
cfunction (spork/rawterm/slice-monowidth bytes columns &opt start-index into)
Get a byte slice that will fit into a number of columns.
Community Examples / source
function (spork/regex/compile pattern)
Compile a subset of regex to a PEG if pattern is a string. If pattern is a PEG, will return the PEG as is.
Community Examples / source
function (spork/regex/find reg text &opt start)
Similar to peg/find, but for regexes.
Community Examples / source
function (spork/regex/find-all reg text &opt start)
Similar to peg/find-all, but for regexes.
Community Examples / source
function (spork/regex/match reg text &opt start)
Similar to peg/match, but for regexes.
Community Examples / source
core/peg spork/regex/peg
Peg used to generate peg source code from a regular expression string.
Community Examples / source
function (spork/regex/replace reg rep text &opt start)
Similar to peg/replace, but for regexes.
Community Examples / source
function (spork/regex/replace-all reg rep text &opt start)
Similar to peg/replace-all, but for regexes.
Community Examples / source
function (spork/regex/source pattern)
Compile a subset of regex to PEG source code.
Community Examples / source
function (spork/rpc/client &opt host port name)
Create an RPC client. The default host is "127.0.0.1" and the default port is "9366". Returns a table of async functions that can be used to make remote calls. This table also contains a :close function that can be used to close the connection.
Community Examples / source
string spork/rpc/default-host
Default host to run server on and connect to.
Community Examples / source
string spork/rpc/default-port
Default port to run the net repl.
Community Examples / source
function (spork/rpc/server functions &opt host port workers-per-connection)
Create an RPC server. The default host is "127.0.0.1" and the default port is "9366". Also must take a dictionary of functions that clients can call.
Community Examples / source
function (spork/schema/make-predicate schema)
Generate a function that can be used to validate a data structure. This is the function form of `predicate`.
Community Examples / source
function (spork/schema/make-validator schema)
Generate a function that can be used to validate a data structure. This is the function form of `validator`.
Community Examples / source
macro (spork/schema/predicate pattern)
Make a validation predicate given a certain schema.
Community Examples / source
macro (spork/schema/validator pattern)
Make a validation function of one argument. A validation function will throw an error on validation failure, otherwise, it will return the argument.
Community Examples / source
keyword spork/services/*current-manager*
The currently running service manager, if there is one
Community Examples / source
keyword spork/services/*current-service*
The currently running service, if there is one
Community Examples / source
function (spork/services/add-service service-name main-function & args)
Spawn a service
Community Examples / source
function (spork/services/all-services )
Get a list of running services
Community Examples / source
function (spork/services/get-manager )
Get the current manager. If no manager exists, create one.
Community Examples / source
function (spork/services/get-service )
Get the current service. If not in a service, raise an error
Community Examples / source
function (spork/services/make-manager &opt log-dir)
Group a number of fibers into a single object for structured concurrency. Also includes utilities for running services like servers in the background.
Community Examples / source
function (spork/services/print-all &opt filter-fn)
Print a table of all running services.
Community Examples / source
function (spork/services/remove-service service-name)
Remove a service
Community Examples / source
function (spork/services/set-title title)
Set a textual description of the service to describe what it is doing currently
Community Examples / source
function (spork/services/start-service service-name)
Start or restart a service
Community Examples / source
function (spork/services/stop-service service-name &opt reason)
Stop a running service
Community Examples / source
function (spork/services/wait )
Once a number of services have been spawned, call `wait` to block the fiber until the manager is canceled. This lets a manager fiber behave as a service itself.
Community Examples / source
function (spork/sh/copy src dest)
Copy a file or directory recursively from one location to another.
Expects input to be unix style paths
Community Examples / source
function (spork/sh/copy-file src-path dst-path)
Copy a file from source to destination. Creates all directories in the path to the destination file if they do not exist.
Community Examples / source
function (spork/sh/create-dirs dir-path)
Create all directories in path specified as string including itself.
Community Examples / source
function (spork/sh/devnull )
get the /dev/null equivalent of the current platform as an open file
Community Examples / source
function (spork/sh/exec & args)
Execute command specified by args returning it's exit code
Community Examples / source
function (spork/sh/exec-fail & args)
Execute command specified by args, fails when command exits with non-zero exit code
Community Examples / source
function (spork/sh/exec-slurp & args)
Read stdout of command specified by args and return it trimmed in a string.
Community Examples / source
function (spork/sh/exec-slurp-all & args)
Read stdout and stderr of subprocess and return it trimmed in a struct with :err and :out containing the output as string.
This will also return the exit code under the :status key.
Community Examples / source
function (spork/sh/exists? path)
Check if the given file or directory exists. (Follows symlinks)
Community Examples / source
function (spork/sh/list-all-files dir &opt into)
List the files in the given directory recursively. Return the paths to all files found, relative to the current working directory if the given path is a relative path, or as an absolute path otherwise.
Community Examples / source
function (spork/sh/make-new-file file-path &opt mode)
Create and open a file, creating all the directories leading to the file if they do not exist, and return it. By default, open as a writable file (mode is `:w`).
Community Examples / source
function (spork/sh/rm path)
Remove a directory and all sub directories recursively.
Community Examples / source
function (spork/sh/scan-directory dir func)
Scan a directory recursively, applying the given function on all files and directories in a depth-first manner. This function has no effect if the directory does not exist.
Community Examples / source
cfunction (spork/tarray/buffer array|size)
Return typed array buffer or create a new buffer.
Community Examples /
cfunction (spork/tarray/copy-bytes src sindex dst dindex &opt count)
Copy count elements (default 1) of src array from index sindex to dst array at position dindex memory can overlap.
Community Examples /
cfunction (spork/tarray/length array|buffer)
Return typed array or buffer size.
Community Examples /
cfunction (spork/tarray/new type size &opt stride offset tarray|buffer)
Create new typed array.
Community Examples /
cfunction (spork/tarray/properties array)
Return typed array properties as a struct.
Community Examples /
cfunction (spork/tarray/slice tarr &opt start end)
Takes a slice of a typed array from start to end. The range is half open, [start, end). Indexes can also be negative, indicating indexing from the end of the end of the typed array. By default, start is 0 and end is the size of the typed array. Returns a new janet array.
Community Examples /
cfunction (spork/tarray/swap-bytes src sindex dst dindex &opt count)
Swap count elements (default 1) between src array from index sindex and dst array at position dindex memory can overlap.
Community Examples /
function (spork/tasker/all-tasks tasker &opt detailed)
Get an array of all task ids for which there is still data on disk. If `detailed` is truthy, return full task metadata instead of ids.
Community Examples / source
function (spork/tasker/cancel-task tasker task-id)
Cancel a queued or running task.
Community Examples / source
function (spork/tasker/close-queues tasker)
Prevent any tasks from being added to queues. When an executor finishes it's current job, if there are any, it will terminate. When all executors complete, the call to `run-executors` will complete.
Community Examples / source
number spork/tasker/default-expiration
Default expiration time (1 day)
Community Examples / source
number spork/tasker/default-priority
Default task priority
Community Examples / source
string spork/tasker/default-task-directory
Default location of task records
Community Examples / source
string spork/tasker/err-file-name
Name of the file for logging errors
Community Examples / source
number spork/tasker/max-priority
Maximum allowed priority (lower priority tasks will execute first)
Community Examples / source
number spork/tasker/min-priority
Minimum allowed priority (lower priority tasks will execute first)
Community Examples / source
function (spork/tasker/new-tasker &opt task-directory queues queue-size)
Create queues and various settings to run tasks. Create a new tasker table.
Community Examples / source
string spork/tasker/out-file-name
Name of the file for general logging
Community Examples / source
function (spork/tasker/queue-task tasker argv &opt note priority qname timeout expiration input)
Add a task specification to a queue. Supply an argv string array that will be used to invoke s a subprocess. The optional `note` parameter is just a textual note for task trackingv. The `priority` parameter should be an integer between 0 and 9 inclusive, default is 4. Lower priority jobs in the same queue will be executed by higher priority. Use input to pass in generic, unstructured input to a task.
Community Examples / source
function (spork/tasker/run-cleanup tasker)
Delete old expired jobs saved on disk
Community Examples / source
function (spork/tasker/run-executors tasker &opt workers-per-queue pre-task post-task)
Start a number of executors to run tasks as with `tasker/spawn-executors`, and then wait for all executors to complete.
Community Examples / source
function (spork/tasker/spawn-executors tasker &opt qnames workers-per-queue pre-task post-task)
Start a number of executors to run tasks. Tasks can be added to a queue by calling queue-task. A single tasker object can make multiple calls to spawn-executors.
Community Examples / source
tuple spork/tasker/statuses
A tuple of all possible statuses that a task can have.
Community Examples / source
function (spork/tasker/task-file tasker task-id &opt file-name)
Get a log file for a path. By default, will get a path to out.log.
Community Examples / source
string spork/tasker/task-meta-name
Name of the task metadata file
Community Examples / source
function (spork/tasker/task-status tasker task-id)
Look up the status of a given task by id.
Community Examples / source
function (spork/temple/add-loader )
Adds the custom template loader to Janet's module/loaders and update module/paths.
Community Examples / source
table spork/temple/base-env
Base environment for rendering
Community Examples / source
function (spork/temple/compile str)
Compile a Temple template into a function which will return a
rendered buffer.

The resulting function should receive the template arguments in the
&keys format.
Community Examples / source
function (spork/temple/create source &opt where)
Compile a template string into a function. Optionally provide a location where the source is from to improve debugging. Returns the template function.
Community Examples / source
macro (spork/test/assert x &opt e)
Override's the default assert with some nice error handling.
Community Examples / source
function (spork/test/assert-docs path)
Assert that all symbols, when module on the path is required,
have proper doc string
Community Examples / source
macro (spork/test/assert-error msg & forms)
Test passes if forms error.
Community Examples / source
macro (spork/test/assert-no-error msg & forms)
Test passes if forms do not error.
Community Examples / source
macro (spork/test/assert-not x &opt e)
Invert assert.
Community Examples / source
macro (spork/test/capture-stderr & body)
Runs the form and captures stderr. Returns tuple with result of the form
and a string with captured stderr.
Community Examples / source
macro (spork/test/capture-stdout & body)
Runs the form and captures stdout. Returns tuple with result of the form
and a string with captured stdout.
Community Examples / source
function (spork/test/end-suite )
Ends test suite, prints summary and exits if any have failed.
Community Examples / source
function (spork/test/start-suite &opt name)
Starts test suite.
Community Examples / source
macro (spork/test/suppress-stderr & body)
Suppreses stdout from the body
Community Examples / source
macro (spork/test/suppress-stdout & body)
Suppreses stdout from the body
Community Examples / source
macro (spork/test/timeit form &opt tag)
Time the execution of `form` using `os/clock` before and after,
and print the result to stdout. returns: result of executing `form`.
Uses `tag` (default "Elapsed time:") to tag the printout.
Community Examples / source
cfunction (spork/utf8/decode-rune buf &opt start)
Read a UTF-8 encoded Unicode codepoint from the buffer which starts at the given index. Returns a tuple [value width], where width = number of bytes consumed. If at the end of buffer or the buffer contains malformed UTF-8, returns [nil 0].
Community Examples / source
cfunction (spork/utf8/encode-rune rune &opt buf)
Encode a Unicode codepoint into the end of a buffer.
Community Examples / source
cfunction (spork/utf8/prefix->width c)
Given the first byte in an UTF-8 sequence, get the number of bytes that the codepoint sequence takes up, including the prefix byte.
Community Examples / source
cfunction (spork/zip/add-bytes writer path data &opt comment flags)
Add a byte sequence to the zip writer.
Community Examples / source
cfunction (spork/zip/add-file writer path filename &opt comment flags)
Add a file to the zip writer.
Community Examples / source
cfunction (spork/zip/compress bytes &opt level into)
Compress data and write to a buffer. Different compression levels can be used - higher compression levels trade smaller output with longer compression times. Returns `into`. If `into` not provided, a new buffer is created.
Community Examples / source
cfunction (spork/zip/decompress bytes &opt into)
Decompress data and write to a buffer. If an `into` buffer is not provided, a new buffer will be created.
Community Examples / source
cfunction (spork/zip/extract reader idx-or-filename &opt into flags)
Extract a file from the zip archive, either to memory or to a file on disk.
Community Examples / source
cfunction (spork/zip/file-directory? reader idx)
Check if a file index is a directory.
Community Examples / source
cfunction (spork/zip/file-encrypted? reader idx)
Check if a file is encrypted inside an archive.
Community Examples / source
cfunction (spork/zip/file-supported? reader idx)
Check if a file is supported with this verstion of miniz.
Community Examples / source
cfunction (spork/zip/get-filename reader idx)
Convert a file index index in the archive to a filename.
Community Examples / source
cfunction (spork/zip/locate-file reader path &opt comment flags)
Get the index of a particular filename in the archive.
Community Examples / source
cfunction (spork/zip/read-bytes bytes &opt flags)
Read a byte sequence as a zip archive. Returns a new zip reader.
Community Examples / source
cfunction (spork/zip/read-file filename &opt flags)
Read a file as a zip archive. Returns a new zip reader.
Community Examples / source
cfunction (spork/zip/reader-close reader)
Close a reader and free related memory.
Community Examples / source
cfunction (spork/zip/reader-count reader)
Get the number of files inside the zip archive. The files can be indexed 
Community Examples / source
cfunction (spork/zip/stat reader idx)
Get stat information of file. Returns a new struct with the following fields:

* :index - integer index in master directory
* :version-made-by - zip verstion
* :version-needed - zip version needed to unzip
* :bit-flag
* :method - compression method
* :time - file time
* :crc32 - checksum of file contents
* :comp-size - size of file when compressed
* :uncomp-size - size of file when uncompressed
* :filename
* :comment
* :internal-attr
* :external-attr
Community Examples / source
cfunction (spork/zip/version )
Get the version string of the underlying miniz library.
Community Examples / source
cfunction (spork/zip/write-buffer )
Create a new zip archive writer that write to memory.
Community Examples / source
cfunction (spork/zip/write-file dest-path)
Create a new zip archive writer that will write into an archive file.
Community Examples / source
cfunction (spork/zip/writer-close writer)
Close a ZipWriter.
Community Examples / source
cfunction (spork/zip/writer-finalize writer)
Finalize a writer, writing any zip files to disk. Return the writer.
Community Examples / source