Comparing version 0.2.0 to 0.3.0
0.3.0 / 2012-07-17 | ||
================== | ||
* add `.parse(obj)` support [3rd-Eden] | ||
0.2.0 / 2012-06-28 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -78,2 +78,4 @@ | ||
if (typeof str !== 'string') str = JSON.stringify(str); | ||
return JSON.parse(str, function(key, val){ | ||
@@ -89,2 +91,2 @@ var plugin, ret; | ||
}); | ||
}; | ||
}; |
{ | ||
"name": "eson" | ||
, "version": "0.2.0" | ||
, "version": "0.3.0" | ||
, "description": "Extended JSON - pluggable JSON logic for dates, includes, and more" | ||
@@ -5,0 +5,0 @@ , "keywords": ["json", "config"] |
201
tests.md
@@ -1,171 +0,82 @@ | ||
- [dimensions](#dimensions) | ||
- [glob](#glob) | ||
- [include](#include) | ||
- [ms](#ms) | ||
- [Parser](#parser) | ||
- [Parser()](#parser) | ||
- [.use(fn)](#usefn) | ||
- [.read(path)](#readpath) | ||
- [.parse(str)](#parsestr) | ||
- [replace](#replace) | ||
1341024169358 | ||
1341024169000 | ||
# TOC | ||
- [args](#args) | ||
- [bools](#bools) | ||
- [date](#date) | ||
- [dimensions](#dimensions) | ||
- [env(prefix)](#envprefix) | ||
- [glob](#glob) | ||
- [include](#include) | ||
- [ms](#ms) | ||
- [Parser](#parser) | ||
- [Parser()](#parser-parser) | ||
- [.use(fn)](#parser-usefn) | ||
- [.read(path)](#parser-readpath) | ||
- [.parse(str)](#parser-parsestr) | ||
- [replace](#replace) | ||
<a name="" /> | ||
<a name="dimensions" /> | ||
# dimensions | ||
should return an object with width/height. | ||
<a name="args" /> | ||
# args | ||
should support --NAME. | ||
```js | ||
dim('', '200x400').should.eql({ width: 200, height: 400 }); | ||
var fn = args(['foo', 'bar']); | ||
fn('dev ui', false).should.be.false; | ||
fn = args(['foo', '--dev-ui']); | ||
fn('dev ui', false).should.be.true; | ||
``` | ||
<a name="glob" /> | ||
# glob | ||
should perform a sync glob. | ||
should support --no-NAME. | ||
```js | ||
glob('', 'glob test/fixtures/*.js').should.eql( | ||
['test/fixtures/bar.js', | ||
'test/fixtures/baz.js', | ||
'test/fixtures/foo.js'] | ||
); | ||
var fn = args(['foo', '--no-dev-ui']); | ||
fn('dev ui', true).should.be.false; | ||
``` | ||
glob('', 'glob test/fixtures/b*.js').should.eql( | ||
['test/fixtures/bar.js', | ||
'test/fixtures/baz.js'] | ||
); | ||
should support --NAME val. | ||
glob('', 'glob test/fixtures/{bar,foo}.js').should.eql( | ||
['test/fixtures/bar.js', | ||
'test/fixtures/foo.js'] | ||
); | ||
```js | ||
var fn = args(['foo', '--dev-ui', 'yes']); | ||
fn('dev ui', false).should.equal('yes'); | ||
``` | ||
<a name="include" /> | ||
# include | ||
should parse the given file. | ||
<a name="bools" /> | ||
# bools | ||
should parse string bool representations. | ||
```js | ||
Parser() | ||
.use(include) | ||
.read('test/fixtures/include.json') | ||
.should.eql([ | ||
"foo", | ||
{ | ||
"view videos": "guest", | ||
"delete videos": "admin" | ||
}, | ||
["admin", "guest"] | ||
]); | ||
bools('', 'yes').should.be.true; | ||
bools('', 'enabled').should.be.true; | ||
bools('', 'no').should.be.false; | ||
bools('', 'disabled').should.be.false; | ||
bools('', true).should.be.true; | ||
bools('', 'other').should.be.equal('other'); | ||
``` | ||
<a name="date" /> | ||
# date | ||
<a name="dimensions" /> | ||
# dimensions | ||
<a name="envprefix" /> | ||
# env(prefix) | ||
<a name="glob" /> | ||
# glob | ||
<a name="include" /> | ||
# include | ||
<a name="ms" /> | ||
# ms | ||
should parse string ms representations. | ||
```js | ||
ms('', '1000ms').should.equal(1000); | ||
ms('', '1s').should.equal(1000); | ||
ms('', '4 seconds').should.equal(4000); | ||
ms('', '4 seconds').should.equal(4000); | ||
ms('', '2 minutes').should.equal(2 * 60000); | ||
ms('', '1 hour').should.equal(3600000); | ||
ms('', '2 days').should.equal(2 * 86400000); | ||
ms('', '5y').should.equal(5 * 31557600000); | ||
ms('', '1 year').should.equal(31557600000); | ||
ms('', '5 years').should.equal(5 * 31557600000); | ||
``` | ||
<a name="parser" /> | ||
# Parser | ||
<a name="parser" /> | ||
<a name="parser-parser" /> | ||
## Parser() | ||
should return a new Parser. | ||
```js | ||
Parser().should.be.an.instanceof(Parser); | ||
``` | ||
<a name="usefn" /> | ||
<a name="parser-usefn" /> | ||
## .use(fn) | ||
should be invoked with both the key and value. | ||
```js | ||
var parser = new Parser; | ||
parser.use(function(key, val){ | ||
key.should.equal('foo'); | ||
val.should.equal('bar'); | ||
done(); | ||
}); | ||
parser.parse('{ "foo": "bar" }'); | ||
``` | ||
<a name="readpath" /> | ||
<a name="parser-readpath" /> | ||
## .read(path) | ||
should read the JSON and apply plugins. | ||
```js | ||
var parser = new Parser; | ||
parser.use(function(key, val){ return val.toUpperCase(); }); | ||
var obj = parser.read('test/fixtures/config.json'); | ||
obj.should.eql({ foo: 'BAR', bar: 'BAZ' }); | ||
``` | ||
<a name="parsestr" /> | ||
<a name="parser-parsestr" /> | ||
## .parse(str) | ||
should invoke each plugin. | ||
```js | ||
var parser = new Parser | ||
, calls = []; | ||
parser.use(function(key, val){ | ||
key.should.equal('foo'); | ||
val.should.equal('bar'); | ||
calls.push('a'); | ||
}); | ||
parser.use(function(key, val){ | ||
key.should.equal('foo'); | ||
val.should.equal('bar'); | ||
calls.push('b'); | ||
calls.should.eql(['a', 'b']); | ||
done(); | ||
}); | ||
parser.parse('{ "foo": "bar" }'); | ||
``` | ||
should not modify when undefined is returned. | ||
```js | ||
var parser = new Parser; | ||
parser.use(function(key, val){}); | ||
parser.parse('{ "foo": "bar" }') | ||
.should.eql({ foo: 'bar' }); | ||
``` | ||
should modify when a value is returned. | ||
```js | ||
var parser = new Parser; | ||
parser.use(function(key, val){ return 'hey'; }); | ||
parser.parse('{ "foo": "bar" }') | ||
.should.eql({ foo: 'hey' }); | ||
``` | ||
<a name="replace" /> | ||
# replace | ||
should replace occurrences of a string. | ||
```js | ||
replace('{root}', '/my/path') | ||
('', '{root}/foo') | ||
.should.equal('/my/path/foo'); | ||
``` | ||
18
225
13215