Skip to content

Commit 6d37bac

Browse files
committed
Initial commit
1 parent b48e191 commit 6d37bac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6486
-0
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extends: standard

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
.eslintcache
3+
.nyc_output
4+
coverage
5+
dist
6+
node_modules

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: node_js
2+
cache:
3+
directories:
4+
- ~/.npm
5+
notifications:
6+
email: false
7+
node_js:
8+
- node
9+
- lts/*
10+
- 8
11+
after_success:
12+
- npx codecov
13+
- npx semantic-release
14+
branches:
15+
except:
16+
- /^v\d+\.\d+\.\d+$/

.vscode/launch.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "tests",
11+
"program": "${workspaceFolder}/node_modules/ava/profile.js",
12+
"args": [
13+
"${file}",
14+
"--serial"
15+
],
16+
"skipFiles": [
17+
"<node_internals>/**"
18+
]
19+
},
20+
21+
]
22+
}

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files.exclude": {
3+
"**/.git": true,
4+
"**/.DS_Store": true,
5+
"**/dist": true
6+
}
7+
}

README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# rollup-plugin-jsonlint
2+
3+
[![NPM version](https://badge.fury.io/js/rollup-plugin-jsonlint.svg)](https://badge.fury.io/js/rollup-plugin-jsonlint)
4+
[![Build Status](https://travis-ci.com/prantlf/rollup-plugin-jsonlint.svg?branch=master)](https://travis-ci.com/prantlf/rollup-plugin-jsonlint)
5+
[![codecov](https://codecov.io/gh/prantlf/rollup-plugin-jsonlint/branch/master/graph/badge.svg)](https://codecov.io/gh/prantlf/rollup-plugin-jsonlint)
6+
[![Dependency Status](https://david-dm.org/prantlf/rollup-plugin-jsonlint.svg)](https://david-dm.org/prantlf/rollup-plugin-jsonlint)
7+
[![devDependency Status](https://david-dm.org/prantlf/rollup-plugin-jsonlint/dev-status.svg)](https://david-dm.org/prantlf/rollup-plugin-jsonlint#info=devDependencies)
8+
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
9+
10+
A [Rollup] plugin which converts `.json` files to ES6 modules. Recognizes standard [JSON], CJSON (JSON with comments) and [JSON5] (further more flexible JSON).
11+
12+
This plugin is based on [`@rollup/plugin-json`]. It supports all original options. It leverages the parser from [`@prantlf/jsonlint`] to provide better error information in case or invalid input and to parse JSON extensions like CJSON and JSON5. If no extension is enabled, the standard `JSON.parse` will be used for the best performance.
13+
14+
## Requirements
15+
16+
This plugin requires [Node.js] [LTS] (currently 12, at least 8) and Rollup 1.20 or newer.
17+
18+
## Installation
19+
20+
Using npm:
21+
22+
npm i -D rollup-plugin-jsonlint
23+
24+
## Usage
25+
26+
Create a `rollup.config.js` [configuration file] and import the plugin:
27+
28+
```js
29+
import jsonlint from 'rollup-plugin-jsonlint'
30+
31+
export default {
32+
input: 'src/index.js',
33+
output: {
34+
dir: 'output',
35+
format: 'cjs'
36+
},
37+
plugins: [jsonlint({ mode: 'cjson' })]
38+
}
39+
```
40+
41+
Then call `rollup` either via the [command-line] or the [programmatically].
42+
43+
With an accompanying file `src/index.js`, the local `package.json` file would now be importable as seen below:
44+
45+
```js
46+
import pkg from './package.json';
47+
console.log(`Running version ${pkg.version}.`);
48+
```
49+
50+
## Input Parsing Options
51+
52+
The following options customize the parser. If no default value is changed, only the standard JSON will be accepted.
53+
54+
### `mode`
55+
56+
Type: `String` (`json`|`cjson`|`json5`)<br>
57+
Default: `json`
58+
59+
A shortcut for setting the three boolean flags below.
60+
61+
* `json` - expects the standard JSON (uses defaults)
62+
* `cjson` - expects CJSON (sets `ignoreComments` to `true`)
63+
* `json5` - expects JSON5 (sets `ignoreComments`, `ignoreTrailingCommas` and `allowSingleQuotedStrings` to `true`)
64+
65+
### `ignoreComments`
66+
67+
Type: `Boolean`<br>
68+
Default: `false`
69+
70+
If `true`, single-line and multi-line JavaScript-style comments will be ignored as another "whitespace". (CJSON and JSON5 feature)
71+
72+
### `ignoreTrailingCommas`
73+
74+
Type: `Boolean`<br>
75+
Default: `false`
76+
77+
If `true`, trailing commas after the last object entry and array items will be ignored without throwing an error. (JSON5 feature)
78+
79+
### `allowSingleQuotedStrings`
80+
81+
Type: `Boolean`<br>
82+
Default: `false`
83+
84+
If `true`, single quotes will be accepted in addition to double quotes as characters for enclosing string literals within. (JSON5 feature)
85+
86+
### `allowDuplicateObjectKeys`
87+
88+
Type: `Boolean`<br>
89+
Default: `true`
90+
91+
If `false`, duplicate object keys will be reported as an error. Useful for detecting mistakes in configuration files, where duplicate keys usually mean old properties forgotten to be deleted.
92+
93+
## Module Generation Options
94+
95+
The following options customize the ES6 module generator.
96+
97+
### `compact`
98+
99+
Type: `Boolean`<br>
100+
Default: `false`
101+
102+
If `true`, instructs the plugin to ignore `indent` and generate the smallest code.
103+
104+
### `exclude`
105+
106+
Type: `String` | `Array[...String]`<br>
107+
Default: `null`
108+
109+
A [minimatch pattern], or array of patterns, which specifies the files in the build the plugin should *ignore*. By default no files are ignored.
110+
111+
### `include`
112+
113+
Type: `String` | `Array[...String]`<br>
114+
Default: `null`
115+
116+
A [minimatch pattern], or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.
117+
118+
### `indent`
119+
120+
Type: `String`<br>
121+
Default: `'\t'`
122+
123+
Specifies the indentation for the generated default export.
124+
125+
### `namedExports`
126+
127+
Type: `Boolean`<br>
128+
Default: `true`
129+
130+
If `true`, instructs the plugin to generate a named export for every property of the JSON object.
131+
132+
### `preferConst`
133+
134+
Type: `Boolean`<br>
135+
Default: `false`
136+
137+
If `true`, instructs the plugin to declare properties as variables, using either `var` or `const`. This pertains to tree-shaking.
138+
139+
## License
140+
141+
Copyright (C) 2019 Ferdinand Prantl
142+
143+
Licensed under the [MIT License].
144+
145+
[MIT License]: http://en.wikipedia.org/wiki/MIT_License
146+
[Rollup]: https://rollupjs.org/
147+
[JSON]: https://tools.ietf.org/html/rfc8259
148+
[JSON5]: https://spec.json5.org
149+
[`@prantlf/jsonlint`]: https://github.com/prantlf/jsonlint#readme
150+
[`@rollup/plugin-json`]: https://github.com/rollup/plugins/tree/master/packages/json#rollupplugin-json
151+
[Node.js]: https://nodejs.org/
152+
[LTS]: https://github.com/nodejs/Release
153+
[configuration file]: https://www.rollupjs.org/guide/en/#configuration-files
154+
[command-line]: https://www.rollupjs.org/guide/en/#command-line-reference
155+
[programmatically]: https://www.rollupjs.org/guide/en/#javascript-api
156+
[minimatch pattern]: https://github.com/isaacs/minimatch

index.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Plugin } from 'rollup'
2+
3+
export interface RollupJsonLintOptions {
4+
/**
5+
* All JSON files will be parsed by default,
6+
* but you can also specifically include files.
7+
*/
8+
include?: string | RegExp | ReadonlyArray<string | RegExp> | null
9+
/**
10+
* All JSON files will be parsed by default,
11+
* but you can also specifically exclude files.
12+
*/
13+
exclude?: string | RegExp | ReadonlyArray<string | RegExp> | null
14+
/**
15+
* For tree-shaking, properties will be declared as variables, using
16+
* either `var` or `const`.
17+
* @default false
18+
*/
19+
preferConst?: boolean
20+
/**
21+
* Specifies indentation for the generated default export.
22+
* @default '\t'
23+
*/
24+
indent: string
25+
/**
26+
* Ignores indent and generates the smallest code.
27+
* @default false
28+
*/
29+
compact: boolean
30+
/**
31+
* Generates a named export for every property of the JSON object.
32+
* @default true
33+
*/
34+
namedExports: true
35+
}
36+
37+
/**
38+
* Converts .json (JSON/CJSON/JSON5) files to ES6 modules.
39+
*/
40+
export default function jsonlint (options?: RollupJsonLintOptions): Plugin

0 commit comments

Comments
 (0)