How to use json-stable-stringify - 10 common examples

To help you get started, we’ve selected a few json-stable-stringify 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 algolia / marvel-search / lib / step5-download-marvel.js View on Github external
let batchPromises = _.map(results, (result) => {
    let savePath = `${distPath}${result.id}.json`;
    let stringContent = stringify(result, {space: '  '});

    return (callback) => {
      // Force JSON to order keys, so diffs are easier to read
      fs.writeFile(savePath, stringContent, () => {
        callback(null, result);
      });
    };
  });
github embroider-build / embroider / packages / core / src / template-compiler.ts View on Github external
private setup() {
    let syntax = loadGlimmerSyntax(this.params.compilerPath);
    initializeEmberENV(syntax, this.params.EmberENV);
    let cacheKey = createHash('md5')
      .update(
        stringify({
          // todo: get resolver reflected in cacheKey
          syntax: syntax.cacheKey,
        })
      )
      .digest('hex');
    return { syntax, cacheKey };
  }
github sourcecred / sourcecred / src / v1 / plugins / git / bin / loadAndPrintRepository.js View on Github external
function main() {
  const args = parseArgs();
  const result = loadRepository(args.repositoryPath, args.rootRef);
  console.log(stringify(result, {space: 4}));
}
github elastic / kibana / src / es_archiver / lib / archives / format.js View on Github external
    createMapStream(record => stringify(record, { space: '  ' })),
    createIntersperseStream(RECORD_SEPARATOR),
github elastic / kibana / x-pack / plugins / infra / server / lib / domains / log_entries_domain / log_entries_domain.ts View on Github external
columns: logColumns.map(logColumn => {
    if (SavedSourceConfigurationTimestampColumnRuntimeType.is(logColumn)) {
      return {
        timestamp: document.key.time,
      };
    } else if (SavedSourceConfigurationMessageColumnRuntimeType.is(logColumn)) {
      return {
        message: formatLogMessage(document.fields),
      };
    } else {
      return {
        field: logColumn.fieldColumn.field,
        value: stringify(document.fields[logColumn.fieldColumn.field] || null),
      };
    }
  }),
});
github sourcecred / sourcecred / src / v3 / core / _address.js View on Github external
arr.forEach((s: string) => {
    if (s == null) {
      throw new Error(`${what}: ${String(s)} in ${stringify(arr)}`);
    }
    if (s.indexOf(SEPARATOR) !== -1) {
      throw new Error(`${what}: NUL char: ${stringify(arr)}`);
    }
  });
}
github sourcecred / sourcecred / src / v1 / plugins / github / porcelain.js View on Github external
mergeCommitHash(): ?string {
    const mergeEdge = this.neighbors({
      edgeType: MERGED_AS_EDGE_TYPE,
      nodeType: COMMIT_NODE_TYPE,
      direction: "OUT",
    }).map(({edge}) => edge);
    if (mergeEdge.length > 1) {
      throw new Error(
        `Node at ${stringify(this.address())} has too many MERGED_AS edges`
      );
    }
    if (mergeEdge.length === 0) {
      return null;
    }
    const payload: MergedAsEdgePayload = (mergeEdge[0].payload: any);
    return payload.hash;
  }
github appbaseio / appbase-js / src / core / api / searchStreamToURL.js View on Github external
} else if (webhook === Object(webhook)) {
    webhooks.push(webhook);
  } else {
    throw new Error('fields missing: second argument(webhook) is necessary');
  }

  const populateBody = () => {
    bodyCopy = {};
    bodyCopy.webhooks = webhooks;
    bodyCopy.query = query;
    bodyCopy.type = type;
  };

  populateBody();

  const encode64 = btoa(stringify(query));
  const path = `.percolator/webhooks-0-${typeString}-0-${encode64}`;

  this.change = () => {
    webhooks = [];

    if (typeof parsedArgs === 'string') {
      const webhook2 = {};
      webhook2.url = parsedArgs;
      webhook2.method = 'POST';
      webhooks.push(webhook2);
    } else if (parsedArgs.constructor === Array) {
      webhooks = parsedArgs;
    } else if (parsedArgs === Object(parsedArgs)) {
      webhooks.push(parsedArgs);
    } else {
      throw new Error('fields missing: one of webhook or url fields is required');
github sourcecred / sourcecred / src / plugins / github / relationalView.js View on Github external
function assertExists(item: ?T, address: N.StructuredAddress): T {
  if (item == null) {
    throw new Error(
      `Invariant violation: Expected entity for ${stringify(address)}`
    );
  }
  return item;
}
github sourcecred / sourcecred / src / core / repoIdRegistry.js View on Github external
export function writeRegistry(
  registry: RepoIdRegistry,
  sourcecredDirectory: string
) {
  const registryFile = path.join(sourcecredDirectory, REPO_ID_REGISTRY_FILE);
  fs.writeFileSync(registryFile, stringify(toJSON(registry)));
}

json-stable-stringify

deterministic JSON.stringify() with custom sorting to get deterministic hashes from stringified results

MIT
Latest version published 10 months ago

Package Health Score

74 / 100
Full package analysis

Popular json-stable-stringify functions