-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first commit
- Loading branch information
0 parents
commit 1f1ee0d
Showing
13 changed files
with
9,599 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- v6 | ||
after_script: cat ./coverage/lcov.info | coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Copyright (c) 2018 Buster Collings <busterc@gmail.com> (https://about.me/buster) | ||
|
||
Permission to use, copy, modify, and/or distribute this software for | ||
any purpose with or without fee is hereby granted, provided that the | ||
above copyright notice and this permission notice appear in all | ||
copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL | ||
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE | ||
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# ndjson-generate-schema [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url] | ||
|
||
> Effortlessly convert your NDJSON data to a JSON Schema. | ||
* Powered by: [`generate-schema`](https://github.com/nijikokun/generate-schema) | ||
|
||
## Installation | ||
|
||
```sh | ||
$ npm install --save ndjson-generate-schema | ||
|
||
# Or to use the CLI globally | ||
$ npm install --global ndjson-generate-schema | ||
``` | ||
|
||
## Usage | ||
|
||
Given an NDJSON file `dogs.db`: | ||
|
||
``` | ||
{"id":1,"name":"Buddy","breed":"Boston Terrier"} | ||
{"id":2,"name":"Charley"} | ||
``` | ||
|
||
### CLI | ||
|
||
```sh | ||
$ ndjson-generate-schema | ||
|
||
Effortlessly convert your NDJSON data to a JSON Schema. | ||
|
||
Usage | ||
|
||
$ ndjson-generate-schema <title> <file> [outfile] | ||
|
||
Inputs | ||
|
||
title Required, Title of Schema | ||
file Required, NDJSON file to read | ||
outfile Optional, filename to write Schema out to | ||
``` | ||
|
||
### Module | ||
|
||
```js | ||
const path = require('path'); | ||
const ndjsonGenerateSchema = require('ndjson-generate-schema'); | ||
|
||
ndjsonGenerateSchema('Dogs', path.resolve(__dirname, 'dogs.db')).then( | ||
schema => { | ||
console.log(schema); | ||
/* | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "Dogs Set", | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "number" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"breed": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"id", | ||
"name" | ||
], | ||
"title": "Dogs" | ||
} | ||
} | ||
*/ | ||
} | ||
); | ||
``` | ||
|
||
## API | ||
|
||
### `ndjsonGenerateSchema(title, file)` | ||
|
||
* ### `title` | ||
* `Required` : `String` the title of the Schema | ||
* ### `file` | ||
* `Required` : `String` the NDJSON file to read | ||
|
||
## License | ||
|
||
ISC © [Buster Collings](https://about.me/buster) | ||
|
||
[npm-image]: https://badge.fury.io/js/ndjson-generate-schema.svg | ||
[npm-url]: https://npmjs.org/package/ndjson-generate-schema | ||
[travis-image]: https://travis-ci.org/busterc/ndjson-generate-schema.svg?branch=master | ||
[travis-url]: https://travis-ci.org/busterc/ndjson-generate-schema | ||
[daviddm-image]: https://david-dm.org/busterc/ndjson-generate-schema.svg?theme=shields.io | ||
[daviddm-url]: https://david-dm.org/busterc/ndjson-generate-schema | ||
[coveralls-image]: https://coveralls.io/repos/busterc/ndjson-generate-schema/badge.svg | ||
[coveralls-url]: https://coveralls.io/r/busterc/ndjson-generate-schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{"id":1,"name":"Buddy","breed":"Boston Terrier"} | ||
{"id":2,"name":"Charley"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
const ndjsonGenerateSchema = require('../index.js'); | ||
|
||
describe('ndjsonGenerateSchema', () => { | ||
it('generates schema', () => { | ||
ndjsonGenerateSchema('Dogs', path.resolve(__dirname, 'dogs.db')).then(schema => { | ||
assert(schema.items.required.find(x => x === 'id')); | ||
assert(!schema.items.required.find(x => x === 'breed')); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const meow = require('meow'); | ||
const ndjsonGenerateSchema = require('./'); | ||
|
||
const cli = meow(` | ||
Usage | ||
$ ndjson-generate-schema <title> <file> [outfile] | ||
Inputs | ||
title Required, Title of Schema | ||
file Required, NDJSON file to read | ||
outfile Optional, filename to write Schema out to | ||
`); | ||
|
||
(function() { | ||
if (cli.input.length < 2) { | ||
return cli.showHelp(); | ||
} | ||
ndjsonGenerateSchema(cli.input[0], cli.input[1]) | ||
.then(schema => { | ||
const schemaJson = JSON.stringify(schema, null, 2); | ||
if (cli.input[2]) { | ||
const outfile = path.resolve(process.cwd(), cli.input[2]); | ||
return fs.writeFileSync(outfile, schemaJson); | ||
} | ||
console.log(schemaJson); | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
const GenerateSchema = require('generate-schema'); | ||
const fs = require('fs-ndjson'); | ||
|
||
module.exports = function(title, file) { | ||
return fs.readFile(file).then(data => { | ||
return GenerateSchema.json(title, data); | ||
}); | ||
}; |
Oops, something went wrong.