How to use the jju.update function in jju

To help you get started, we’ve selected a few jju examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / just / packages / just-scripts-utils / src / __tests__ / rush.spec.ts View on Github external
it('handles valid case', () => {
    // call this before mocking fs since it internally uses a dynamic require,
    // which doesn't work while fs is mocked (but if it's called before mocking,
    // the required file will be cached)
    jju.update('{}', {});

    mockfs({
      root1: { 'rush.json': rushJsonStrNoProjects }, // no projects yet
      root2: { 'rush.json': rushJsonStr } // already has a project
    });

    rushAddPackage('a', 'root1');
    expect(fs.readFileSync('root1/rush.json').toString()).toBe(rushJsonStr);

    rushAddPackage('b', 'root2');
    expect(fs.readFileSync('root2/rush.json').toString()).toBe(rushJsonUpdatedStr);
  });
github microsoft / rushstack / libraries / node-core-library / src / JsonFile.ts View on Github external
public static updateString(
    previousJson: string,
    newJsonObject: Object,
    options?: IJsonFileStringifyOptions
  ): string {
    if (!options) {
      options = {};
    }

    JsonFile.validateNoUndefinedMembers(newJsonObject);

    let stringified: string;

    if (previousJson !== '') {
      // NOTE: We don't use mode=json here because comments aren't allowed by strict JSON
      stringified = jju.update(previousJson, newJsonObject, {
        mode: 'cjson',
        indent: 2
      });
    } else if (options.prettyFormatting) {
      stringified = jju.stringify(newJsonObject, {
        mode: 'json',
        indent: 2
      });
    } else {
      stringified = JSON.stringify(newJsonObject, undefined, 2);
    }

    // Add the trailing newline
    stringified = Text.ensureTrailingNewline(stringified);

    if (options && options.newlineConversion) {
github OfficeDev / office-ui-fabric-react / scripts / write-config.js View on Github external
function writeConfig(file, newValue) {
  file = findConfig(file);
  if (!file) {
    return false;
  }

  const oldContents = fs.readFileSync(file, 'utf8');
  const newContents = jju.update(oldContents, newValue, {
    mode: 'cjson',
    indent: 2
  });
  fs.writeFileSync(file, newContents);
  return true;
}
github wiredmax / npm-json5 / lib / write.js View on Github external
function update(file, old_data, new_data) {
 if (file === "package.json5") {
		if (!old_data) {
			return json2json(new_data)
		} else {
			return require("jju").update(old_data, JSON.parse(new_data))
		}

	} else {
		if (!old_data) {
			return new_data
		} else {
			return require("jju").update(old_data, JSON.parse(new_data), {mode: "json"})
		}
	}
}
github microsoft / just / packages / just-scripts-utils / src / rush.ts View on Github external
const rushJson = _parseRushJson(oldContents);
  if (!rushJson) {
    logger.error(`Couldn't read rush.json under ${rootPath}. Not adding package.`);
    return;
  }

  if (!rushJson.projects) {
    rushJson.projects = [];
  }
  rushJson.projects.push({
    packageName,
    projectFolder: `packages/${packageName}`
  });

  try {
    const newContents = jju.update(oldContents, rushJson, { mode: 'cjson', indent: 2 });
    fs.writeFileSync(rushJsonPath, newContents);
  } catch (ex) {
    logger.error(`Couldn't update rush.json under ${rootPath}. Not adding package.`);
    logger.error('Error:', ex);
  }
}
github rlidwka / jju / editor.html View on Github external
function on_input_update(name, value) {
 var old_text = $('textarea').val()
 var json = jju.parse(old_text)
 
 if (value === '') {
  delete json[name]
 } else {
  json[name] = value
 }
 $('textarea').val(jju.update(old_text, json))
}
<a href="https://github.com/rlidwka/jju"><img class="forkme" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" src="https://github-camo.global.ssl.fastly.net/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"></a><nav class="navbar navbar-default" role="navigation"><div class="container-fluid"><div class="collapse navbar-collapse"><ul class="nav navbar-nav"><li><a href="index.html">Home</a></li><li><a href="readme.html">Readme</a></li><li class="active"><a href="editor.html">Demo - Editor</a></li><li><a href="tokenizer.html">Demo - Tokenizer</a></li></ul></div></div></nav><div class="container"><div class="row"><div class="col-md-6"><form class="form-horizontal" role="form"><div class="form-group my-cool-editor"><label class="control-label col-sm-2" for="name">Name</label><div class="col-sm-10"><input class="form-control" placeholder="foobar" type="text"></div><label class="control-label col-sm-2" for="version">Version</label><div class="col-sm-10"><input class="form-control" placeholder="1.2.3" type="text" id="version"></div><label class="control-label col-sm-2" for="description">Desc</label><div class="col-sm-10"><input class="form-control" placeholder="module that hopefully does something useful" type="text" id="description"></div><label class="control-label col-sm-2" for="author">Author</label><div class="col-sm-10"><input class="form-control" placeholder="My Name <my@email>" type="text" id="author"></div><label class="control-label col-sm-2" for="dependencies">Deps</label><div class="col-sm-10"><input class="form-control" data-role="tagsinput" placeholder="" type="text" id="dependencies"></div></div></form><pre class="error">Warning: you really need JavaScript to be enabled to get it working</pre></div><div class="col-md-6"><form role="form"><div class="form-group"><div class="col-sm-12"><label class="control-label" for="textarea">Copy-paste your package.json here:</label></div><div class="col-sm-12"><textarea class="form-control" rows="20" id="textarea">{ "name": "just-a-demo",</textarea></div></div></form></div></div></div>
github wiredmax / npm-json5 / lib / write.js View on Github external
function update(file, old_data, new_data) {
 if (file === "package.json5") {
		if (!old_data) {
			return json2json(new_data)
		} else {
			return require("jju").update(old_data, JSON.parse(new_data))
		}

	} else {
		if (!old_data) {
			return new_data
		} else {
			return require("jju").update(old_data, JSON.parse(new_data), {mode: "json"})
		}
	}
}

jju

a set of utilities to work with JSON / JSON5 documents

MIT
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis