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

replace-json-property

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

replace-json-property - npm Package Compare versions

Comparing version 1.7.1 to 1.8.0

7

bin/replace-json-property.bin.js

@@ -18,2 +18,6 @@ #!/usr/bin/env node

.option('--silent [boolean]', 'Silent mode. Executes without log messages')
.option(
'--limit [number]',
'Limit the maximum number of replacements, for example (1, 4)'
)
.action(function(path, property, value) {

@@ -23,5 +27,6 @@ replaceJsonProperty.replace(path, property, value, {

EOL: commander.eol,
silent: commander.silent
silent: commander.silent,
limit: commander.limit
});
})
.parse(process.argv);

2

package.json
{
"name": "replace-json-property",
"version": "1.7.1",
"version": "1.8.0",
"description": "CLI tool to replace a property in a JSON file",

@@ -5,0 +5,0 @@ "main": "src/replace-json-property.js",

@@ -76,4 +76,2 @@

## Usage from code

@@ -87,3 +85,3 @@

import {replace} from 'replace-json-property';
replace('./environment/test.json', 'foo', 'new value');

@@ -96,8 +94,6 @@ ```

const replaceJSONProperty = require('replace-json-property');
replaceJSONProperty.replace('./environment/test.json', 'foo', 'new value');
```
## Options

@@ -112,5 +108,4 @@

| --silent | Silent mode. Executes without log messages | False |
| --limit | Limit the number of replacements | 0 (unlimited) |
## Help command

@@ -117,0 +112,0 @@

@@ -7,2 +7,3 @@ const jsonfile = require('jsonfile');

EOL: '\n',
LIMIT: 0,
SILENT: false

@@ -17,10 +18,11 @@ };

EOL: (options && options.EOL) || DEFAULT_OPTIONS.EOL,
silent: (options && options.silent) || DEFAULT_OPTIONS.SILENT
silent: (options && options.silent) || DEFAULT_OPTIONS.SILENT,
limit: parseInt((options && options.limit) || DEFAULT_OPTIONS.LIMIT, 10)
};
try {
const file = readFile(path, property, newValue);
const file = readFile(path, property, newValue, options.limit);
jsonfile.writeFileSync(path, file, options);
if (!options.silent) {
log.success(
`Property: "${property}" in file: ${path} successfully overwritten with "${newValue}"`
`Properties: "${property}" in file: ${path} successfully overwritten with "${newValue}"`
);

@@ -33,6 +35,11 @@ }

const readFile = (path, property, newValue) => {
const readFile = (path, property, newValue, limit) => {
let limitCounter = 0;
return jsonfile.readFileSync(path, {
reviver: (key, value) => {
if (key === property) {
if (limit > 0 && limitCounter >= limit) {
return value;
}
++limitCounter;
return newValue;

@@ -39,0 +46,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