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

utility

Package Overview
Dependencies
Maintainers
3
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utility - npm Package Compare versions

Comparing version 1.13.1 to 1.14.0

6

History.md
1.14.0 / 2018-06-29
==================
**features**
* [[`d401917`](http://github.com/node-modules/utility/commit/d401917f20f89c52be237279d575c695f1bf6ae0)] - feat: add replacer and space to writeJSON* (#34) (Khaidi Chu <<i@2333.moe>>)
1.13.1 / 2017-10-17

@@ -3,0 +9,0 @@ ==================

20

lib/json.js

@@ -22,7 +22,13 @@ 'use strict';

exports.writeJSONSync = function(filepath, str) {
exports.writeJSONSync = function(filepath, str, options) {
options = options || {};
if (!('space' in options)) {
options.space = 2;
}
mkdirp.sync(path.dirname(filepath));
if (typeof str === 'object') {
str = JSON.stringify(str, null, 2) + '\n';
str = JSON.stringify(str, options.replacer, options.space) + '\n';
}
fs.writeFileSync(filepath, str);

@@ -44,6 +50,12 @@ };

exports.writeJSON = function(filepath, str) {
exports.writeJSON = function(filepath, str, options) {
options = options || {};
if (!('space' in options)) {
options.space = 2;
}
if (typeof str === 'object') {
str = JSON.stringify(str, null, 2) + '\n';
str = JSON.stringify(str, options.replacer, options.space) + '\n';
}
return mkdir(path.dirname(filepath))

@@ -50,0 +62,0 @@ .then(function() {

2

package.json
{
"name": "utility",
"version": "1.13.1",
"version": "1.14.0",
"description": "A collection of useful utilities.",

@@ -5,0 +5,0 @@ "main": "lib/utility.js",

@@ -227,3 +227,6 @@ # utility

const pkg = utils.readJSONSync('package.json');
utils.writeJSONSync('package.json', pkg);
utils.writeJSONSync('package.json', pkg, {
replacer: null,
space: '\t',
});
```

@@ -240,2 +243,14 @@

> **Hint:** In `utils.writeJSON*()`, if `pkg` is an object, the **optional** third parameter `options` may contain two
> keys.
>
> + `replacer`: Equals to `JSON.stringify()`'s second parameter;
> + `space`: Equals to `JSON.stringify()`'s third parameter. Defaults to `2`.
>
> Refs:
>
> + https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter
> + https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument
### Object.assign

@@ -242,0 +257,0 @@

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