• Stars
    star
    1,333
  • Rank 34,099 (Top 0.7 %)
  • Language
    CoffeeScript
  • License
    Other
  • Created almost 13 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CoffeeScript-Object-Notation. Same as JSON but for CoffeeScript objects.

CSON

Travis CI Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
GitHub Sponsors donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

CoffeeScript-Object-Notation. Same as JSON but for CoffeeScript objects.

Projects using CSON.

Projects using CSON Parser directly.

Since v2, this CSON package is a higher-level wrapper around the lower-level CSON Parser.

What is CSON?

Everyone knows JSON, it's the thing that looks like this:

{
  "greatDocumentaries": [
    "earthlings.com",
    "forksoverknives.com",
    "cowspiracy.com"
  ],
  "importantFacts": {
    "emissions": "Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.\nGoodland, R Anhang, J. “Livestock and Climate Change: What if the key actors in climate change were pigs, chickens and cows?”\nWorldWatch, November/December 2009. Worldwatch Institute, Washington, DC, USA. Pp. 10–19.\nhttp://www.worldwatch.org/node/6294",
    "landuse": "Livestock covers 45% of the earth’s total land.\nThornton, Phillip, Mario Herrero, and Polly Ericksen. “Livestock and Climate Change.” Livestock Exchange, no. 3 (2011).\nhttps://cgspace.cgiar.org/bitstream/handle/10568/10601/IssueBrief3.pdf",
    "burger": "One hamburger requires 660 gallons of water to produce – the equivalent of 2 months’ worth of showers.\nCatanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.\nhttp://blog.epa.gov/healthywaters/2012/03/virtual-water-real-impacts-world-water-day-2012/\n“50 Ways to Save Your River.” Friends of the River.\nhttp://www.friendsoftheriver.org/site/PageServer?pagename=50ways",
    "milk": "1,000 gallons of water are required to produce 1 gallon of milk.\n“Water trivia facts.” United States Environmental Protection Agency.\nhttp://water.epa.gov/learn/kids/drinkingwater/water_trivia_facts.cfm#_edn11",
    "more": "http://cowspiracy.com/facts"
  }
}

Now let's write the same thing in CSON:

# Comments!!!

# An Array with no commas!
greatDocumentaries: [
	'earthlings.com'
	'forksoverknives.com'
	'cowspiracy.com'
]

# An Object without braces!
importantFacts:
	# Multi-Line Strings! Without Quote Escaping!
	emissions: '''
		Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.
		Goodland, R Anhang, J. “Livestock and Climate Change: What if the key actors in climate change were pigs, chickens and cows?”
		WorldWatch, November/December 2009. Worldwatch Institute, Washington, DC, USA. Pp. 10–19.
		http://www.worldwatch.org/node/6294
		'''

	landuse: '''
		Livestock covers 45% of the earth’s total land.
		Thornton, Phillip, Mario Herrero, and Polly Ericksen. “Livestock and Climate Change.” Livestock Exchange, no. 3 (2011).
		https://cgspace.cgiar.org/bitstream/handle/10568/10601/IssueBrief3.pdf
		'''

	burger: '''
		One hamburger requires 660 gallons of water to produce – the equivalent of 2 months’ worth of showers.
		Catanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.
		http://blog.epa.gov/healthywaters/2012/03/virtual-water-real-impacts-world-water-day-2012/
		“50 Ways to Save Your River.” Friends of the River.
		http://www.friendsoftheriver.org/site/PageServer?pagename=50ways
		'''

	milk: '''
		1,000 gallons of water are required to produce 1 gallon of milk.
		“Water trivia facts.” United States Environmental Protection Agency.
		http://water.epa.gov/learn/kids/drinkingwater/water_trivia_facts.cfm#_edn11
		'''

	more: 'http://cowspiracy.com/facts'

Which is far more lenient than JSON, way nicer to write and read, no need to quote and escape everything, has comments and readable multi-line strings, and won't fail if you forget a comma.

Using CSON

Via the Command Line

Use CSON with the command line with:

# Convert a JSON file into a CSON file
json2cson in.json > out.cson
# Same thing via piping
cat in.json | json2cson > out.cson

# Convert a CSON file into a JSON file
cson2json in.cson > out.json
# Same thing via piping
cat in.cson | cson2json > out.json

Requires a global CSON install: npm install -g cson

Via the API

Include CSON:

var CSON = require('cson')

Each method can be executed without a callback like so:

var result = CSON.createCSONString({a:{b:'c'}}, {/* optional options argument */})
if ( result instanceof Error ) {
	console.log(result.stack)
} else {
	console.log(result)
}

Or via a callback like so:

CSON.createCSONString({a:{b:'c'}}, {/* optional options argument */}, function(err,result){
	console.log(err, result)
})

Executing the method with a callback still executes the method synchronously.

Click the below function names to open more detailed documentation.

Create Strings

Parse Strings

Parse Files

Require Files

Install

npm

Install Globally

  • Install: npm install --global cson
  • Executables: cson2json, json2cson

Install Locally

  • Install: npm install --save cson
  • Executables: npx cson2json, npx json2cson
  • Import: import * as pkg from ('cson')
  • Require: const pkg = require('cson')

Editions

This package is published with the following editions:

History

Discover the release history by heading on over to the HISTORY.md file.

Contribute

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

GitHub Sponsors donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

License

Unless stated otherwise all works are:

and licensed under:

More Repositories

1

watchr

Better file system watching for Node.js. Provides a normalised API the file watching APIs of different node versions, nested/recursive file and directory watching, and accurate detailed events for file/directory changes, deletions and creations.
JavaScript
540
star
2

caterpillar

Caterpillar is the ultimate logging system for Deno, Node.js, and Web Browsers. Log levels are implemented to the RFC standard. Log entries can be filtered and piped to various streams, including coloured output to the terminal, the browser's console, and debug files. You can even write your own transforms.
TypeScript
400
star
3

staticsitegenerators-website

Website containing the complete listing of static site generators
TypeScript
364
star
4

getmac

Get the mac address of the current machine you are on via Node.js
TypeScript
347
star
5

query-engine

QueryEngine provides extensive Querying, Filtering, and Searching abilities for Backbone.js Collections as well as JavaScript arrays and objects
CoffeeScript
329
star
6

projectz

Stop wasting time maintaining your project's readme and package files! Let Projectz do it for you.
TypeScript
262
star
7

dorothy

🧙🏻‍♀️ Bring your dotfile commands and configuration to any shell. Sensible defaults and hundreds of commands preloaded. Supports Bash, Zsh, Fish, Nu, Xonsh, Elvish, Dash, KornShell, macOS, Linux, Windows.
Shell
261
star
8

staticsitegenerators-list

A comprehensive, partially automatically generated comparison of static site generators
TypeScript
222
star
9

istextorbinary

Determine if a filename and/or buffer is text or binary. Smarter detection than the other solutions.
TypeScript
145
star
10

badges

The definitive rendering collection of badges
TypeScript
110
star
11

editions

📦 The best way to produce and consume the JavaScript packages you care about.
TypeScript
61
star
12

envfile

Parse and write environment files with Node.js
TypeScript
58
star
13

taskgroup

Group together synchronous and asynchronous tasks and execute them with support for concurrency, naming, and nesting.
JavaScript
49
star
14

typechecker

Utilities to get and check variable types (isString, isPlainObject, isRegExp, etc)
TypeScript
47
star
15

make-deno-edition

Automatically makes package.json projects (such as npm packages and node.js modules) compatible with Deno.
TypeScript
41
star
16

kava

Kava has been powering accurate test suites in node.js and the browser since 2012.
JavaScript
33
star
17

domain-browser

Node's domain module for the web browser
JavaScript
31
star
18

base

Base files for new projects
30
star
19

terraform-scaleway-hashistack

Terraform module to deploy Consul, Nomad, Vault onto Scaleway
Shell
20
star
20

boundation

Automatic scaffolding and upgrading of your JavaScript ecosystem projects using Bevry's best practices
JavaScript
19
star
21

safeps

Work with processes safely and easily in Node.js
JavaScript
17
star
22

filedirname

Fetch the current file and directory path, no matter your environment (Deno, Node.js, Web Browsers, ESM, CJS)
TypeScript
16
star
23

ambi

Ambi lets you execute any function ambidextrously; providing you the ability to execute any function (be it synchronous, asynchronous, returns, callbacks, promises) as if it returned a promise.
TypeScript
15
star
24

get-current-line

Get the current line number of the executing file and method
TypeScript
12
star
25

coda-packs

Monorepo of Coda packs
TypeScript
12
star
26

daet

Minimal immutable date class that supports relative time, calendar time, and plus/minus of different units.
TypeScript
11
star
27

textextensions

The definitive listing of filename extensions that are used for text files.
TypeScript
11
star
28

pluginclerk

 A clerk for retrieving compatible plugins from the npm database
TypeScript
9
star
29

errlop

An extended Error class that envelops a parent error, such that the stack trace contains the causation
TypeScript
9
star
30

native-promise-pool

Create a pool of a specified concurrency that accepts promises
TypeScript
9
star
31

event-emitter-grouped

Emit events in serial or parallel with support for synchronous and asynchronous listeners
JavaScript
9
star
32

awesome-crypto

The definitive listing of every cryptocurrency service; including their capabilities, fees, currencies, withdrawal process, etc.
9
star
33

extract-opts

Deprecated. Convert your API to promises
JavaScript
7
star
34

getsetdeep

Get or set nested variables of an object
TypeScript
7
star
35

scandirectory

Scan a directory recursively with a lot of control and power
TypeScript
7
star
36

safefs

Deprecated. Use the @bevry/fs-* packages instead
JavaScript
7
star
37

sortobject

Deeply sort an object by its keys without mangling any arrays inside of it
TypeScript
6
star
38

meetings

Bevry Meetings Website (WIP)
TypeScript
6
star
39

eachr

Deprecated: Use `for ( const [key, value] of Object.entries(thing) )`
TypeScript
6
star
40

binaryextensions

The definitive listing of filename extensions that are used for binary files.
TypeScript
6
star
41

arrangekeys

Returns a copy of a JavaScript object with the keys arranged in a specified order. Useful for formatting JSON files.
TypeScript
6
star
42

discourser

Discourse API Client written in TypeScript for Node.js and Browser environments
TypeScript
5
star
43

extendr

Utilities for cloning, extending, and de-referencing objects in shallow, deep, and safe ways
JavaScript
5
star
44

hooks

Aggregation of react hooks that we use. Such as useInterval and useMetaKey.
TypeScript
5
star
45

get-cli-arg

Deprecated. Use https://github.com/bevry/argument
TypeScript
5
star
46

cachely

A tiny wrapper that sits around your request function that caches its data for a specified duration, provides updates as requested rather than polling each interval
TypeScript
5
star
47

ropo

String replacement utilities with support for both synchronous and asynchronous replacements. Supports replacing Regular Expressions, HTML Elements, and Comment Elements. Compatible with async/await.
TypeScript
5
star
48

eslint-config-bevry

Bevry's ESLint configuration is an adaptive configuration that automatically configures ESLint
JavaScript
4
star
49

pluginloader

A class for loading, verifying, and creating plugins. Used by DocPad for years.
TypeScript
4
star
50

progress-title

Your usual progress bar, but this time it is displayed within the terminal's title, which is much simpler
JavaScript
3
star
51

hostenv

Exports the correct PORT and HOSTNAME values for Heroku, AppFog, CloudFoundry, OpenShift, and other service environments
TypeScript
3
star
52

ansi

ANSI colors and styles for Deno, Node.js, JavaScript, and TypeScript
TypeScript
3
star
53

start-of-week

Returns the start of the week based on the locale.
TypeScript
3
star
54

oneday

The number of milliseconds in one day
TypeScript
3
star
55

memo

Wrap a function in a memo to reuse the first invocation result of the function
TypeScript
3
star
56

billing

Bevry's billing system
TypeScript
3
star
57

list

List/array/set utility functions: union, intersect, complement, unique, first, last, has, add, toggle
TypeScript
3
star
58

arrange-package-json

Arrange the properties in the package.json file to a universally consistent order
TypeScript
2
star
59

github-orgs

JSON listing of all the Bevry managed GitHub organisations
TypeScript
2
star
60

version-range

Check version ranges like `>=N` and `X || Y || Z` with support for Node.js, Web Browsers, Deno, and TypeScript.
TypeScript
2
star
61

docmatter

Battle tested SSG front matter parser. Extracted from DocPad. Delimiter lines have 3+ of the same character (such as /*** and ***/) allowing front matters to work with the syntax highlighting of your code editor. Supports custom parsers, e.g. --- cson. Parsers are handled externally.
CoffeeScript
2
star
62

mdx

MDX loader for Next.js
TypeScript
2
star
63

discourse-component-youtubetimestamps

Convert timetamps in your post, to a timestamped link to the post's (otherwise topic's) referenced youtube video
HTML
2
star
64

json

Helpers for reading and writing JSON.
TypeScript
2
star
65

trim-indentation

Trim the initial indentation from a string
TypeScript
2
star
66

designs

Designs and resources for our company, community, and products
2
star
67

version-compare

Compare two versions quickly
TypeScript
2
star
68

dominject

Inject scripts and styles into the DOM with duplicate prevention and completion callback support
JavaScript
2
star
69

normalify

Normalize different variable value types - e.g. `"1"` becomes `1`
TypeScript
2
star
70

nodejs-versions

Filter the absolute or significant Node.js versions by vast amounts of criteria, such as LTS status.
TypeScript
2
star
71

fs-accessible

Check if a path is accessible
TypeScript
1
star
72

logger-clearable

A logger that is clearable
JavaScript
1
star
73

github-api

Interact with the GitHub API, fetching commits, repositories, members, and backers (authors, maintainers, contributors, funders, sponsors, donors)
TypeScript
1
star
74

valid-directory

Check whether or not the current working directory is valid on windows
TypeScript
1
star
75

rfc-log-levels

A map of log level aliases matched to their numeric values. Follows the RFC Standard.
TypeScript
1
star
76

assert-helpers

Common utilities and helpers to make testing assertions easier
TypeScript
1
star
77

.github

1
star
78

duration-timestamp

Parse and stringify duration timestamps (such as hh:mm:ss and HhMmSs)
TypeScript
1
star
79

detect-indentation

Utility to detect indentation from a string
TypeScript
1
star
80

render

Render elements for HTML and Markdown
TypeScript
1
star
81

valid-module

Verify that file or package, be it remote, or local, is a valid ECMAScript Module
TypeScript
1
star
82

file-url-to-path

Convert a file: URL to its path
TypeScript
1
star
83

fellow

Fellow is a package for creating people that can be unified by their shared values via a singleton list on the class
TypeScript
1
star
84

unicode-symbols

Unicode Symbols
TypeScript
1
star
85

links

Collection of Links for Redirection on the Bevry websites
TypeScript
1
star
86

ignorepatterns

A regular expression that matches common filenames that we want to ignore
TypeScript
1
star
87

spinner-title

Write your spinner to the terminal title bar
TypeScript
1
star
88

requirefresh

Require a file without adding it into the require cache
TypeScript
1
star
89

ignorefs

Ignore common and custom patterns of the file system
TypeScript
1
star
90

ecmascript-versions

Get all ECMAScript versions, or the ECMAScript version that was ratified on a specific date.
TypeScript
1
star
91

unbounded

Function.prototype.bind replacement that provides an `unbounded` hidden property on the returned bounded function, that contains the original unbounded function
TypeScript
1
star