2.0.2 • Published 1 year ago

edn-parser-js v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

edn-parser-js

npm package Build Status

EDN parser library for JS/TS.

Rationaly

There are a number of existing EDN parsers for JS/TS. But I'm not aware of one that supports all EDN features that modern Clojure could emit/parse. First of all, it's namespaced maps introduced in Clojure 1.9

This parser is trying to support everything that Clojure could emit and parse using clojure.edn, even if it's not in EDN "spec". It includes namespaced maps, | in symbols/keywords, metadata parsing.

Types mapping

EDN TypeTS TypeEDN ValueJS Value
integer/floatnumber123123
nilnullnilnull
booleanbooleantruetrue
stringstring"hello""hello!"
char{ char: string }\a{ char: "a" }
symbol{ symbol: string; ns?: string }foo{ symbol: "foo" }
bar/foo{ symbol: "foo", ns: "bar" }
keyword{ keyword: string; ns?: string }:foo{ keyword: "foo" }
:bar/foo{ keyword: "foo", ns: "bar" }
vector{ list: EDN[] }1 2 3{ list: 1, 2, 3 }
map{ map: EDN, EDN }{"hello" "world}{ map: ["hello", "world"]}
set{ set: EDN[] }#{1 2 3}{ set: 1, 2, 3 }
list{ list: EDN[] }(1 2 3){ list: 1, 2 ,3 }
^meta ...{ meta: EDN, EDN; value: EDN }^{"comment": "hi"} []{ meta: {"comment": "hi"}, value: List()}

Install

npm install edn-parser-js

Usage

import { ednParse } from 'edn-parser-js';

ednParse('{:hello "world"}');
//=> Map(1) { { keyword: 'hello' } => 'world' }

API

export type EDNSymbol = { symbol: string; ns?: string };

export type EDN =
  | number
  | null
  | boolean
  | string
  | EDNSymbol
  | { keyword: string; ns?: string }
  | { char: string }
  | EDN[]
  | { map: [EDN, EDN][] }
  | { set: EDN[] }
  | { list: EDN[] }
  | { tag: EDNSymbol; value: EDN }
  | { meta: [EDN, EDN][]; value: EDN };

ednParse(string): EDN

ednParseMulti(string): EDN[]

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago