spell 0.1.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -136
- package/package.json +24 -21
- package/.gitignore +0 -4
- package/.travis.yml +0 -6
- package/spell.js +0 -338
- package/test/css/mocha.css +0 -110
- package/test/index.html +0 -34
- package/test/lib/JSONStream/.gitignore +0 -3
- package/test/lib/JSONStream/bench.js +0 -35
- package/test/lib/JSONStream/examples/all_docs.js +0 -13
- package/test/lib/JSONStream/index.js +0 -118
- package/test/lib/JSONStream/package.json +0 -13
- package/test/lib/JSONStream/readme.markdown +0 -120
- package/test/lib/JSONStream/test/fixtures/all_docs_include.json +0 -4245
- package/test/lib/JSONStream/test/fixtures/all_npm.json +0 -4030
- package/test/lib/JSONStream/test/parsejson.js +0 -25
- package/test/lib/JSONStream/test/stringify.js +0 -41
- package/test/lib/JSONStream/test/test.js +0 -35
- package/test/lib/JSONStream/test/test2.js +0 -29
- package/test/lib/JSONStream/test/two-ways.js +0 -41
- package/test/lib/jquery-1.7.1.min.js +0 -4
- package/test/lib/json2.js +0 -487
- package/test/lib/mocha-0.3.6.js +0 -2672
- package/test/lib/request/LICENSE +0 -55
- package/test/lib/request/README.md +0 -285
- package/test/lib/request/main.js +0 -618
- package/test/lib/request/mimetypes.js +0 -146
- package/test/lib/request/oauth.js +0 -34
- package/test/lib/request/package.json +0 -15
- package/test/lib/request/tests/googledoodle.png +0 -0
- package/test/lib/request/tests/run.sh +0 -6
- package/test/lib/request/tests/server.js +0 -57
- package/test/lib/request/tests/test-body.js +0 -90
- package/test/lib/request/tests/test-cookie.js +0 -29
- package/test/lib/request/tests/test-cookiejar.js +0 -90
- package/test/lib/request/tests/test-errors.js +0 -30
- package/test/lib/request/tests/test-oauth.js +0 -109
- package/test/lib/request/tests/test-pipes.js +0 -167
- package/test/lib/request/tests/test-proxy.js +0 -39
- package/test/lib/request/tests/test-timeout.js +0 -87
- package/test/lib/request/uuid.js +0 -19
- package/test/lib/request/vendor/cookie/index.js +0 -55
- package/test/lib/request/vendor/cookie/jar.js +0 -72
- package/test/perf.js +0 -44
- package/test/resources/big.js +0 -9
- package/test/resources/big.json +0 -29159
- package/test/resources/big.txt +0 -128457
- package/test/resources/big_browser.js +0 -29159
- package/test/resources/npm.js +0 -26
- package/test/resources/npm.json +0 -84701
- package/test/resources/perf1.js +0 -144
- package/test/resources/perf2.js +0 -366
- package/test/spell.js +0 -276
package/test/index.html
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
<head>
|
|
3
|
-
<title>spell.js</title>
|
|
4
|
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
5
|
-
<link rel="stylesheet" href="css/mocha.css" />
|
|
6
|
-
<script src="lib/jquery-1.7.1.min.js" type="text/javascript"></script>
|
|
7
|
-
<script src="lib/mocha-0.3.6.js"></script>
|
|
8
|
-
<script src="lib/json2.js"></script>
|
|
9
|
-
<script src="../spell.js"></script>
|
|
10
|
-
<script src="resources/big_browser.js"></script>
|
|
11
|
-
<script src="resources/perf1.js"></script>
|
|
12
|
-
<script src="resources/perf2.js"></script>
|
|
13
|
-
<script>mocha.setup('bdd')</script>
|
|
14
|
-
<script>
|
|
15
|
-
function assert(expr, msg) {
|
|
16
|
-
if (!expr) throw new Error(msg || 'failed');
|
|
17
|
-
}
|
|
18
|
-
</script>
|
|
19
|
-
<script src="spell.js"></script>
|
|
20
|
-
<script>
|
|
21
|
-
onload = function(){
|
|
22
|
-
var runner = mocha.run();
|
|
23
|
-
runner.globals(['foo', 'bar', 'baz']);
|
|
24
|
-
|
|
25
|
-
runner.on('test end', function(test){
|
|
26
|
-
console.log(test.fullTitle());
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
</script>
|
|
30
|
-
</head>
|
|
31
|
-
<body>
|
|
32
|
-
<div id="mocha"></div>
|
|
33
|
-
</body>
|
|
34
|
-
</html>
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var fs = require('fs')
|
|
4
|
-
, join = require('path').join
|
|
5
|
-
, JSONStream = require('./')
|
|
6
|
-
, es = require('event-stream')
|
|
7
|
-
, request = require('request')
|
|
8
|
-
, floby = require('json-streams').createParseStream()
|
|
9
|
-
var file = join(__dirname, 'test/fixtures/all_docs_include.json')
|
|
10
|
-
, stat = fs.statSync(file)
|
|
11
|
-
, parser = JSONStream.parse(['rows',/./])
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function checkStream() {
|
|
15
|
-
var start = Date.now()
|
|
16
|
-
fs.createReadStream(file).pipe(floby)
|
|
17
|
-
floby.on('end', function (err, array) {
|
|
18
|
-
var time = Date.now() - start
|
|
19
|
-
|
|
20
|
-
console.error({type: 'JSONStream.parse', size: stat.size, time: time})
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function checkParse() {
|
|
25
|
-
var start = Date.now()
|
|
26
|
-
fs.readFile(file, function (err, json) {
|
|
27
|
-
var obj = JSON.parse(json)
|
|
28
|
-
var time = Date.now() - start
|
|
29
|
-
|
|
30
|
-
console.error({type: 'JSON.parse', size: stat.size, time: time})
|
|
31
|
-
checkStream()
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
checkParse()
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
var request = require('request')
|
|
2
|
-
, JSONStream = require('JSONStream')
|
|
3
|
-
, es = require('event-stream')
|
|
4
|
-
|
|
5
|
-
var parser = JSONStream.parse(['rows', /./]) //emit parts that match this path (any element of the rows array)
|
|
6
|
-
, req = request({url: 'http://isaacs.couchone.com/registry/_all_docs'})
|
|
7
|
-
, logger = es.mapSync(function (data) { //create a stream that logs to stderr,
|
|
8
|
-
console.error(data)
|
|
9
|
-
return data
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
req.pipe(parser)
|
|
13
|
-
parser.pipe(logger)
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var Parser = require('jsonparse')
|
|
3
|
-
, Stream = require('stream').Stream
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
|
|
7
|
-
the value of this.stack that creationix's jsonparse has is weird.
|
|
8
|
-
|
|
9
|
-
it makes this code ugly, but his problem is way harder that mine,
|
|
10
|
-
so i'll forgive him.
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
exports.parse = function (path) {
|
|
15
|
-
|
|
16
|
-
var stream = new Stream()
|
|
17
|
-
var parser = new Parser()
|
|
18
|
-
var count = 0
|
|
19
|
-
if(!path.length)
|
|
20
|
-
path = null
|
|
21
|
-
parser.onValue = function () {
|
|
22
|
-
if(!this.root && this.stack.length == 1){
|
|
23
|
-
stream.root = this.value
|
|
24
|
-
}
|
|
25
|
-
if(!path || this.stack.length !== path.length)
|
|
26
|
-
return
|
|
27
|
-
var _path = []
|
|
28
|
-
for( var i = 0; i < (path.length - 1); i++) {
|
|
29
|
-
var key = path[i]
|
|
30
|
-
var c = this.stack[1 + (+i)]
|
|
31
|
-
|
|
32
|
-
if(!c) {
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
var m =
|
|
36
|
-
( 'string' === typeof key
|
|
37
|
-
? c.key == key
|
|
38
|
-
: key.exec(c.key))
|
|
39
|
-
_path.push(c.key)
|
|
40
|
-
|
|
41
|
-
if(!m)
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
var c = this
|
|
46
|
-
|
|
47
|
-
var key = path[path.length - 1]
|
|
48
|
-
var m =
|
|
49
|
-
( 'string' === typeof key
|
|
50
|
-
? c.key == key
|
|
51
|
-
: key.exec(c.key))
|
|
52
|
-
if(!m)
|
|
53
|
-
return
|
|
54
|
-
_path.push(c.key)
|
|
55
|
-
|
|
56
|
-
count ++
|
|
57
|
-
stream.emit('data', this.value[this.key])
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
parser.onError = function (err) {
|
|
62
|
-
stream.emit('error', err)
|
|
63
|
-
}
|
|
64
|
-
stream.readable = true
|
|
65
|
-
stream.writable = true
|
|
66
|
-
stream.write = function (chunk) {
|
|
67
|
-
if('string' === typeof chunk)
|
|
68
|
-
chunk = new Buffer(chunk)
|
|
69
|
-
parser.write(chunk)
|
|
70
|
-
}
|
|
71
|
-
stream.end = function (data) {
|
|
72
|
-
if(data)
|
|
73
|
-
stream.write(data)
|
|
74
|
-
if(!count)
|
|
75
|
-
stream.emit('data', stream.root)
|
|
76
|
-
stream.emit('end')
|
|
77
|
-
}
|
|
78
|
-
return stream
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
exports.stringify = function (op, sep, cl) {
|
|
82
|
-
if (op === false){
|
|
83
|
-
op = ''
|
|
84
|
-
sep = '\n'
|
|
85
|
-
cl = ''
|
|
86
|
-
} else if (op == null) {
|
|
87
|
-
|
|
88
|
-
op = '[\n'
|
|
89
|
-
sep = '\n,\n'
|
|
90
|
-
cl = '\n]\n'
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
//else, what ever you like
|
|
95
|
-
|
|
96
|
-
var stream = new Stream ()
|
|
97
|
-
, first = true
|
|
98
|
-
, ended = false
|
|
99
|
-
stream.write = function (data) {
|
|
100
|
-
var json = JSON.stringify(data)
|
|
101
|
-
if(first) { first = false ; stream.emit('data', op + json)}
|
|
102
|
-
else stream.emit('data', sep + json)
|
|
103
|
-
}
|
|
104
|
-
stream.end = function (data) {
|
|
105
|
-
if(ended)
|
|
106
|
-
return
|
|
107
|
-
ended = true
|
|
108
|
-
if(data)
|
|
109
|
-
stream.write(data)
|
|
110
|
-
stream.emit('data', cl)
|
|
111
|
-
|
|
112
|
-
stream.emit('end')
|
|
113
|
-
}
|
|
114
|
-
stream.writable = true
|
|
115
|
-
stream.readable = true
|
|
116
|
-
|
|
117
|
-
return stream
|
|
118
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{ "name": "JSONStream"
|
|
2
|
-
, "version": "0.1.2"
|
|
3
|
-
, "description": "rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)"
|
|
4
|
-
, "homepage": "http://github.com/dominictarr/JSONStream"
|
|
5
|
-
, "repository":
|
|
6
|
-
{ "type": "git"
|
|
7
|
-
, "url": "https://github.com/dominictarr/JSONStream.git" }
|
|
8
|
-
, "dependencies": {
|
|
9
|
-
"jsonparse": "0.0.1"
|
|
10
|
-
}
|
|
11
|
-
, "devDependencies": {}
|
|
12
|
-
, "author": "Dominic Tarr <dominic.tarr@gmail.com> (http://bit.ly/dominictarr)"
|
|
13
|
-
, "scripts": { "test": "meta-test test/*.js" } }
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
# JSONStream
|
|
2
|
-
|
|
3
|
-
streaming JSON.parse and stringify
|
|
4
|
-
|
|
5
|
-
## example
|
|
6
|
-
|
|
7
|
-
```javascript
|
|
8
|
-
|
|
9
|
-
var request = require('request')
|
|
10
|
-
, JSONStream = require('JSONStream')
|
|
11
|
-
, es = require('event-stream')
|
|
12
|
-
|
|
13
|
-
var parser = JSONStream.parse(['rows', /./])
|
|
14
|
-
, req = request({url: 'http://isaacs.couchone.com/registry/_all_docs'})
|
|
15
|
-
, logger = es.mapSync(function (data) {
|
|
16
|
-
console.error(data)
|
|
17
|
-
return data
|
|
18
|
-
})
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
in node 0.4.x
|
|
22
|
-
|
|
23
|
-
``` javascript
|
|
24
|
-
|
|
25
|
-
req.pipe(parser)
|
|
26
|
-
parser.pipe(logger)
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
in node v0.5.x
|
|
31
|
-
|
|
32
|
-
``` javascript
|
|
33
|
-
req.pipe(parser).pipe(logger)
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## JSONStream.parse(path)
|
|
38
|
-
|
|
39
|
-
usally, a json API will return a list of objects.
|
|
40
|
-
|
|
41
|
-
`path` should be an array of property names and/or `RedExp`s.
|
|
42
|
-
any object that matches the path will be emitted as 'data' (and `pipe`d down stream)
|
|
43
|
-
|
|
44
|
-
if `path` is empty or null, or if no matches are made:
|
|
45
|
-
JSONStream.parse will only one 'data': the root object.
|
|
46
|
-
|
|
47
|
-
(this is useful when there is an error, because the error will probably not match your path)
|
|
48
|
-
|
|
49
|
-
### example
|
|
50
|
-
|
|
51
|
-
query a couchdb view:
|
|
52
|
-
|
|
53
|
-
``` bash
|
|
54
|
-
curl -sS localhost:5984/tests/_all_docs&include_docs=true
|
|
55
|
-
```
|
|
56
|
-
you will get something like this:
|
|
57
|
-
|
|
58
|
-
``` js
|
|
59
|
-
{"total_rows":129,"offset":0,"rows":[
|
|
60
|
-
{ "id":"change1_0.6995461115147918"
|
|
61
|
-
, "key":"change1_0.6995461115147918"
|
|
62
|
-
, "value":{"rev":"1-e240bae28c7bb3667f02760f6398d508"}
|
|
63
|
-
, "doc":{
|
|
64
|
-
"_id": "change1_0.6995461115147918"
|
|
65
|
-
, "_rev": "1-e240bae28c7bb3667f02760f6398d508","hello":1}
|
|
66
|
-
},
|
|
67
|
-
{ "id":"change2_0.6995461115147918"
|
|
68
|
-
, "key":"change2_0.6995461115147918"
|
|
69
|
-
, "value":{"rev":"1-13677d36b98c0c075145bb8975105153"}
|
|
70
|
-
, "doc":{
|
|
71
|
-
"_id":"change2_0.6995461115147918"
|
|
72
|
-
, "_rev":"1-13677d36b98c0c075145bb8975105153"
|
|
73
|
-
, "hello":2
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
]}
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
we are probably most interested in the `rows.*.docs`
|
|
81
|
-
|
|
82
|
-
create a `Stream` that parses the documents from the feed like this:
|
|
83
|
-
|
|
84
|
-
``` js
|
|
85
|
-
JSONStream.parse(['rows', /./, 'doc']) //rows, ANYTHING, doc
|
|
86
|
-
```
|
|
87
|
-
awesome!
|
|
88
|
-
|
|
89
|
-
## JSONStream.stringify(open, sep, close)
|
|
90
|
-
|
|
91
|
-
Create a writable stream.
|
|
92
|
-
|
|
93
|
-
you may pass in custom `open`, `close`, and `seperator` strings.
|
|
94
|
-
But, by default, `JSONStream.stringify()` will create an array,
|
|
95
|
-
(with default options `open='[\n', sep='\n,\n', cl='\n]\n'`)
|
|
96
|
-
|
|
97
|
-
If you call `JSONStream.stringify(false)`
|
|
98
|
-
the elements will only be seperated by a newline.
|
|
99
|
-
|
|
100
|
-
If you only write one item this will be valid JSON.
|
|
101
|
-
|
|
102
|
-
If you write many items,
|
|
103
|
-
you can use a `RegExp` to split it into valid chunks.
|
|
104
|
-
|
|
105
|
-
## numbers
|
|
106
|
-
|
|
107
|
-
There are occasional problems parsing and unparsing very precise numbers.
|
|
108
|
-
|
|
109
|
-
I have opened an issue here:
|
|
110
|
-
|
|
111
|
-
https://github.com/creationix/jsonparse/issues/2
|
|
112
|
-
|
|
113
|
-
+1
|
|
114
|
-
|
|
115
|
-
## Acknowlegements
|
|
116
|
-
|
|
117
|
-
this module depends on https://github.com/creationix/jsonparse
|
|
118
|
-
by Tim Caswell
|
|
119
|
-
and also thanks to Florent Jaby for teaching me about parsing with:
|
|
120
|
-
https://github.com/Floby/node-json-streams
|