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

coffeeson

v0.1.0

Published

Like json, but with coffee script

Downloads

26

Readme

COFFESON

Coffeeson is a little syntax that compiles into JSON. Underneath all those awkward braces and commas, JSON has always had a gorgeous data format at its heart. Coffeeson is an attempt to expose the good parts of JSON in a more human maintainable way.

;)

Why?

JSON is an awesome data exchange format. But when a human has to maintain it, it's not quite so awesome. Balanced braces, commas everywhere, and quoted key names make maintenance a bit tricky.

Coffeeson aims to solve that. JavaScript powered applications, like node.js servers and the like, tend to use json files as configuration. Humans write these files, but machines read them.

It is not meant to be a data exchange format, there is no way to save data as Coffeeson, only to convert it to JSON or parse it as JavaScript. This is intentional. You should still use JSON for machine -> machine data transmision.

SECURITY WARNING!

Since it's designed for humans editing trusted files, it is much less secure than JSON. Self executing functions will be run as coffee script parses the file. So don't accept and parse Coffeeson from untrusted sources, that's what JSON is for.

Installation

npm install coffeeson

Syntax

So with that out of the way...

It works just like CoffeeScript, since it is CoffeeScript. Simply start listing keys of the root level object at the lowest indent level.

pre: 123
a:
  b:
    c: '456'
  d: [
    7
    8
    e:
      f: 'g'
  ]

That snippet would compile into this JSON.

{
  "pre": 123,
  "a": {
    "b": {
      "c": "456"
    },
    "d": [
      7,
      8,
      {
        "e": {
          "f": "g"
        }
      }
    ]
  }
}

Usage

(Examples will assume you are using coffee script. Because if you aren't, chances are you are fine with JSON as it is.)

With the npm module installed, simply require it.

coffeeson = require 'coffeeson'

API

.parse(coffeesonString)

Simply parse a coffeeson string and return a JS native object.

coffeeson.parse('a:123').a #=> 123

.parseFile(path, callback(err, result))

Asynchronously parse a coffeeson file and return a JS native object.

coffeeson.parseFile 'config.coffeeson', (err, result) ->
  result.a #=> 123

.toJSON(src)

Parse a coffeeson string and return an equivalent JSON string.

coffeeson.toJSON 'a:123' #=> '{"a":123}'

.toJSON.pretty(src)

Parse a coffeeson string and return an equivalent JSON string, nicely indented.

coffeeson.toJSON.pretty 'a:b:123' #=> '''
                                      {
                                        "a": {
                                          "b": 123
                                        }
                                      }
                                      '''

.fileToJSON(path, callback(err, json))

Asynchronously read a file and callback with the content as JSON.

coffeeson.fileToJSON 'config.coffeeson', (err, json) ->
  json #=> '{"a":{"b":123}}'

.fileToJSON.pretty(path, callback(err, json))

Asynchronously read a file and callback with the content as pretty and indented JSON.

coffeeson.fileToJSON.pretty 'config.coffeeson', (err, json) ->
  json #=> '''
           {
             "a": {
               "b": 123
             }
           }
           '''

.convertFile(path, [callback(err)])

Asynchronously read a file and save a .json file right next the source file.

coffeeson.convertFile 'config.coffeeson', (err) ->
  # "config.json" now contains JSON version of "config.coffeeson"

.convertFile.pretty(path, [callback(err)])

Asynchronously read a file and save a pretty and indented .json file right next the source file. Works exactly like convertFile()

coffeeson.convertFile.pretty 'config.coffeeson', (err) ->
  # "config.json" now contains pretty JSON version of "config.coffeeson"