easyjevko.js is a JavaScript library for Easy Jevko -- a simple data format built on Jevko.
The library can convert between something like this:
id [johnny]
display name [John Doe]
organization id [megacorp]
follower ids [
[roger]
[alice]
[bob]
]
and something like this:
{
"id": "johnny",
"display name": "John Doe",
"organization id": "megacorp",
"follower ids": ["roger", "alice", "bob"]
}
See library functions.
Easy Jevko can serve as a simple configuration, interchange, or serialization format or as a template for building more advanced formats on top of Jevko.
To try out the library immediately without installing it, you can use the REPL (read–eval–print loop, aka interactive shell) of your JavaScript runtime. Below are instructions for Node.js and Deno.
Note: this requires a version of Node.js which supports the --experimental-network-imports
flag (v17 or up).
Start the REPL by running the following in the terminal:
node --experimental-network-imports
Start the REPL by running the following in the terminal:
deno
Paste the following into the REPL:
const {fromString} = await import('https://cdn.jsdelivr.net/gh/jevko/easyjevko.js/bundle.js')
fromString(`
id [johnny]
display name [John Doe]
organization id [megacorp]
follower ids [
[roger]
[alice]
[bob]
]
`)
The result should be something like:
{
"id": "johnny",
"display name": "John Doe",
"organization id": "megacorp",
"follower ids": ["roger", "alice", "bob"]
}
This imports the latest version of easyjevko.js from github via jsDelivr, extracts the fromString function from it and calls it on a string, obtaining a JS object as a result.
The examples install version 0.1.4
. Adjust as needed.
Note: requires Node.js >= 13.2.0.
npm install jevko/easyjevko.js#semver:0.1.4
Then either use a dynamic import:
import("easyjevko.js").then(({fromString, toString}) => {
console.log(fromString('a [b]')) // -> {"a": "b"}
})
or, if you have ECMAScript modules enabled, simply:
import {fromString, toString} from "easyjevko.js"
console.log(fromString('a [b]')) // -> {"a": "b"}
Import from jsDelivr:
import {fromString, toString} from 'https://cdn.jsdelivr.net/gh/jevko/[email protected]/mod.js'
Input: string which contains a Jevko.
Description:
- A Jevko without subjevkos is converted to a string.
- A Jevko with subjevkos is converted to an array or an object. The first subjevko decides which:
- If the first subjevko has empty or whitespace-only prefix then the Jevko will be converted to an array.
- Otherwise the Jevko will be converted to an Object.
- Leading and trailing spaces in object keys are ignored.
Output: JavaScript object/array/string.
fromString('a [b]') // -> {"a": "b"}
Input: JavaScript object/array/string, arbitrarily nested.
Restrictions: empty arrays and objects are not allowed. Empty keys or keys with leading and trailing spaces in objects are not allowed.
Output: pretty-printed string which contains a Jevko.
toString({"a": "b"}) // -> 'a [b]'
Input: a Jevko, as returned by parseJevko
.
Description:
- A Jevko without subjevkos is converted to a string.
- A Jevko with subjevkos is converted to an array or an object. The first subjevko decides which:
- If the first subjevko has empty or whitespace-only prefix then the Jevko will be converted to an array.
- Otherwise the Jevko will be converted to an Object.
- Leading and trailing spaces in object keys are ignored.
Output: JavaScript object/array/string.
fromJevko(parseJevko('a [b]')) // -> {"a": "b"}
Input: JavaScript object/array/string, arbitrarily nested.
Restrictions: empty arrays and objects are not allowed. Empty keys or keys with leading and trailing spaces in objects are not allowed.
Output: a Jevko.
toJevko({"a": "b"}) // -> {"subjevkos":[{"prefix":"a","jevko":{"subjevkos":[],"suffix":"b"}}],"suffix":""}
© 2022 Jevko.org