# json-easy-strip

> Load and strip JS-type comments from JSON file, easy and fast!

Latest version **1.0.6** (published 2020-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-easy-strip
pnpm add json-easy-strip
yarn add json-easy-strip
bun add json-easy-strip
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2020-07-19 |
| First published | 2020-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | tarkh |
| Maintainers | tarkh |
| Keywords | json, remove, comments, easy, fast, parse, config, configuration, settings, strip, delete, filter |

## Links

- npm: https://www.npmjs.com/package/json-easy-strip
- Repository: https://github.com/tarkh/json-easy-strip
- Homepage: https://github.com/tarkh/json-easy-strip#readme
- Issues: https://github.com/tarkh/json-easy-strip/issues
- npm.io page: https://npm.io/package/json-easy-strip

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.6 (latest) — 2020-07-19
- 1.0.5 — 2020-07-17
- 1.0.4 — 2020-07-17
- 1.0.3 — 2020-07-17
- 1.0.2 — 2020-07-17
- 1.0.1 — 2020-07-17

## README

# json-easy-strip
> Load and strip JS-type comments from JSON file, easy and fast!

- Works with all JS-type comments
- File caching functionality
- Optional access to strip method only
- Super easy and fast
- 999 bytes, 44 lines of code (with comments!)

## Install
```
$ npm install json-easy-strip
```

## Usage
#### sweet.json:
```js
{
	/*
	 * Sweet section
	 */
	"fruit": "Watermelon", // Yes, watermelons is sweet!
	"dessert": /* Yummy! */ "Cheesecake",
	// And finally
	"drink": "Milkshake - /* strawberry */ or // chocolate!" // Mmm...
}
```

#### index.js:
```js
const requireJSON = require('json-easy-strip');
const obj = requireJSON('./sweet.json');
console.log(obj);

//  {
//    fruit: 'Watermelon',
//    dessert: 'Cheesecake',
//    drink: 'Milkshake - /* strawberry */ or // chocolate!'
//  }

```
#### Caching
Enabled by default, but you always can flush it
```js
const path = require('path');
const requireJSON = require('json-easy-strip');

// Loads, strips and parse sweet.json, puts it
// in the cache, and then returns a JSON object
const obj = requireJSON('./sweet.json');

// Returns a JSON object from cache
const obj2 = requireJSON('./sweet.json');

// Flushes the cache as in the standard require() function
delete requireJSON.cache[path.resolve('./sweet.json')];

// Again loads, strips and parse sweet.json and
// puts it in the cache
const obj3 = requireJSON('./sweet.json');

```
#### Access to strip method only
If you don't need to load file, only strip method is avaliable
```js
const requireJSON = require('json-easy-strip');

const jsonString = `{
	/*
	 * Sweet section
	 */
	"fruit": "Watermelon", // Yes, watermelons is sweet!
	"dessert": /* Yummy! */ "Cheesecake",
	// And finally
	"drink": "Milkshake - /* strawberry */ or // chocolate!" // Mmm...
}`;

const obj = requireJSON.strip(jsonString);
console.log(obj);

//  {
//    fruit: 'Watermelon',
//    dessert: 'Cheesecake',
//    drink: 'Milkshake - /* strawberry */ or // chocolate!'
//  }
```

## API
### requireJSON(path)
#### path
Type: `string`  
Path to JSON file.

#### returns
Type: `object`  
The function returns a parsed JSON object, as the standard require() function does.

### requireJSON.strip(data)
#### data
Type: `string`  
Stringified JSON data, loaded or recieved from elsewhere.

#### returns
Type: `object`  
The function returns a parsed JSON object.

### requireJSON.cache
Type: `object`  
Contains cached data as key (file path) => value (JSON object).

---
_Source: https://npm.io/package/json-easy-strip · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
