Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

edit-json-file

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

edit-json-file - npm Package Compare versions

Comparing version 1.2.1 to 1.3.1

8

lib/index.js

@@ -13,3 +13,4 @@ "use strict";

fs = require("fs"),
iterateObject = require("iterate-object");
iterateObject = require("iterate-object"),
os = require('os');

@@ -28,2 +29,3 @@ var JsonEditor = function () {

* - `stringify_fn` (Function): A function used by `JSON.stringify`.
* - `stringify_eol` (Boolean): Wheter to add the new line at the end of the file or not (default: `false`)
* - `autosave` (Boolean): Save the file when setting some data in it.

@@ -39,2 +41,3 @@ *

options.stringify_fn = options.stringify_fn || null;
options.stringify_eol = options.stringify_eol || false;
this.path = path;

@@ -185,3 +188,4 @@ this.data = this.read();

value: function save(cb) {
this.write(JSON.stringify(this.data, this.options.stringify_fn, this.options.stringify_width), cb);
var data = JSON.stringify(this.data, this.options.stringify_fn, this.options.stringify_width, this.options.stringify_eol);
this.write(this.options.stringify_eol ? data + os.EOL : data, cb);
return this;

@@ -188,0 +192,0 @@ }

@@ -13,3 +13,3 @@ {

"license": "MIT",
"version": "1.2.1",
"version": "1.3.1",
"main": "lib/index.js",

@@ -47,5 +47,5 @@ "scripts": {

"r-json": "^1.2.5",
"set-value": "^0.4.0",
"set-value": "^3.0.1",
"w-json": "^1.3.5"
}
}

@@ -1,28 +0,49 @@

<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->
# edit-json-file
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/edit-json-file.svg)](https://www.npmjs.com/package/edit-json-file) [![Downloads](https://img.shields.io/npm/dt/edit-json-file.svg)](https://www.npmjs.com/package/edit-json-file) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
Edit a json file with ease.
<a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>
> Edit a json file with ease.
## :cloud: Installation
## Installation
```sh
# Using npm
npm install --save edit-json-file
# Using yarn
yarn add edit-json-file
$ npm i edit-json-file
```
## :clipboard: Example
## Example
```js
"use strict";
const editJsonFile = require("edit-json-file");

@@ -68,2 +89,3 @@

// a: { new: { field: [Object] } } }
```

@@ -73,14 +95,9 @@

## :question: Get Help
There are few ways to get help:
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
2. For bug reports and feature requests, open issues. :bug:
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
## Documentation
## :memo: Documentation

@@ -91,3 +108,2 @@

#### Params
- **String** `path`: The path to the JSON file.

@@ -97,2 +113,3 @@ - **Object** `options`: An object containing the following fields:

- `stringify_fn` (Function): A function used by `JSON.stringify`.
- `stringify_eol` (Boolean): Wheter to add the new line at the end of the file or not (default: `false`)
- `autosave` (Boolean): Save the file when setting some data in it.

@@ -107,3 +124,2 @@

#### Params
- **String** `path`: The object path.

@@ -119,3 +135,2 @@ - **Anything** `value`: The value.

#### Params
- **String** `path`:

@@ -130,3 +145,2 @@

#### Params
- **String** `path`: The object path.

@@ -141,3 +155,2 @@

#### Params
- **Function** `cb`: An optional callback function which will turn the function into an asynchronous one.

@@ -153,3 +166,2 @@

#### Params
- **String** `The`: file content.

@@ -165,3 +177,2 @@ - **Function** `cb`: An optional callback function which will turn the function into an asynchronous one.

#### Params
- **Function** `cb`: The callback function.

@@ -173,3 +184,2 @@

#### Params
- **Function** `cb`: An optional callback function which will turn the function into an asynchronous one.

@@ -189,3 +199,2 @@

#### Params
- **String** `path`: The path to the JSON file.

@@ -199,68 +208,16 @@ - **Object** `options`: An object containing the following fields:

## :yum: How to contribute
Have an idea? Found a bug? See [how to contribute][contributing].
## :sparkling_heart: Support my projects
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it).
## How to contribute
Have an idea? Found a bug? See [how to contribute][contributing].
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
- Starring and sharing the projects you like :rocket:
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book:
- [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
- [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
- **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
## License
See the [LICENSE][license] file.
![](https://i.imgur.com/z6OQI95.png)
Thanks! :heart:
## :dizzy: Where is this library used?
If you are using this library in one of your projects, add it in this list. :sparkles:
- [`blip-lang`](https://github.com/ZippyMagician/Blip#readme) (by Joshua Barnett)—A programming language
- [`bloggify-tools`](https://github.com/Bloggify/bloggify-tools)—Interactive command line tool to help you win at Bloggify.
- [`deyarn`](https://npmjs.com/package/deyarn) (by Spencer Brown)—A command-line tool for converting projects that use Yarn to npm.
- [`easybackup`](https://npmjs.com/package/easybackup) (by Bruno Morceli - pirofagista@gmail.com)—Easy way to backup/restore multiple mongodb databases.
- [`extracct`](https://npmjs.com/package/extracct) (by awyerbx)—Node Module
- [`fix-package-versions`](https://github.com/segux/fix-package-versions#readme) (by Jose Segura García)—This is the first approach to a fix package.json versions
- [`gyaon-cli`](https://npmjs.com/package/gyaon-cli) (by stkay)—
- [`jollof-cli`](https://npmjs.com/package/jollof-cli) (by Iyobo Eki)—The Entry point to creating and working with Jollof Projects
- [`jollofjs`](https://npmjs.com/package/jollofjs) (by Iyobo Eki)—The Entry point to creating and working with Jollof Projects
- [`live-stream-radio`](https://github.com/torch2424/live-stream-radio#readme) (by Aaron Turner)—24/7 live stream video radio station CLI / API
- [`lyo`](https://github.com/bokub/lyo) (by Boris K)—Node.js to browser - The easy way
- [`menreiki-init`](https://npmjs.com/package/menreiki-init)—用于创建menreiki项目骨架
- [`menreiki2`](http://gitlab.alipay-inc.com/oc/spa#readme) (by 汗僧)—ssr with react
- [`node-file-rev`](https://github.com/lukasoppermann/node-file-rev#readme) (by Lukas Oppermann)—Simple node cli tool to revision files and write them to a rev-manifest.json
- [`pandocuments`](https://github.com/kontheocharis/pandocuments#readme) (by Constantine Theocharis)—A pandoc helper to quickly initialize school papers (very opinionated)
- [`pipe-boy`](https://github.com/slammayjammay/pipe-boy#readme) (by Scott McKenzie)—Interactive CLI to pass output from one command as input to another
- [`project-initializer`](https://npmjs.com/package/project-initializer) (by Linesh)—A command utility to different kinds of projects with different tech stacks.
- [`returrn`](https://npmjs.com/package/returrn) (by awyerbx)—Return everything you need.
- [`uiseeds`](https://github.com/codechavez/uiseeds#readme) (by Victor Chavez)—uiseeds is an easy to use tool to create seed projects for Angular
- [`webify-generator`](https://github.com/sdantuoni/webify-generator#readme) (by Santiago D´Antuoni)—A web application generator
## :scroll: License
[MIT][license] © [Ionică Bizău][website]
[badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg
[badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg
[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg
[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg
[patreon]: https://www.patreon.com/ionicabizau
[amazon]: http://amzn.eu/hRo9sIZ
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW
[license]: http://showalicense.com/?fullname=Ionic%C4%83%20Biz%C4%83u%20%3Cbizauionica%40gmail.com%3E%20(https%3A%2F%2Fionicabizau.net)&year=2015#license-mit
[website]: https://ionicabizau.net
[license]: /LICENSE
[contributing]: /CONTRIBUTING.md
[docs]: /DOCUMENTATION.md
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc