All Projects → jorinvo → Edn Data

jorinvo / Edn Data

Licence: mit
EDN parser and generator that works with plain JS data, with support for TS and node streams

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
clojure
4091 projects

Projects that are alternatives of or similar to Edn Data

Java
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go
Stars: ✭ 1,308 (+2872.73%)
Mutual labels:  parser, serialization
Go
A high-performance 100% compatible drop-in replacement of "encoding/json"
Stars: ✭ 10,248 (+23190.91%)
Mutual labels:  parser, serialization
Edn format
EDN reader and writer implementation in Python, using PLY (lex, yacc)
Stars: ✭ 92 (+109.09%)
Mutual labels:  serialization, edn
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+1800%)
Mutual labels:  parser, serialization
Parse5
HTML parsing/serialization toolset for Node.js. WHATWG HTML Living Standard (aka HTML5)-compliant.
Stars: ✭ 2,778 (+6213.64%)
Mutual labels:  parser, serialization
Yamldotnet
YamlDotNet is a .NET library for YAML
Stars: ✭ 1,382 (+3040.91%)
Mutual labels:  parser, serialization
Mini Yaml
Single header YAML 1.0 C++11 serializer/deserializer.
Stars: ✭ 79 (+79.55%)
Mutual labels:  parser, serialization
Rapidyaml
Rapid YAML - a library to parse and emit YAML, and do it fast.
Stars: ✭ 183 (+315.91%)
Mutual labels:  parser, serialization
Eden
edn (extensible data notation) encoder/decoder for Elixir
Stars: ✭ 32 (-27.27%)
Mutual labels:  serialization, edn
Nippy
High-performance serialization library for Clojure
Stars: ✭ 838 (+1804.55%)
Mutual labels:  serialization, edn
Donerserializer
A C++14 JSON Serialization Library
Stars: ✭ 31 (-29.55%)
Mutual labels:  serialization
Parsley
An exceptionally fast parser combinator library for Scala
Stars: ✭ 31 (-29.55%)
Mutual labels:  parser
Goawk
A POSIX-compliant AWK interpreter written in Go
Stars: ✭ 995 (+2161.36%)
Mutual labels:  parser
Quilt
Quilt is a self-organizing data hub for S3
Stars: ✭ 1,007 (+2188.64%)
Mutual labels:  serialization
Pbparser
Golang library for parsing protocol buffer (.proto) files
Stars: ✭ 30 (-31.82%)
Mutual labels:  parser
Google Libphonenumber
The up-to-date and reliable Google's libphonenumber package for node.js.
Stars: ✭ 984 (+2136.36%)
Mutual labels:  parser
Ssp
C++ CSV parser
Stars: ✭ 30 (-31.82%)
Mutual labels:  parser
Mysqllog
Lightweight MySQL slow query log parser in Go
Stars: ✭ 29 (-34.09%)
Mutual labels:  parser
Adenium
Adenium Normalizer
Stars: ✭ 29 (-34.09%)
Mutual labels:  parser
Serd
A lightweight C library for RDF syntax
Stars: ✭ 43 (-2.27%)
Mutual labels:  parser

edn-data

edn-data is a JavaScript and TypeScript library that provides functionality to generate and parse data in the EDN format, as known from Clojure land.

Why create another library for working with EDN?

  • Support TypeScript with a strictly typed interface
  • Support the rich EDN types
  • Allow working with plain data in JavaScript, so everything can also be serialized to JSON
  • Support modern JavaScript types such as Map, Set and bigint
  • Support streaming EDN lists as standard Node stream in Node.js
  • Have a solution that works in Node.js and in browsers

Why work with EDN in JavaScript or TypeScript?

The number one reason is, your code wants to interact with data coming from Clojure.

But even outside Clojure EDN can be a compelling data format in a world where developers are stuck fighting YAML and complaining about JSON.

EDN has:

  • less syntax than JSON
  • built-in data types to represent maps, sets, keywords, dates, uuids, chars, bigints, ...
  • multi-line strings
  • tags and symbols to represent rich, custom data types
  • comments
  • streaming parsers
  • no relevant whitespace

Get started

Install with:

npm install edn-data

Parsing EDN

By default parsing returns JSON-compatible data structures that can represent all of the rich EDN types.

There are options to make it easier to parse simpler types.

import { parseEDNString } from 'edn-data'

parseEDNString('{:key "value" :list [1 2 3]}')
// Returns:
{
  map: [
    [{ key: 'key' }, 'value'],
    [{ key: 'list' }, [1, 2, 3]],
  ],
}

parseEDNString(
  '{:key "value" :list [1 2 3]}',
  { mapAs: 'object', keywordAs: 'string' },
)
// Returns:
{
  key: 'value',
  list: [1, 2, 3],
}

EDN lists can be streamed value by value as standard Node.js Readable streams. This is not available in the browser.

import { parseEDNListStream } from 'edn-data/stream'

const s = parseEDNListStream()
s.write('(1 2 3)')
s.read() // 1
s.read() // 2
s.read() // 3

Generating EDN

EDN is generated from plain JSON structures.

With toEDNString the same data structures parseEDNString returns can be turned to valid strings, and they represent a rich set of types.

For simple JavaScript types often toEDNStringFromSimpleObject might be the simpler use.

import { toEDNString, toEDNStringFromSimpleObject } from 'edn-data';

toEDNString({
  map: [
    [1, { key: 'keyword' }],
    [{ set: [1, 2] }, { char: 'a' }],
  ],
})
// Returns:
'{1 :keyword #{1 2} \a}'

toEDNStringFromSimpleObject({ first: 1, second: 2 })
// Returns:
'{:first 1 :second 2}'

Development

The library is developed driven by its tests.

Verify them using

npm test

For continuous development use

npm run test:watch

Ensure the code formatting with

npm run fix

CI verifies tests and creates npm releases for tags automatically.

Publish a new version

  1. Change the version in the package.json
  2. Push a commit to master in the following form Release <version>
  3. A Git tag will be created and the new version will be published to NPM

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].