How to use jju - 10 common examples

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 / just / packages / just-scripts-utils / src / rush.ts View on Github external
export function _parseRushJson(rushJsonContents: string): RushJson | undefined {
  try {
    // rush.json can contain comments, so we have to use a json library which supports comments
    // (instead of JSON.parse/JSON.stringify)
    return jju.parse(rushJsonContents, { mode: 'cjson' });
  } catch {
    return undefined;
  }
}
github microsoft / rushstack / libraries / node-core-library / src / JsonFile.ts View on Github external
public static load(jsonFilename: string): any {
    // tslint:disable-line:no-any
    if (!FileSystem.exists(jsonFilename)) {
      throw new Error(`Input file not found: ${jsonFilename}`);
    }

    const contents: string = FileSystem.readFile(jsonFilename);
    try {
      return jju.parse(contents);
    } catch (error) {
      throw new Error(`Error reading "${jsonFilename}":` + os.EOL + `  ${error.message}`);
    }
  }
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 microsoft / rushstack / libraries / node-core-library / src / JsonFile.ts View on Github external
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) {
      switch (options.newlineConversion) {
        case NewlineKind.CrLf:
          return Text.convertToCrLf(stringified);
        case NewlineKind.Lf:
          return Text.convertToLf(stringified);
github microsoft / just / packages / just-scripts-utils / src / __tests__ / rush.spec.ts View on Github external
it('parses file', () => {
    const rushJsonParsed = jju.parse(rushJsonStr, { mode: 'cjson' });
    expect(_parseRushJson(rushJsonStr)).toEqual(rushJsonParsed);
  });
});
github rlidwka / jju / tokenizer.html View on Github external
function on_textarea_update() {
 try {
  var tokens = jju.tokenize($('textarea').val())
 } catch(err) {
  return console.log(err)
 }
 
 function tr(html) {
  return '' + html + ''
 }
 
 function td(text) {
  var node = $('')
  node.text(text)
  return node[0].outerHTML
 }
 
 $('#tokens .data').remove()
github OfficeDev / office-ui-fabric-react / scripts / read-config.js View on Github external
function readConfig(file) {
  file = findConfig(file);
  if (file && fs.existsSync(file)) {
    return jju.parse(fs.readFileSync(file, 'utf8'));
  }
}
github rlidwka / jju / editor.html View on Github external
function update_deps() {
   var items = $('#dependencies').val()
   if (items === _old_items) return
   _old_items = items
   
   var deps = {}
   var json = jju.parse($('textarea').val())
   $('#dependencies').tagsinput('items').forEach(function(x) {
    deps[x] = (json.dependencies && json.dependencies[x]) || '*'
   })
   on_input_update('dependencies', deps)
  }
 })()
github ds300 / react-native-typescript-transformer / index.js View on Github external
function loadJsonFile(jsonFileName) {
  try {
    const buffer = fs.readFileSync(jsonFileName)
    const jju = require('jju')
    return jju.parse(buffer.toString())
  } catch (error) {
    throw new Error(
      `Error reading "${jsonFileName}":${os.EOL}  ${error.message}`
    )
  }
}

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