GithubHelp home page GithubHelp logo

jevko / easyjevko.js Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 65 KB

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

License: MIT License

JavaScript 100.00%
easy format jevko easyjevko

easyjevko.js's Introduction

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

easyjevko.js's People

Contributors

djedr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.