How to use the write-json-file.sync function in write-json-file

To help you get started, we’ve selected a few write-json-file 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 DefinitelyTyped / DefinitelyTyped / types / write-json-file / write-json-file-tests.ts View on Github external
import * as write from 'write-json-file';

// Basic
write('foo.json', {foo: true}).then(() => { });
write.sync('foo.json', {foo: true});

// With options
const options: write.Options = {
    indent: '  ',
    detectIndent: true,
    sortKeys: true,
    mode: 0o666
};
write('foo.json', {foo: true}, options).then(() => { });
write.sync('foo.json', {foo: true}, options);

// JSON.stringify replacer
function replacer(key: any, value: any) {
  // Filtering out properties
  if (typeof value === 'string') {
    return undefined;
  }
  return value;
}

write.sync('foo.json', {foo: true}, {replacer});
write.sync('foo.json', {foo: true}, {replacer: null});
write.sync('foo.json', {foo: true}, {replacer: [1, 2, 3]});
write.sync('foo.json', {foo: true}, {replacer: ['a', 'b', 'c']});

JSON.stringify({foo: true}, replacer);
github mapbox / cross-street-indexer / lib / reducer.js View on Github external
// Main processing
    const quadkey = tilebelt.tileToQuadkey(tile);
    const features = sources.qatiles.osm.features;
    const highways = qaTilesFilter(features);
    const intersects = intersections(highways);
    const index = createIndex(intersects);

    // Create folder if does not exist
    if (!fs.existsSync(output)) mkdirp.sync(output);

    // Output Features for Testing purposes
    if (debug) {
        const debugPath = path.join(output, quadkey) + path.sep;

        // GeoJSON
        write.sync(debugPath + 'highways.geojson', featureCollection(highways));
        write.sync(debugPath + 'intersects.geojson', uniques2features(intersects));
        write.sync(debugPath + 'tile.geojson', feature(tilebelt.tileToGeoJSON(tile)));

        // Names
        const names = new Set([]);
        const namesEn = new Set([]);
        const namesFr = new Set([]);
        highways.forEach(feature => {
            if (feature.properties.name) names.add(feature.properties.name);
            if (feature.properties.ref) names.add(feature.properties.ref);
            if (feature.properties['name:en']) namesEn.add(feature.properties['name:en']);
            if (feature.properties['name:fr']) namesFr.add(feature.properties['name:fr']);
        });
        write.sync(debugPath + 'names.json', set2json(names));
        write.sync(debugPath + 'names:en.json', set2json(namesEn));
        write.sync(debugPath + 'names:fr.json', set2json(namesFr));
github mapbox / cross-street-indexer / lib / reducer.js View on Github external
const quadkey = tilebelt.tileToQuadkey(tile);
    const features = sources.qatiles.osm.features;
    const highways = qaTilesFilter(features);
    const intersects = intersections(highways);
    const index = createIndex(intersects);

    // Create folder if does not exist
    if (!fs.existsSync(output)) mkdirp.sync(output);

    // Output Features for Testing purposes
    if (debug) {
        const debugPath = path.join(output, quadkey) + path.sep;

        // GeoJSON
        write.sync(debugPath + 'highways.geojson', featureCollection(highways));
        write.sync(debugPath + 'intersects.geojson', uniques2features(intersects));
        write.sync(debugPath + 'tile.geojson', feature(tilebelt.tileToGeoJSON(tile)));

        // Names
        const names = new Set([]);
        const namesEn = new Set([]);
        const namesFr = new Set([]);
        highways.forEach(feature => {
            if (feature.properties.name) names.add(feature.properties.name);
            if (feature.properties.ref) names.add(feature.properties.ref);
            if (feature.properties['name:en']) namesEn.add(feature.properties['name:en']);
            if (feature.properties['name:fr']) namesFr.add(feature.properties['name:fr']);
        });
        write.sync(debugPath + 'names.json', set2json(names));
        write.sync(debugPath + 'names:en.json', set2json(namesEn));
        write.sync(debugPath + 'names:fr.json', set2json(namesFr));
github notadd / next / packages / injection / loaders / injection.loader.js View on Github external
writeCachesToFile(path, data) {
        if (fs_1.existsSync(path_1.dirname(path))) {
            writeJsonToFile.sync(path, data);
            this.logger.log("Write caches to file: " + path);
        }
        else {
            this.logger.warn(`Path: \`${path}\` do not exists`);
        }
    }
}
github notadd / next / src / server / install.ts View on Github external
database = {
                type: engine,
                database: "./notadd.sqlite",
                entities: [
                    "**/*.entity.js",
                ],
                migrations: [
                    "**/*.migration.js",
                ],
                logging: true,
                migrationsRun: false,
                synchronize: false,
            };
            break;
    }
    writeJsonFile.sync(join(process.cwd(), "configurations", "database.json"), database, {
        indent: 4,
        sortKeys: true,
    });
    let wanted = "";
    switch (engine) {
        case "mysql":
            wanted = "mysql";
            break;
        case "sqlite":
            wanted = "sqlite3";
            break;
        default:
            wanted = "pg";
            break;
    }
github zeit / now / src / util / config-files.js View on Github external
const writeToConfigFile = stuff =>
  writeJSON.sync(CONFIG_FILE_PATH, stuff, { indent : 2 })
github apifytech / apify-cli / src / lib / secrets.js View on Github external
const writeSecretsFile = (secrets) => {
    writeJson.sync(SECRETS_FILE_PATH, secrets);
    return secrets;
};
github notadd / next / src / injection / loaders / injection.loader.ts View on Github external
protected writeCachesToFile(path: string, data: any) {
        if (existsSync(dirname(path))) {
            writeJsonToFile.sync(path, data);
            this.logger.log("Write caches to file: " + path);
        } else {
            this.logger.warn(`Path: \`${path}\` do not exists`);
        }
    }
}
github Turfjs / turf / scripts / update-dependencies.js View on Github external
glob.sync(path.join(__dirname, '..', 'packages', 'turf-*', 'package.json')).forEach(packagePath => {
    const pckg = load.sync(packagePath);
    pckg.dependencies = updateDependencies(pckg);
    pckg.devDependencies = updateDevDependencies(pckg);
    write.sync(packagePath, pckg, {indent: 2});
});

write-json-file

Stringify and write JSON to a file atomically

MIT
Latest version published 4 months ago

Package Health Score

75 / 100
Full package analysis

Popular write-json-file functions