Skip to content

Commit fe7ee2e

Browse files
committed
Initial commit
0 parents  commit fe7ee2e

35 files changed

+15918
-0
lines changed

.editorconfig

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[{package.json,*.xml}]
12+
indent_style = space
13+
indent_size = 2
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/backup/
2+
/wiki/
3+
/node_modules/
4+
/backup/
5+
/coverage/
6+
src*.zip
7+
TODO.md
8+
ignore*.*

.travis.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: node_js
2+
node_js:
3+
- '8'
4+
- '6'
5+
before_script: cd $TRAVIS_BUILD_DIR
6+
script:
7+
- npm run cover
8+
- npm run coveralls
9+
notifications:
10+
email:
11+
# recipients:
12+
13+
on_success: never # default: change
14+
on_failure: always # default: always
15+

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2018, Onur Yıldırım <[email protected]>. All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# jsonc
2+
3+
[![build-status](https://img.shields.io/travis/onury/jsonc.svg?branch=master)](https://travis-ci.org/onury/jsonc)
4+
[![npm](http://img.shields.io/npm/v/jsonc.svg)](https://www.npmjs.com/package/jsonc)
5+
[![release](https://img.shields.io/github/release/onury/jsonc.svg)](https://github.com/onury/jsonc)
6+
[![dependencies](https://david-dm.org/onury/jsonc.svg)](https://david-dm.org/onury/jsonc)
7+
[![license](http://img.shields.io/npm/l/jsonc.svg)](https://github.com/onury/jsonc/blob/master/LICENSE)
8+
[![maintained](https://img.shields.io/maintenance/yes/2018.svg)](https://github.com/onury/jsonc/graphs/punch-card)
9+
10+
> © 2018, Onur Yıldırım ([@onury](https://github.com/onury)). MIT License.
11+
12+
Everything you need in JSON land.
13+
14+
`npm i jsonc`
15+
16+
## Features
17+
18+
- Parse JSON with comments.
19+
- Stringify objects with circular references.
20+
- Safely parse / stringify without try/catch blocks.
21+
- Read and auto-parse JSON files gracefully, sync or async (with promises).
22+
- Auto-stringify and write JSON files gracefully, sync or async (with promises).
23+
- Strips UTF-8 BOM.
24+
- Log objects as JSON (without worrying about errors).
25+
- Uglify/beautify JSON strings.
26+
- More helpful JSON errors.
27+
- Friendly API.
28+
- TypeScript support.
29+
30+
## Usage
31+
32+
See the concise [API reference][docs-api].
33+
34+
```js
35+
const jsonc = require('jsonc');
36+
// or
37+
import { jsonc } from 'jsonc';
38+
```
39+
40+
This is safe for JSON with comments:
41+
```js
42+
jsonc.parse('// comment\n{"data": /* comment */ "value"}\n'); // » { data: 'value' }
43+
```
44+
45+
And this is safe for circular references:
46+
```js
47+
const obj = { x: 1 };
48+
obj.y = obj; // circular
49+
jsonc.stringify(obj); // » { x: 1, y: '[Circular]' }
50+
```
51+
52+
But this is seriously safe:
53+
```js
54+
// safe version of every method
55+
const jsonc = require('jsonc').safe;
56+
// or
57+
import { safe as jsonc } from 'jsonc';
58+
59+
const [err, result] = jsonc.parse('[invalid JSON}');
60+
if (err) {
61+
console.log(`Failed to parse JSON: ${err.message}`);
62+
} else {
63+
console.log(result);
64+
}
65+
```
66+
67+
## Documentation
68+
69+
See the concise [API reference][docs-api].
70+
71+
## Change Log
72+
73+
- **v1.0.0** (2018-10-10)
74+
+ Initial release.
75+
76+
77+
## License
78+
MIT.
79+
80+
81+
[docs-api]:https://onury.io/jsonc/api
82+
[strip-json-comments]:https://github.com/sindresorhus/strip-json-comments
83+
[json-stringify-safe]:https://github.com/isaacs/json-stringify-safe
84+
[parse-json]:https://github.com/sindresorhus/parse-json
85+
[fs-extra]:https://www.npmjs.com/package/fs-extra

docma.json

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"debug": 5,
3+
"jsdoc": {
4+
"encoding": "utf8",
5+
"recurse": false,
6+
"pedantic": false,
7+
"access": ["public"],
8+
"package": null,
9+
"module": true,
10+
"undocumented": false,
11+
"undescribed": false,
12+
"ignored": false,
13+
"hierarchy": true,
14+
"sort": "grouped",
15+
"relativePath": null,
16+
"filter": null,
17+
"allowUnknownTags": true,
18+
"plugins": [],
19+
"includePattern": ".+\\.js(doc|x)?$"
20+
},
21+
"markdown": {
22+
"gfm": true,
23+
"tables": true,
24+
"breaks": false,
25+
"pedantic": false,
26+
"sanitize": false,
27+
"smartLists": true,
28+
"smartypants": false,
29+
"tasks": true,
30+
"emoji": true
31+
},
32+
"app": {
33+
"title": "jsonc",
34+
"meta": null,
35+
"base": "/jsonc",
36+
"entrance": "content:guide",
37+
"routing": "path",
38+
"server": "github"
39+
},
40+
"template": {
41+
"path": "zebra",
42+
"options": {
43+
"title": {
44+
"label": "jsonc",
45+
"href": "/jsonc/?"
46+
},
47+
"logo": null, // URL String or { dark: String, light: String }
48+
"sidebar": {
49+
"enabled": true,
50+
"outline": "tree", // "flat" | "tree"
51+
"collapsed": false,
52+
"toolbar": true,
53+
"itemsFolded": false,
54+
"itemsOverflow": "crop", // "crop" | "shrink"
55+
"badges": true, // true | false | <string-value>
56+
"search": true,
57+
"animations": true
58+
},
59+
"symbols": {
60+
"autoLink": true, // "internal" | "external" | true (both)
61+
"params": "list", // "list" | "table"
62+
"enums": "list", // "list" | "table"
63+
"props": "list", // "list" | "table"
64+
"meta": false
65+
},
66+
"contentView": {
67+
"bookmarks": "h1,h2,h3"
68+
},
69+
"navbar": {
70+
"enabled": true,
71+
"fixed": true,
72+
"dark": false,
73+
"animations": true,
74+
"menu": [
75+
{
76+
"iconClass": "ico-mouse-pointer",
77+
"label": "Guide",
78+
"href": "./"
79+
},
80+
{
81+
"iconClass": "ico-book",
82+
"label": "API Reference",
83+
"href": "./api"
84+
},
85+
{
86+
"iconClass": "ico-md ico-download",
87+
"label": "Download",
88+
"items": [
89+
{
90+
"label": "<code>npm i jsonc</code>",
91+
"href": "https://www.npmjs.com/package/jsonc",
92+
"target": "_blank"
93+
},
94+
{
95+
"label": "<code>yarn add jsonc</code>",
96+
"href": "https://yarn.pm/jsonc",
97+
"target": "_blank"
98+
},
99+
{
100+
"separator": true
101+
},
102+
{
103+
"label": "Download as Archive",
104+
"href": "https://github.com/onury/jsonc/releases",
105+
"target": "_blank"
106+
}
107+
// ,
108+
// {
109+
// "separator": true
110+
// },
111+
// {
112+
// "label": "Change Log",
113+
// "href": "./changelog"
114+
// }
115+
]
116+
},
117+
{
118+
"iconClass": "ico-md ico-github",
119+
"label": "GitHub",
120+
"href": "https://github.com/onury/jsonc",
121+
"target": "_blank"
122+
}
123+
]
124+
}
125+
}
126+
},
127+
"src": [
128+
"./lib/**/*.js",
129+
// "./CHANGELOG.md",
130+
{
131+
"guide": "./README.md"
132+
}
133+
],
134+
"dest": "../onury.github.io/jsonc",
135+
"clean": true
136+
}

index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var jsonc = require('./lib/jsonc').jsonc;
2+
module.exports = jsonc;
3+
// adding circular ref to allow easy importing in both ES5/6 and TS projects
4+
module.exports.jsonc = jsonc;
5+
module.exports.safe = jsonc.safe;

lib/helper.d.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as mkdirp from 'mkdirp';
2+
import { IConfig, IStringifyOptions, Replacer } from './interfaces';
3+
declare const helper: {
4+
isObject(o: any): boolean;
5+
isPrimitive(value: any): boolean;
6+
strLog(value: any, pretty: boolean): string;
7+
getLogger(config: IConfig, pretty: boolean): Function;
8+
getStringifyOptions(options: IStringifyOptions | Replacer, space: string | number): IStringifyOptions;
9+
fs: any;
10+
mkdirp: typeof mkdirp;
11+
promise: {
12+
readFile: any;
13+
writeFile: any;
14+
mkdirp: any;
15+
};
16+
safeSync(fn: any): any;
17+
safeAsync(promise: Promise<any>): Promise<any>;
18+
};
19+
export { helper };

0 commit comments

Comments
 (0)