npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

edn-data

v1.1.2

Published

EDN parser and generator that work with plain JS data, with support for TS and node streams

Downloads

229,490

Readme

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