Skip to content

A JavaScript library for Easy Jevko -- a simple data format built on Jevko.

License

Notifications You must be signed in to change notification settings

jevko/easyjevko.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

easyjevko.js

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.

Applications

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.

Ultraquickstart: Node.js or Deno REPL

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.

Step 1. Start the REPL

a) Node.js variant

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

b) Deno variant

Start the REPL by running the following in the terminal:

deno

Step 2.

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.

Installation

The examples install version 0.1.4. Adjust as needed.

Node.js

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"}

Deno and the browser

Import from jsDelivr:

import {fromString, toString} from 'https://cdn.jsdelivr.net/gh/jevko/[email protected]/mod.js'

Library functions

fromString

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"}

toString

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]'

fromJevko

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"}

toJevko

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":""}

MIT License

© 2022 Jevko.org

About

A JavaScript library for Easy Jevko -- a simple data format built on Jevko.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published