1.1.4 • Published 6 years ago

sexprs v1.1.4

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
6 years ago

sexprs

parse and format S-expressions as JavaScript objects

npm install --save sexprs

background

Kicad files are S-expressions, i wanted an easy way to consume and produce these files.

i also think S-expressions are a cool file format, maybe i'll use them for something in the future. :wink:

example

var sexprs = Sexprs({
  operators: {
    person: {
      args: ['name']
    },
    location: {
      args: ['lat', 'long']
    },
    likes: {
      hasMany: true
    }
  }
})
var inputString = `
  (person Mikey
    (version 1.0.0)
    (website http://dinosaur.is)
    (location 121 121)
    (likes (name chocolate))
    (likes (name JavaScript))
  )
`
// parse string into object
var object = sexprs.parse(inputString)
var expectedObject = {
  person: {
    name: 'Mikey',
    version: '1.0.0',
    website: 'http://dinosaur.is',
    location: { lat: 121, long: 121 },
    likes: [
      { name: 'chocolate' },
      { name: 'JavaScript' }
    ]
  }
}
t.deepEqual(object, expectedObject)

// stringify object back into string
var string = sexprs.stringify(expectedObject)
var expectedString = inputString + '\n'
t.deepEqual(string, expectedString)

usage

Sexprs = require('sexprs')

sexprs = Sexprs(options)

options is object with keys:

  • operators: an object where
    • keys are names of S-expression operators (the first symbol after an open parentheses)
    • values are objects with possible keys:
      • args: how to interpret indexed arguments as keys
      • hasMany: whether values should be grouped into an array

object = sexprs.parse(string)

string = sexprs.format(object)

license

The Apache License

Copyright © 2018 Michael Williams

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago