noon

no ordinary object notation

Unlicense 114 个版本
安装
npm install noon
yarn add noon
pnpm add noon
bun add noon
README

icon

noon

noon

is an object notation with a focus on human readability.

Whitespace is preferred over other control characters:

example files

format

hierarchy

is expressed by indentation with spaces

grandpa
    parent
        child
        sibling
    uncle

dictionaries

two or more spaces mark the end of a dictionary key, therefore ...
keys and list items can have single spaces in them but ...
unescaped dictionary keys can't contain consecutive spaces:

key 1    value 1
key 2    value 2 contains    spaces

one key makes an object

this is
an   object

the above as json: {"this is": null, "an": "object"}
while

this is
not an object

is equivalent to ["this is", "not an object"]

objects inside lists

are expressed like this:

.
    a  1
.
    b  2

the above as json: [{"a": 1}, {"b": 2}]

strings

escaping

if trimming your strings is not an option, you can escape:

a             |  leading spaces
b             trailing spaces  |
c             |  leading and trailing spaces  |
pipe symbol   |||
empty string  ||

keys must be escaped from both ends:

| s  pace |  key keeps spaces
|    |       key consists of spaces
||           key is empty string

multiline strings

key  ...
value is
a text with
line breaks
which stops
now
...  

comments

# comments start with the hash sign
# mixing of data and comments is not allowed
therefore:
    1 # this is not a comment
    | # neither is this one
      # but this one is 

inline

sometimes data needs to be encoded in a single line.

dense notation

key  . a .. b . c

is equivalent to

key
    a
        b
    c

one line notation

:: represents a line break
no spaces in keys allowed, therefore ...
no two-space-seperation necessary:

key . a :: b . c :: d 1 :: e 2

is equivalent to

key
    a
b
    c
d   1
e   2

command line

cli

module

noon = require 'noon'

# usage is similar to JSON 

noon.stringify { hello: 'world' }

# hello    world

noon.parse """
hello         world
what's up?    ☺
"""

# { hello: 'world', 'what\'s up?': '☺' }

stringify_options =   # stringify's second argument, defaults are: 
    ext:      'noon'  # output format: noon or json
    indent:   4       # number of spaces per indent level
    align:    true    # vertically align object values
    maxalign: 32      # maximal number of spaces when aligning
    sort:     false   # sort object keys alphabetically
    circular: false   # check for circular references (expensive!)
    colors:   false   # colorize output with ansi colors
    

# load data from file 

data = noon.load 'file.noon' 
data = noon.load 'file.json'

# write data to file

noon.save 'file.noon', data

noon.save 'file.noon', data, stringify_options
noon.save 'file.json', data  # < write as json
noon.save 'noext', data, ext: 'noon'

caveats

  • keys can't start with the pipe symbol: |
  • escaped keys can't contain the pipe symbol
  • empty objects are not expressible

Don't use it if you can't live with the limitations mentioned above.

npm package Build Status downloads

版本列表
3.5.0 2021-11-13
3.4.0 2021-11-13
3.1.0 2020-12-15
3.0.3 2020-03-29
3.0.0 2019-08-05
2.15.0 2019-07-20
2.14.1 2019-06-13
2.14.0 2019-06-13
2.13.0 2019-06-10
2.12.3 2019-06-10
2.12.2 2019-06-10
2.12.1 2019-06-10
2.11.0 2019-06-09
2.10.0 2019-06-07
2.9.0 2019-06-07
2.8.0 2019-06-07
2.7.0 2019-06-07
2.6.0 2019-06-07
2.5.0 2019-05-30
2.4.0 2019-05-29
2.3.0 2019-05-19
2.0.2 2019-05-11
2.0.0 2019-05-11
1.5.0 2018-06-09
1.4.0 2018-05-31
1.3.1 2018-05-29
1.3.0 2018-05-29
1.2.0 2018-05-29
1.1.2 2018-05-28
1.1.1 2018-02-25
1.1.0 2017-04-18
1.0.14 2017-03-09
1.0.13 2016-09-20
1.0.12 2016-07-06
1.0.11 2016-06-27
1.0.9 2016-06-14
1.0.8 2016-05-14
1.0.6 2016-04-28
1.0.5 2016-04-28
1.0.4 2016-02-03
1.0.3 2016-02-03
1.0.2 2016-02-03
1.0.1 2016-02-02
0.9.17 2016-01-31
0.9.16 2016-01-31
0.9.15 2016-01-31
0.9.14 2016-01-31
0.9.13 2016-01-30
0.9.12 2016-01-29
0.9.11 2016-01-29
0.9.10 2016-01-29
0.9.9 2016-01-28
0.9.8 2016-01-28
0.9.7 2016-01-28
0.9.6 2016-01-28
0.9.5 2016-01-28
0.9.4 2016-01-28
0.9.3 2016-01-28
0.9.2 2016-01-28
0.9.1 2016-01-28
0.8.3 2016-01-24
0.8.2 2016-01-24
0.8.1 2016-01-23
0.7.5 2016-01-22
0.7.4 2016-01-18
0.7.3 2016-01-18
0.7.2 2016-01-16
0.7.1 2016-01-16
0.6.17 2016-01-13
0.6.16 2016-01-13
0.6.15 2016-01-13
0.6.14 2016-01-12
0.6.13 2016-01-12
0.6.12 2016-01-12
0.6.11 2016-01-10
0.6.10 2016-01-10
0.6.9 2016-01-10
0.6.8 2016-01-10
0.6.7 2016-01-10
0.6.6 2016-01-10
0.6.5 2016-01-10
0.6.4 2016-01-07
0.6.3 2016-01-07
0.6.2 2016-01-07
0.6.1 2016-01-05
0.5.6 2016-01-05
0.5.5 2016-01-05
0.5.4 2015-12-28
0.5.3 2015-12-27
0.5.2 2015-12-22
0.5.1 2015-12-21
0.4.5 2015-12-21
0.4.4 2015-12-20
0.4.3 2015-12-19
0.4.2 2015-12-19
0.4.1 2015-12-18
0.3.6 2015-12-18
0.3.5 2015-12-18
0.3.4 2015-12-15
0.3.3 2015-12-15
0.3.2 2015-12-14
0.3.1 2015-12-14
0.2.2 2015-12-13
0.2.1 2015-12-13
0.1.6 2015-12-06
0.1.5 2015-12-06
0.1.4 2015-12-06
0.1.3 2015-12-06
0.1.2 2015-12-06
0.1.1 2015-12-06
0.0.4 2015-12-05
0.0.3 2015-12-05
0.0.2 2015-12-05
0.0.1 2015-12-05